Bug 1215526 - part 2 - write dependencies to file_generate.py's depfile; r=glandium
authorNathan Froyd <froydnj@mozilla.com>
Wed, 21 Oct 2015 10:36:08 -0400
changeset 304566 936491b643506f1c5abc0bd8cc6fecfa9c11da8d
parent 304565 888b0896189183754bfe6a4cd83caae64011db54
child 304567 b77130c95e52af0831b33c63557f4564414d3018
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1215526
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1215526 - part 2 - write dependencies to file_generate.py's depfile; r=glandium
python/mozbuild/mozbuild/action/file_generate.py
python/mozbuild/mozbuild/frontend/context.py
--- a/python/mozbuild/mozbuild/action/file_generate.py
+++ b/python/mozbuild/mozbuild/action/file_generate.py
@@ -10,16 +10,17 @@ from __future__ import absolute_import, 
 
 import argparse
 import imp
 import os
 import sys
 import traceback
 
 from mozbuild.util import FileAvoidWrite
+from mozbuild.makeutil import Makefile
 
 def main(argv):
     parser = argparse.ArgumentParser('Generate a file from a Python script',
                                      add_help=False)
     parser.add_argument('python_script', metavar='python-script', type=str,
                         help='The Python script to run')
     parser.add_argument('method_name', metavar='method-name', type=str,
                         help='The method of the script to invoke')
@@ -51,16 +52,26 @@ def main(argv):
         print('Error: script "{0}" is missing a {1} method'.format(script, method),
               file=sys.stderr)
         return 1
 
     ret = 1
     try:
         with FileAvoidWrite(args.output_file) as output:
             ret = module.__dict__[method](output, *args.additional_arguments)
+            # We treat sets as a statement of success.  Everything else
+            # is an error (so scripts can conveniently |return 1| or
+            # similar).
+            if isinstance(ret, set) and ret:
+                mk = Makefile()
+                mk.create_rule([args.output_file]).add_dependencies(ret)
+                with FileAvoidWrite(args.dep_file) as dep_file:
+                    mk.dump(dep_file)
+                # The script succeeded, so reset |ret| to indicate that.
+                ret = None
     except IOError as e:
         print('Error opening file "{0}"'.format(e.filename), file=sys.stderr)
         traceback.print_exc()
         return 1
     return ret
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -902,16 +902,19 @@ VARIABLES = {
 
         To enable using the same script for generating multiple files with
         slightly different non-filename parameters, alternative entry points
         into ``script`` can be specified::
 
           GENERATED_FILES += ['bar.c']
           bar = GENERATED_FILES['bar.c']
           bar.script = 'generate.py:make_bar'
+
+        The chosen script entry point may optionally return a set of strings,
+        indicating extra files the output depends on.
         """, 'export'),
 
     'DEFINES': (OrderedDict, dict,
         """Dictionary of compiler defines to declare.
 
         These are passed in to the compiler as ``-Dkey='value'`` for string
         values, ``-Dkey=value`` for numeric values, or ``-Dkey`` if the
         value is True. Note that for string values, the outer-level of