Bug 1254355 - Part 1: Prepare to generalize generate_build_config. r=gps draft
authorNick Alexander <nalexander@mozilla.com>
Mon, 17 Apr 2017 13:38:24 -0700
changeset 565221 bc1e3ba32c2e39218a552e1312167918b3503af2
parent 565220 ea6b601d497aa45d632e73a0743ffe45763a692e
child 565222 996c581315a57427c1cb3de4bd454141d688be68
push id54815
push usernalexander@mozilla.com
push dateWed, 19 Apr 2017 16:27:19 +0000
reviewersgps
bugs1254355, 1355625
milestone55.0a1
Bug 1254355 - Part 1: Prepare to generalize generate_build_config. r=gps I'm taking another kick at this. Since glandium's negative review of older patches a year ago, generate_build_config.py landed (with your r+, gps). These patches extend that mechanism to generate AndroidManifest.xml. This sets the stage for that. This is all in service of Bug 1355625, which will need the generate_build_config.py extension point to do things that the preprocessor cannot handle: generating Java code, copying resource files, and merging resource XML declarations. MozReview-Commit-ID: AcyC3CBMQl1
mobile/android/base/generate_build_config.py
mobile/android/base/moz.build
--- a/mobile/android/base/generate_build_config.py
+++ b/mobile/android/base/generate_build_config.py
@@ -21,26 +21,24 @@ from __future__ import (
     unicode_literals,
 )
 
 from collections import defaultdict
 import os
 import sys
 
 import buildconfig
-from mozbuild.preprocessor import Preprocessor
+
+from mozbuild import preprocessor
 
 
-def main(output_file, input_filename):
-    # input_filename is an absolute path, so there's no need to join with __DIR__.
-    pp = Preprocessor(defines=buildconfig.defines, marker='//#')
-
+def _defines():
     CONFIG = defaultdict(lambda: None)
     CONFIG.update(buildconfig.substs)
-    DEFINES = {}
+    DEFINES = dict(buildconfig.defines)
 
     for var in ('MOZ_ANDROID_ACTIVITY_STREAM'
                 'MOZ_ANDROID_ANR_REPORTER',
                 'MOZ_ANDROID_BEAM',
                 'MOZ_ANDROID_CUSTOM_TABS',
                 'MOZ_ANDROID_DOWNLOADS_INTEGRATION',
                 'MOZ_ANDROID_DOWNLOAD_CONTENT_SERVICE',
                 'MOZ_ANDROID_EXCLUDE_FONTS',
@@ -96,21 +94,20 @@ def main(output_file, input_filename):
     else:
         DEFINES['MOZ_MIN_CPU_VERSION'] = 5
 
     # It's okay to use MOZ_ADJUST_SDK_KEY here because this doesn't
     # leak the value to build logs.
     if CONFIG['MOZ_INSTALL_TRACKING']:
         DEFINES['MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN'] = CONFIG['MOZ_ADJUST_SDK_KEY']
 
-    # TODO: mark buildid.h as a dependency?  How about the buildconfig itself?
     DEFINES['MOZ_BUILDID'] = open(os.path.join(buildconfig.topobjdir, 'buildid.h')).readline().split()[2]
 
-    pp.context.update(DEFINES)
-
-    with open(input_filename, 'rU') as input:
-        pp.processFile(input=input, output=output_file)
-
-    return 0
+    return DEFINES
 
 
-if __name__ == '__main__':
-    sys.exit(main(sys.stdout, *sys.argv[1:]))
+def generate_java(output_file, input_filename):
+    includes = preprocessor.preprocess(includes=[input_filename],
+                                   defines=_defines(),
+                                   output=output_file,
+                                   marker="//#")
+    includes.add(os.path.join(buildconfig.topobjdir, 'buildid.h'))
+    return includes
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -118,23 +118,23 @@ with Files('resources/menu/browsersearch
 DIRS += ['locales']
 
 GENERATED_FILES += [
     '../geckoview/generated/preprocessed/org/mozilla/geckoview/BuildConfig.java',
     'generated/preprocessed/org/mozilla/gecko/AdjustConstants.java',
     'generated/preprocessed/org/mozilla/gecko/AppConstants.java',
 ]
 w = GENERATED_FILES['../geckoview/generated/preprocessed/org/mozilla/geckoview/BuildConfig.java']
-w.script = 'generate_build_config.py'
+w.script = 'generate_build_config.py:generate_java'
 w.inputs += ['../geckoview/BuildConfig.java.in']
 x = GENERATED_FILES['generated/preprocessed/org/mozilla/gecko/AdjustConstants.java']
-x.script = 'generate_build_config.py'
+x.script = 'generate_build_config.py:generate_java'
 x.inputs += ['AdjustConstants.java.in']
 y = GENERATED_FILES['generated/preprocessed/org/mozilla/gecko/AppConstants.java']
-y.script = 'generate_build_config.py'
+y.script = 'generate_build_config.py:generate_java'
 y.inputs += ['AppConstants.java.in']
 
 include('android-services.mozbuild')
 
 geckoview_source_dir = TOPSRCDIR + '/mobile/android/geckoview/src/main/'
 geckoview_thirdparty_source_dir = TOPSRCDIR + '/mobile/android/geckoview/src/thirdparty/'
 thirdparty_source_dir = TOPSRCDIR + '/mobile/android/thirdparty/'