Changes invokeMakes to iterate over a list of commands instead of '&&'ing them to improve error reporting
authorTill Schneidereit <tschneidereit@gmail.com>
Tue, 08 May 2012 16:21:26 +0200
changeset 55 d564126208f06b5e090ba9e896778e4726002776
parent 54 43f1e3c8aed6c3922e2da2fdb6d6ac1a0ebe4a6e
child 56 f5410b3216663f099a5e0a61435b3beeac7bb4b5
push id35
push userjosh@joshmatthews.net
push dateTue, 08 May 2012 23:07:39 +0000
Changes invokeMakes to iterate over a list of commands instead of '&&'ing them to improve error reporting
smartmake.py
--- a/smartmake.py
+++ b/smartmake.py
@@ -21,46 +21,48 @@ conffile = './.hg/.smartmake'
 section = 'smartmake'
 timestampfile = '.hg/.smartmake-timestamp'
 depspecsfile = sys.path[0] + '/depspecs'
 ignoresfile = '.hg/.smartmake-ignoredpaths'
 
 def echo(s):
     print s
 
-def error(s):
+def error(s, code=1):
     echo("error: %s" % s)
-    sys.exit(1)
+    sys.exit(code)
 
 def usage():
     echo("Usage: smartmake.py [-h] [--help] [-f] [list of modified directories]")
     echo("  Must have a .smartmake config file present in .hg/ containing")
     echo("    [smartmake]")
     echo("    objdir: your-objdir/ (or use MOZ_OBJDIR)")
     echo("    cmd: make -C (or equivalent make command)")
     echo("")
     echo("  Use DEBUG=1 to perform a dry-run and see what make commands will be executed")
     echo("")
     echo("  Optionally, paths to ignore when deriving make calls can be "\
         "defined in the file '%s'" % ignoresfile)
     echo("    Format: One entry per line, relative to the project's root dir, no leading './'")
     sys.exit(1)
 
-def invokeMake(cmdline, timestampfile):
+def invokeMake(commands, timestampfile):
     timestamp = subprocess.check_output('date -u', shell=True)
-    cmdprocess = subprocess.Popen(cmdline, shell=True)
-    ret = cmdprocess.wait()
-    if ret is 0:
-        try:
-            f = open(timestampfile, 'w')
+    for cmd in commands:
+        cmdprocess = subprocess.Popen(cmd, shell=True)
+        ret = cmdprocess.wait()
+        if ret != 0:
+            error("make command '%s' failed" % cmd, ret)
+    try:
+        with open(timestampfile, 'w') as f:
             f.write(timestamp)
-        except Exception, e:
-            echo("Couldn't store timestamp. Error: %s" % e)
-            sys.exit(1)
-    sys.exit(ret)
+    except Exception, e:
+        echo("Couldn't store timestamp. Error: %s" % e)
+        sys.exit(1)
+    sys.exit(0)
 
 force = '-f' in sys.argv
 if force:
     sys.argv.remove('-f')
 
 if '-h' in sys.argv or '--help' in sys.argv:
     usage()
 
@@ -212,22 +214,22 @@ if changedFiles and not force:
     echo("Smartmake doesn't know how to build with the following files changed:")
     echo('\t' + '\n\t'.join(changedFiles))
     echo('Please do a full build, or re-run smartmake.py with -f to force an incremental build')
     sys.exit(1)
 
 if force:
     echo("NOTE: Forcing an incremental build")
 
-cmdline = " && ".join(map(lambda x: cmd + objdir + x, outdirs))
+commands = map(lambda x: cmd + objdir + x, outdirs)
 
 if debug:
     if findoutput:
         echo("changed files:")
         echo(findoutput)
     echo("make commands:")
 
-print(cmdline)
+print('\n'.join(commands))
 
 if debug:
     sys.exit(0)
 
-invokeMake(cmdline, timestampfile)
+invokeMake(commands, timestampfile)