[PATCH v3 1/5] waf: Support auto-filling of cross-answers by cross-execute

Uri Simchoni urisimchoni at gmail.com
Tue May 5 16:02:15 MDT 2015


Adds a new mode to samba cross-compiling.

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 at gmail.com>
---
 buildtools/wafsamba/samba_cross.py | 61 +++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 14 deletions(-)

diff --git a/buildtools/wafsamba/samba_cross.py b/buildtools/wafsamba/samba_cross.py
index 3838e34..9ca2f8d 100644
--- a/buildtools/wafsamba/samba_cross.py
+++ b/buildtools/wafsamba/samba_cross.py
@@ -19,6 +19,16 @@ def add_answer(ca_file, msg, answer):
     except:
         Logs.error("Unable to open cross-answers file %s" % ca_file)
         sys.exit(1)
+    (retcode, retstring) = answer
+    # if retstring is more than one line then we probably
+    # don't care about its actual content (the tests should
+    # yield one-line output in order to comply with the cross-answer
+    # format)
+    retstring = retstring.strip()
+    if len(retstring.split('\n')) > 1:
+        retstring = ''
+    answer = (retcode, retstring)
+
     if answer == ANSWER_OK:
         f.write('%s: OK\n' % msg)
     elif answer == ANSWER_UNKNOWN:
@@ -26,8 +36,7 @@ def add_answer(ca_file, msg, answer):
     elif answer == ANSWER_FAIL:
         f.write('%s: FAIL\n' % msg)
     else:
-        (retcode, retstring) = answer
-        f.write('%s: (%d, "%s")' % (msg, retcode, retstring))
+        f.write('%s: (%d, "%s")\n' % (msg, retcode, retstring))
     f.close()
 
 
@@ -36,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()
@@ -58,8 +66,10 @@ def cross_answer(ca_file, msg):
                 f.close()
                 return ANSWER_FAIL
             elif ans[0] == '"':
+                f.close()
                 return (0, ans.strip('"'))
             elif ans[0] == "'":
+                f.close()
                 return (0, ans.strip("'"))
             else:
                 m = re.match('\(\s*(-?\d+)\s*,\s*\"(.*)\"\s*\)', ans)
@@ -69,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
 
 
@@ -77,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)
@@ -115,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])
-- 
1.9.1



More information about the samba-technical mailing list