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='//#')