Index: build.py |
=================================================================== |
--- a/build.py |
+++ b/build.py |
@@ -7,90 +7,87 @@ 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") |
-DIST_PATH = os.path.join(ABB_PATH, "obj-arm-linux-androideabi", "dist") |
+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" |
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])}) |
-def check_mozconfig(path, distribution_mode, build_mode): |
- if not os.path.exists(path): |
- raise Exception("'%s' doesn't exist, please create it." % path) |
- |
- with open(path) as file: |
- contents = file.read() |
- |
- # This check can be removed once https://issues.adblockplus.org/ticket/2490 is |
- # done. |
- if "--disable-crashreporter" not in contents: |
- raise Exception( |
- "'%s' doesn't seem to set --disable-crashreporter, please do." % path) |
- |
- if "export MOZILLA_OFFICIAL=1" not in contents: |
- raise Exception( |
- "'%s' doesn't seem to export MOZILLA_OFFICIAL=1, please do." % path) |
- |
- updater_disabled = "--disable-updater" in contents |
- if updater_disabled and distribution_mode == "standalone": |
- raise Exception("'%s' seems to set --disable-updater, please don't." % path) |
- elif not updater_disabled and distribution_mode == "store": |
- raise Exception( |
- "'%s' doesn't seem to set --disable-updater, please do." % path) |
- |
- release_build = "export ABB_RELEASE_BUILD=1" in contents |
- if release_build and build_mode != "release": |
- raise Exception("'%s' shouldn't export ABB_RELEASE_BUILD=1." % path) |
- elif not release_build and build_mode == "release": |
- raise Exception("'%s' should export ABB_RELEASE_BUILD=1." % 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) |
+ 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) |
+ return mozconfig_path |
-def find_mozconfig(distribution_mode, build_mode): |
- mozconfig_path = os.path.join(BASE_DIR, "mozconfig-" + distribution_mode + |
- "-" + build_mode) |
- check_mozconfig(mozconfig_path, distribution_mode, build_mode) |
- return mozconfig_path |
- |
- |
-def build(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"] = find_mozconfig(distribution_mode, build_mode) |
+ 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["OBJDIR"] = obj_dir |
subprocess.check_call([os.path.join(ABB_PATH, "mach"), "clobber"], |
env=build_environment) |
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 |
[manifest_path] = glob.glob(os.path.join( |
- DIST_PATH, "fennec-*.multi.android-arm.json")) |
+ 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") |
+ apk_path = os.path.join(dist_path, "gecko-unsigned-unaligned.apk") |
if build_mode == "release": |
- target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_version"] |
+ target_apk_name = "adblockbrowser-%s-%s.apk" % ( |
+ manifest["moz_app_version"], architecture) |
else: |
- target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( |
- manifest["moz_app_version"], manifest["buildid"]) |
- target_apk_path = os.path.join(DIST_PATH, target_apk_name) |
+ 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 |
@@ -132,15 +129,20 @@ if __name__ == "__main__": |
print >>sys.stderr, "Invalid distribution mode, check config.py" |
sys.exit(4) |
build_mode = config.BUILD_MODE |
if build_mode not in ("devbuild", "release"): |
print >>sys.stderr, "Invalid build mode, check config.py" |
sys.exit(5) |
+ architecture = config.ARCHITECTURE |
+ if architecture not in (ARCH_ARM, ARCH_X86): |
+ print >>sys.stderr, "Invalid architecture, check config.py" |
+ sys.exit(6) |
+ |
if do_build: |
- apk_path = build(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) |
else: |
print apk_path |