Adds a new mode to samba cross-compiling.
authorUri Simchoni <urisimchoni@gmail.com>
Mon, 18 May 2015 18:15:19 +0000 (21:15 +0300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 20 May 2015 09:19:11 +0000 (11:19 +0200)
When both --cross-answers and --cross-execute are set, this means:
- Use cross-answers
- If answer is unknown, then instead of adding UNKNOWN to the cross-answers
  file and failing configure, the new mode runs cross-execute to determine the
  answer and adds that to the cross-answers file.

Signed-off-by: Uri Simchoni <urisimchoni@gmail.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
buildtools/wafsamba/samba_cross.py

index b48155336d8d75ee50a3c1cc3ffa6f5c9a70ab39..9ca2f8d4610d8c7def48a3bb919bccc207d4b323 100644 (file)
@@ -45,7 +45,6 @@ def cross_answer(ca_file, msg):
     try:
         f = open(ca_file, 'r')
     except:
-        add_answer(ca_file, msg, ANSWER_UNKNOWN)
         return ANSWER_UNKNOWN
     for line in f:
         line = line.strip()
@@ -80,7 +79,6 @@ def cross_answer(ca_file, msg):
                 else:
                     raise Utils.WafError("Bad answer format '%s' in %s" % (line, ca_file))
     f.close()
-    add_answer(ca_file, msg, ANSWER_UNKNOWN)
     return ANSWER_UNKNOWN
 
 
@@ -88,24 +86,47 @@ class cross_Popen(Utils.pproc.Popen):
     '''cross-compilation wrapper for Popen'''
     def __init__(*k, **kw):
         (obj, args) = k
-
-        if '--cross-execute' in args:
-            # when --cross-execute is set, then change the arguments
-            # to use the cross emulator
-            i = args.index('--cross-execute')
-            newargs = args[i+1].split()
-            newargs.extend(args[0:i])
-            args = newargs
-        elif '--cross-answers' in args:
+        use_answers = False
+        ans = ANSWER_UNKNOWN
+
+        # Three possibilities:
+        #   1. Only cross-answers - try the cross-answers file, and if
+        #      there's no corresponding answer, add to the file and mark
+        #      the configure process as unfinished.
+        #   2. Only cross-execute - get the answer from cross-execute
+        #   3. Both - try the cross-answers file, and if there is no
+        #      corresponding answer - use cross-execute to get an answer,
+        #       and add that answer to the file.
+        if '--cross-answers' in args:
             # when --cross-answers is set, then change the arguments
             # to use the cross answers if available
+            use_answers = True
             i = args.index('--cross-answers')
             ca_file = args[i+1]
             msg     = args[i+2]
             ans = cross_answer(ca_file, msg)
+
+        if '--cross-execute' in args and ans == ANSWER_UNKNOWN:
+            # when --cross-execute is set, then change the arguments
+            # to use the cross emulator
+            i = args.index('--cross-execute')
+            newargs = args[i+1].split()
+            newargs.extend(args[0:i])
+            if use_answers:
+                p = real_Popen(newargs,
+                               stdout=Utils.pproc.PIPE,
+                               stderr=Utils.pproc.PIPE)
+                ce_out, ce_err = p.communicate()
+                ans = (p.returncode, ce_out)
+                add_answer(ca_file, msg, ans)
+            else:
+                args = newargs
+
+        if use_answers:
             if ans == ANSWER_UNKNOWN:
                 global cross_answers_incomplete
                 cross_answers_incomplete = True
+                add_answer(ca_file, msg, ans)
             (retcode, retstring) = ans
             args = ['/bin/sh', '-c', "echo -n '%s'; exit %d" % (retstring, retcode)]
         real_Popen.__init__(*(obj, args), **kw)
@@ -126,7 +147,8 @@ def SAMBA_CROSS_ARGS(conf, msg=None):
 
     if conf.env.CROSS_EXECUTE:
         ret.extend(['--cross-execute', conf.env.CROSS_EXECUTE])
-    elif conf.env.CROSS_ANSWERS:
+
+    if conf.env.CROSS_ANSWERS:
         if msg is None:
             raise Utils.WafError("Cannot have NULL msg in cross-answers")
         ret.extend(['--cross-answers', os.path.join(Options.launch_dir, conf.env.CROSS_ANSWERS), msg])