Bug 1254355 - Part 1: Make AndroidManifest.xml and fennec_ids.txt GENERATED_FILES. r?glandium draft
authorNick Alexander <nalexander@mozilla.com>
Thu, 10 Mar 2016 13:13:58 -0800
changeset 339325 3c0b38ab7dc095889d71410b10804815e592f5f4
parent 339324 77fe280423e5ec7f41d06c7d9f42ab419a7299eb
child 339326 eb704b7c6ba1aae7c2c5c29e7e7211ed62a134a2
push id12698
push usernalexander@mozilla.com
push dateFri, 11 Mar 2016 00:31:59 +0000
reviewersglandium
bugs1254355
milestone48.0a1
Bug 1254355 - Part 1: Make AndroidManifest.xml and fennec_ids.txt GENERATED_FILES. r?glandium MozReview-Commit-ID: EoFVwcX0JEL
mobile/android/base/Makefile.in
mobile/android/base/moz.build
python/mozbuild/mozbuild/action/generate_android.py
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -302,23 +302,16 @@ jni-stubs.inc: gecko-browser.jar constan
 ANNOTATION_PROCESSOR_JAR_FILES := $(DEPTH)/build/annotationProcessors/annotationProcessors.jar
 
 # This annotation processing step also generates
 # GeneratedJNIWrappers.h and GeneratedJNINatives.h
 GeneratedJNIWrappers.cpp: $(ANNOTATION_PROCESSOR_JAR_FILES)
 GeneratedJNIWrappers.cpp: $(ALL_JARS)
 	$(JAVA) -classpath constants.jar:$(JAVA_BOOTCLASSPATH):$(JAVA_CLASSPATH):$(ANNOTATION_PROCESSOR_JAR_FILES) org.mozilla.gecko.annotationProcessors.AnnotationProcessor $(ALL_JARS)
 
-manifest := \
-  AndroidManifest.xml.in \
-  fennec_ids.txt.in \
-  $(NULL)
-
-PP_TARGETS += manifest
-
 # Certain source files need to be preprocessed.  This special rule
 # generates these files into generated/org/mozilla/gecko for
 # consumption by the build system and IDEs.
 
 # The list in moz.build looks like
 # 'preprocessed/org/mozilla/gecko/AppConstants.java'.  The list in
 # constants_PP_JAVAFILES looks like
 # 'generated/preprocessed/org/mozilla/gecko/AppConstants.java'.  We
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -2,16 +2,25 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DIRS += ['locales']
 
 CONFIGURE_SUBST_FILES += ['adjust_sdk_app_token']
