Index: build.py |
=================================================================== |
--- a/build.py |
+++ b/build.py |
@@ -5,144 +5,159 @@ import json |
import os |
import re |
import shutil |
import string |
import subprocess |
import sys |
import tempfile |
-BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
-ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py") |
-GENERATED_MOZCONFIG_PATH = os.path.join(BASE_DIR, "generated", "mozconfig") |
-MOZCONFIG_COMMON_PATH = os.path.join(BASE_DIR, "mozconfig-common") |
-MOZCONFIG_ARM_PATH = os.path.join(BASE_DIR, "mozconfig-arm") |
-MOZCONFIG_X86_PATH = os.path.join(BASE_DIR, "mozconfig-x86") |
-MOZCONFIG_STORE_PATH = os.path.join(BASE_DIR, "mozconfig-store") |
-MOZCONFIG_RELEASE_PATH = os.path.join(BASE_DIR, "mozconfig-release") |
-MOZCONFIG_CUSTOM_PATH = os.path.join(BASE_DIR, "mozconfig-custom") |
-MULTI_L10N_PATH = os.path.join(BASE_DIR, "mozharness", "scripts", |
- "multil10n.py") |
-ABB_PATH = os.path.join(BASE_DIR, "adblockbrowser") |
-ARCH_ARM = "arm" |
-ARCH_X86 = "x86" |
-ARCH_X86_I386 = "i386" |
-DIST_STORE = "store" |
-BUILD_RELEASE = "release" |
-OBJDIR_ARM = "obj-arm-linux-androideabi" |
-OBJDIR_X86 = "obj-i386-linux-android" |
+_BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
+_ENSURE_DEPENDENCIES_PATH = os.path.join(_BASE_DIR, "ensure_dependencies.py") |
+_GENERATED_MOZCONFIG_PATH = os.path.join(_BASE_DIR, "generated", "mozconfig") |
+_MOZCONFIG_COMMON_PATH = os.path.join(_BASE_DIR, "mozconfig-common") |
+_MOZCONFIG_ARM_PATH = os.path.join(_BASE_DIR, "mozconfig-arm") |
+_MOZCONFIG_X86_PATH = os.path.join(_BASE_DIR, "mozconfig-x86") |
+_MOZCONFIG_STORE_PATH = os.path.join(_BASE_DIR, "mozconfig-store") |
+_MOZCONFIG_RELEASE_PATH = os.path.join(_BASE_DIR, "mozconfig-release") |
+_MOZCONFIG_CUSTOM_PATH = os.path.join(_BASE_DIR, "mozconfig-custom") |
+_MULTI_L10N_PATH = os.path.join(_BASE_DIR, "mozharness", "scripts", |
+ "multil10n.py") |
+_ABB_PATH = os.path.join(_BASE_DIR, "adblockbrowser") |
+_CMD_BUILD = "build" |
+_CMD_SIGN = "sign" |
+_CMD_BUILD_SIGN = "build-and-sign" |
+_ARCH_ARM = "arm" |
+_ARCH_X86 = "x86" |
+_ARCH_X86_I386 = "i386" |
+_ARCHS = (_ARCH_ARM, _ARCH_X86) |
+_DIST_STANDALONE = "standalone" |
+_DIST_STORE = "store" |
+_DIST_MODES = (_DIST_STANDALONE, _DIST_STORE) |
+_BUILD_DEVBUILD = "devbuild" |
+_BUILD_RELEASE = "release" |
+_BUILD_MODES = (_BUILD_DEVBUILD, _BUILD_RELEASE) |
+_OBJDIR_ARM = "obj-arm-linux-androideabi" |
+_OBJDIR_X86 = "obj-i386-linux-android" |
def print_usage(): |
print >>sys.stderr, string.Template("""\ |
-Usage: $name build |
- $name sign APK_PATH |
- $name build-and-sign\ |
-""").substitute({"name": os.path.basename(sys.argv[0])}) |
+Usage: $name %s |
+ $name %s APK_PATH |
+ $name %s\ |
+""" % (_CMD_BUILD, _CMD_SIGN, |
+ _CMD_BUILD_SIGN)).substitute({"name": os.path.basename(sys.argv[0])}) |
-def generate_mozconfig(architecture, distribution_mode, build_mode): |
- mozconfig_path = GENERATED_MOZCONFIG_PATH |
+def _generate_mozconfig(architecture, distribution_mode, build_mode): |
+ mozconfig_path = _GENERATED_MOZCONFIG_PATH |
with open(mozconfig_path, "w+") as mozconfig: |
- mozconfig.write(". \"%s\"\n" % MOZCONFIG_COMMON_PATH) |
- if architecture == ARCH_X86: |
- mozconfig.write(". \"%s\"\n" % MOZCONFIG_X86_PATH) |
+ mozconfig.write(". \"%s\"\n" % _MOZCONFIG_COMMON_PATH) |
+ if architecture == _ARCH_X86: |
+ mozconfig.write(". \"%s\"\n" % _MOZCONFIG_X86_PATH) |
else: |
- mozconfig.write(". \"%s\"\n" % MOZCONFIG_ARM_PATH) |
- if distribution_mode == DIST_STORE: |
- mozconfig.write(". \"%s\"\n" % MOZCONFIG_STORE_PATH) |
- if build_mode == BUILD_RELEASE: |
- mozconfig.write(". \"%s\"\n" % MOZCONFIG_RELEASE_PATH) |
- mozconfig.write(". \"%s\"\n" % MOZCONFIG_CUSTOM_PATH) |
+ mozconfig.write(". \"%s\"\n" % _MOZCONFIG_ARM_PATH) |
+ if distribution_mode == _DIST_STORE: |
+ mozconfig.write(". \"%s\"\n" % _MOZCONFIG_STORE_PATH) |
+ if build_mode == _BUILD_RELEASE: |
+ mozconfig.write(". \"%s\"\n" % _MOZCONFIG_RELEASE_PATH) |
+ mozconfig.write(". \"%s\"\n" % _MOZCONFIG_CUSTOM_PATH) |
return mozconfig_path |
-def build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): |
+def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): |
build_environment = os.environ.copy() |
- build_environment["MOZCONFIG"] = generate_mozconfig( |
- architecture, distribution_mode, build_mode) |
build_environment["ANDROID_SDK_PATH"] = sdk_path |
build_environment["ANDROID_NDK_PATH"] = ndk_path |
- obj_dir = OBJDIR_X86 if architecture == ARCH_X86 else OBJDIR_ARM |
+ build_environment["MOZCONFIG"] = _generate_mozconfig( |
+ architecture, distribution_mode, build_mode) |
+ obj_dir = _OBJDIR_X86 if architecture == _ARCH_X86 else _OBJDIR_ARM |
build_environment["OBJDIR"] = obj_dir |
- subprocess.check_call([os.path.join(ABB_PATH, "mach"), "clobber"], |
+ subprocess.check_call([os.path.join(_ABB_PATH, "mach"), "clobber"], |
env=build_environment) |
- subprocess.check_call([MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], |
+ subprocess.check_call([_MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], |
env=build_environment) |
- dist_path = os.path.join(ABB_PATH, obj_dir, "dist") |
- arch_suffix = ARCH_X86_I386 if architecture == ARCH_X86 else ARCH_ARM |
+ dist_path = os.path.join(_ABB_PATH, obj_dir, "dist") |
+ arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM |
[manifest_path] = glob.glob(os.path.join( |
dist_path, "fennec-*.multi.android-%s.json" % arch_suffix)) |
with open(manifest_path) as manifest_file: |
manifest = json.load(manifest_file) |
apk_path = os.path.join(dist_path, "gecko-unsigned-unaligned.apk") |
- if build_mode == "release": |
+ if build_mode == _BUILD_RELEASE: |
target_apk_name = "adblockbrowser-%s-%s.apk" % ( |
manifest["moz_app_version"], architecture) |
else: |
target_apk_name = "adblockbrowser-%s.%s-%s.apk" % ( |
manifest["moz_app_version"], manifest["buildid"], architecture) |
target_apk_path = os.path.join(dist_path, target_apk_name) |
shutil.copyfile(apk_path, target_apk_path) |
target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) |
shutil.copyfile(manifest_path, target_manifest_path) |
return target_apk_path |
-def sign(apk_path, key_store, key_name): |
+def _sign(apk_path, key_store, key_name): |
temp_apk_path = tempfile.NamedTemporaryFile().name |
shutil.copyfile(apk_path, temp_apk_path) |
try: |
- subprocess.check_call(["jarsigner", "-verbose", "-sigalg", "SHA1withRSA", |
- "-digestalg", "SHA1", "-keystore", key_store, |
+ subprocess.check_call(["jarsigner", "-verbose", |
+ "-sigalg", "SHA1withRSA", |
+ "-digestalg", "SHA1", |
+ "-keystore", key_store, |
temp_apk_path, key_name]) |
os.remove(apk_path) |
subprocess.check_call(["zipalign", "-v", "4", temp_apk_path, apk_path]) |
finally: |
os.remove(temp_apk_path) |
if __name__ == "__main__": |
if len(sys.argv) < 2: |
print_usage() |
sys.exit(1) |
mode = sys.argv[1] |
- do_build = mode in ("build", "build-and-sign") |
- do_sign = mode in ("sign", "build-and-sign") |
+ do_build = mode in (_CMD_BUILD, _CMD_BUILD_SIGN) |
+ do_sign = mode in (_CMD_SIGN, _CMD_BUILD_SIGN) |
if not do_build and not do_sign: |
print_usage() |
sys.exit(2) |
if do_sign: |
if len(sys.argv) < 3: |
print_usage() |
sys.exit(3) |
apk_path = sys.argv[2] |
- subprocess.check_call([ENSURE_DEPENDENCIES_PATH]) |
+ subprocess.check_call([_ENSURE_DEPENDENCIES_PATH]) |
import config |
+ error_msg = "Invalid %s, check config.py. Supported %s: %s" |
architecture = config.ARCHITECTURE |
- if architecture not in (ARCH_ARM, ARCH_X86): |
- print >>sys.stderr, "Invalid architecture, check config.py" |
+ if architecture not in _ARCHS: |
+ print >>sys.stderr, error_msg % ( |
+ "architecture", "architectures", _ARCHS) |
sys.exit(4) |
distribution_mode = config.DISTRIBUTION_MODE |
- if distribution_mode not in ("standalone", "store"): |
- print >>sys.stderr, "Invalid distribution mode, check config.py" |
+ if distribution_mode not in _DIST_MODES: |
+ print >>sys.stderr, error_msg % ( |
+ "distribution mode", "distribution modes", _DIST_MODES) |
sys.exit(5) |
build_mode = config.BUILD_MODE |
- if build_mode not in ("devbuild", "release"): |
- print >>sys.stderr, "Invalid build mode, check config.py" |
+ if build_mode not in _BUILD_MODES: |
+ print >>sys.stderr, error_msg % ( |
+ "build mode", "build modes", _BUILD_MODES) |
sys.exit(6) |
if do_build: |
- apk_path = build(architecture, distribution_mode, build_mode, |
- config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) |
+ apk_path = _build(architecture, distribution_mode, build_mode, |
+ config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) |
if do_sign: |
- sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME) |
+ _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME) |
else: |
print apk_path |