Bug 1562996 - Add a GeneratedFile template to get rid of some of the boilerplate involved in interfacing with GENERATED_FILES. r=nalexander
authorRicky Stewart <Ricky Stewart>
Tue, 01 Oct 2019 18:10:16 +0000
changeset 2362735 134999fb1885d55868a18682dd7334676a0c2082
parent 2362734 1ca9b7056c58303f35da14504be8ada9d38ec9aa
child 2362736 eeaa7ecf70e3ffbcd4a1908d02982b2e5d6fc8a8
push id430144
push usernsilva@mozilla.com
push dateWed, 02 Oct 2019 09:19:45 +0000
treeherdertry@403cf2da83b8 [default view] [failures only]
reviewersnalexander
bugs1562996
milestone71.0a1
Bug 1562996 - Add a GeneratedFile template to get rid of some of the boilerplate involved in interfacing with GENERATED_FILES. r=nalexander Differential Revision: https://phabricator.services.mozilla.com/D47019
build/templates.mozbuild
devtools/client/shared/build/node-templates.mozbuild
js/src/build/moz.build
--- a/build/templates.mozbuild
+++ b/build/templates.mozbuild
@@ -161,10 +161,39 @@ def ForceInclude(*headers):
     """Force includes a set of header files in C++ compilations"""
     if CONFIG['CC_TYPE'] == 'clang-cl':
         include_flag = '-FI'
     else:
         include_flag = '-include'
     for header in headers:
         CXXFLAGS += [include_flag, header]
 
+@template
+def GeneratedFile(name, *names, **kwargs):
+    """Add one or more GENERATED_FILES with the given attributes.
+
+    You must pass in at least one generated file (the "name" argument). Other
+    names can be included as positional arguments after "name"."""
+    script = kwargs.get('script')
+    entry_point = kwargs.get('entry_point')
+    inputs = kwargs.get('inputs', [])
+    flags = kwargs.get('flags', [])
+    force = kwargs.get('force', False)
+    if entry_point and not script:
+       error('entry_point cannot be provided if script is not provided')
+    if script and ':' in script:
+       error('script should not include a `:`. If you want to provide an '
+             'alternative entry point for your script, use the entry_point '
+             'parameter.')
+
+    key = (name,) + names if names else name
+    GENERATED_FILES += [key]
+    generated_file = GENERATED_FILES[key]
+    if script and not entry_point:
+        generated_file.script = script
+    if script and entry_point:
+        generated_file.script = script + ':' + entry_point
+    generated_file.inputs = inputs
+    generated_file.flags = flags
+    generated_file.force = force
+
 include('gecko_templates.mozbuild')
 include('test_templates.mozbuild')
--- a/devtools/client/shared/build/node-templates.mozbuild
+++ b/devtools/client/shared/build/node-templates.mozbuild
@@ -27,15 +27,13 @@ def CompiledModules(*modules):
     size += 1
 
   if size == 0:
     return
 
   # For the same reason as https://searchfox.org/mozilla-central/source/mobile/android/base/moz.build#180-184
   # we have to insert a first entry as recursivemake overrides the first entry and we end up with empty files
   # for the first file only.
-  outputs = tuple(("node.stub",) + modules)
-  GENERATED_FILES += [outputs]
-
-  bundle = GENERATED_FILES[outputs]
-  bundle.script = '/python/mozbuild/mozbuild/action/node.py:generate'
-  bundle.inputs = ['/devtools/client/shared/build/build.js',]
-  bundle.inputs.extend(modules)
+  GeneratedFile(
+      "node.stub", *modules,
+      script='/python/mozbuild/mozbuild/action/node.py',
+      entry_point='generate',
+      inputs=['/devtools/client/shared/build/build.js'] + [module for module in modules])
--- a/js/src/build/moz.build
+++ b/js/src/build/moz.build
@@ -24,22 +24,19 @@ if not CONFIG['JS_STANDALONE']:
 
 if CONFIG['JS_SHARED_LIBRARY']:
     GeckoSharedLibrary('js', linkage=None)
     SHARED_LIBRARY_NAME = CONFIG['JS_LIBRARY_NAME']
 
     # Ensure symbol versions of shared library on Linux do not conflict
     # with those in libxul.
     if CONFIG['OS_TARGET'] == 'Linux':
-        GENERATED_FILES += ['symverscript']
-        GENERATED_FILES['symverscript'].script = '/build/gen_symverscript.py'
-        GENERATED_FILES['symverscript'].inputs = ['symverscript.in']
-        GENERATED_FILES['symverscript'].flags = [
-            CONFIG['JS_LIBRARY_NAME'].replace('-', '_'),
-        ]
+        GeneratedFile('symverscript', script='/build/gen_symverscript.py', 
+                      inputs=['symverscript.in'], 
+                      flags=[CONFIG['JS_LIBRARY_NAME'].replace('-', '_')])
         SYMBOLS_FILE = '!symverscript'
 else:
     Library('js')
 
 FORCE_STATIC_LIB = True
 STATIC_LIBRARY_NAME = 'js_static'
 
 if CONFIG['ENABLE_INTL_API']:
@@ -81,17 +78,16 @@ if CONFIG['MOZ_NEEDS_LIBATOMIC']:
 OS_LIBS += CONFIG['REALTIME_LIBS']
 
 NO_EXPAND_LIBS = True
 
 DIST_INSTALL = True
 
 # Run SpiderMonkey style checker after linking the static library. This avoids
 # running the script for no-op builds.
-GENERATED_FILES += ['spidermonkey_checks']
-run_checks = GENERATED_FILES['spidermonkey_checks']
-run_checks.script = '/config/run_spidermonkey_checks.py'
-run_checks.inputs += [
-    '!%sjs_static.%s' % (CONFIG['LIB_PREFIX'], CONFIG['LIB_SUFFIX']),
-    '/config/check_spidermonkey_style.py',
-    '/config/check_macroassembler_style.py',
-    '/config/check_js_opcode.py'
-]
+GeneratedFile(
+    'spidermonkey_checks', script='/config/run_spidermonkey_checks.py',
+    inputs=[
+        '!%sjs_static.%s' % (CONFIG['LIB_PREFIX'], CONFIG['LIB_SUFFIX']),
+        '/config/check_spidermonkey_style.py',
+        '/config/check_macroassembler_style.py',
+        '/config/check_js_opcode.py'
+        ])