+GENERATED_FILES += ['AndroidManifest.xml']
+manifest = GENERATED_FILES['AndroidManifest.xml']
+manifest.script = '/python/mozbuild/mozbuild/action/generate_android.py:generate_android_manifest'
+manifest.inputs = ['AndroidManifest.xml.in']
+
+GENERATED_FILES += ['fennec_ids.txt']
+fennec_ids = GENERATED_FILES['fennec_ids.txt']
+fennec_ids.script = '/python/mozbuild/mozbuild/action/generate_android.py:generate_fennec_ids'
+fennec_ids.inputs = ['fennec_ids.txt.in']
 
 include('android-services.mozbuild')
 
 thirdparty_source_dir = TOPSRCDIR + '/mobile/android/thirdparty/'
 
 constants_jar = add_java_jar('constants')
 constants_jar.sources = ['java/org/mozilla/gecko/' + x for x in [
     'adjust/AdjustHelperInterface.java',
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/action/generate_android.py
@@ -0,0 +1,138 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+'''
+Script to generate and preprocess files for Fennec.
+
+Handles exposing Android-specific build system substitutions as preprocessor
+defines.
+
+Intended for use with GENERATED_FILES.
+'''
+
+
+import buildconfig
+
+from mozbuild.preprocessor import preprocess
+from mozbuild.android_version_code import android_version_code
+
+import os
+
+
+def _local_defines():
+    CONFIG = buildconfig.substs
+    defines = {}
+    for var in (
+            'MOZ_ANDROID_ANR_REPORTER',
+            'MOZ_ANDROID_DOWNLOADS_INTEGRATION',
+            'MOZ_ANDROID_GCM',
+            'MOZ_ANDROID_MLS_STUMBLER',
+            'MOZ_ANDROID_SEARCH_ACTIVITY',
+            'MOZ_DEBUG',
+            'MOZ_INSTALL_TRACKING',
+            'MOZ_LINKER_EXTRACT',
+            'MOZ_NATIVE_DEVICES',
+    ):
+        if CONFIG.get(var):
+            defines[var] = 1
+
+    for var in (
+            'MOZ_ANDROID_GCM_SENDERID',
+            'MOZ_ANDROID_SHARED_ID',
+            'MOZ_PKG_SPECIAL',
+            'MOZ_UPDATER',
+    ):
+        if CONFIG.get(var):
+            defines[var] = CONFIG.get(var)
+
+    for var in (
+            'ANDROID_CPU_ARCH',
+            'ANDROID_PACKAGE_NAME',
+            'GRE_MILESTONE',
+            'MOZILLA_VERSION',
+            'MOZ_ANDROID_APPLICATION_CLASS',
+            'MOZ_ANDROID_BROWSER_INTENT_CLASS',
+            'MOZ_ANDROID_SEARCH_INTENT_CLASS',
+            'MOZ_APP_BASENAME',
+            'MOZ_APP_DISPLAYNAME',
+            'MOZ_APP_ID',
+            'MOZ_APP_NAME',
+            'MOZ_APP_UA_NAME',
+            'MOZ_APP_VENDOR',
+            'MOZ_APP_VERSION',
+            'MOZ_CHILD_PROCESS_NAME',
+            'MOZ_CRASHREPORTER',
+            'MOZ_MOZILLA_API_KEY',
+            'MOZ_UPDATE_CHANNEL',
+            'OMNIJAR_NAME',
+            'OS_TARGET',
+            'TARGET_XPCOM_ABI',
+    ):
+        defines[var] = CONFIG.get(var)
+
+    # Mangle our package name to avoid Bug 750548.
+    defines['MANGLED_ANDROID_PACKAGE_NAME'] = \
+        CONFIG['ANDROID_PACKAGE_NAME'].replace('fennec', 'f3nn3c')
+    defines['MOZ_APP_ABI'] = CONFIG['TARGET_XPCOM_ABI']
+    if not CONFIG.get('COMPILE_ENVIRONMENT'):
+        # These should come from the included binaries, but that's not easy.
+        defines['MOZ_APP_ABI'] = 'arm-eabi-gcc3'
+        defines['TARGET_XPCOM_ABI'] = 'arm-eabi-gcc3'
+
+    if '-march=armv7' in CONFIG['OS_CFLAGS']:
+        defines['MOZ_MIN_CPU_VERSION'] = 7
+    else:
+        defines['MOZ_MIN_CPU_VERSION'] = 5
+
+    # This is awful, but it's what we did in our Makefiles.  Perhaps
+    # we should expose this directly in buildconfig.
+    buildidh = os.path.join(buildconfig.topobjdir, 'buildid.h')
+    define, MOZ_BUILDID, buildid = open(buildidh, 'r').read().split()
+    defines['MOZ_BUILDID'] = buildid
+
+    # Set the appropriate version code, based on the existance of the
+    # MOZ_APP_ANDROID_VERSION_CODE variable.
+    if CONFIG.get('MOZ_APP_ANDROID_VERSION_CODE'):
+        defines['ANDROID_VERSION_CODE'] = \
+            CONFIG.get('MOZ_APP_ANDROID_VERSION_CODE')
+    else:
+        min_sdk = int(CONFIG.get('MOZ_ANDROID_MIN_SDK_VERSION') or '0') or None
+        max_sdk = int(CONFIG.get('MOZ_ANDROID_MAX_SDK_VERSION') or '0') or None
+        defines['ANDROID_VERSION_CODE'] = android_version_code(
+            buildid=defines['MOZ_BUILDID'],
+            cpu_arch=CONFIG['ANDROID_CPU_ARCH'],
+            min_sdk=min_sdk,
+            max_sdk=max_sdk)
+
+    if CONFIG.get('MOZ_INSTALL_TRACKING'):
+        defines['MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN'] = \
+            CONFIG['MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN']
+
+    return defines
+
+
+def _do_preprocessing(output, input, additional_defines, marker='#'):
+    defines = {}
+    # Per invocation defines override defines in this file override defines
+    # from the buildconfig.
+    defines.update(buildconfig.defines)
+    defines.update(_local_defines())
+    defines.update(additional_defines)
+    return preprocess(output=output,
+                      includes=[input],
+                      marker=marker,
+                      defines=defines)
+
+
+def generate_android_manifest(output, input):
+    return _do_preprocessing(output, input, {}, marker='#')
+
+
+def generate_fennec_ids(output, input):
+    return _do_preprocessing(output, input, {}, marker='#')
+
+
+def generate_preprocessed_java(output, input):
+    return _do_preprocessing(output, input, {}, marker='//#')