Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: build.py

Issue 29365816: Issue 4677 - Add support for x86 builds in adblockbrowser-build (Closed)
Patch Set: Created Nov. 30, 2016, 2:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « adblockbrowser-cfg.py ('k') | config.py.sample » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import glob 3 import glob
4 import json 4 import json
5 import os 5 import os
6 import re 6 import re
7 import shutil 7 import shutil
8 import string 8 import string
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 import tempfile 11 import tempfile
12 12
13 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 13 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
14 ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py") 14 ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py")
15 GENERATED_MOZCONFIG_PATH = os.path.join(BASE_DIR, "generated", "mozconfig")
16 MOZCONFIG_COMMON_PATH = os.path.join(BASE_DIR, "mozconfig-common")
17 MOZCONFIG_ARM_PATH = os.path.join(BASE_DIR, "mozconfig-arm")
18 MOZCONFIG_X86_PATH = os.path.join(BASE_DIR, "mozconfig-x86")
19 MOZCONFIG_STORE_PATH = os.path.join(BASE_DIR, "mozconfig-store")
20 MOZCONFIG_RELEASE_PATH = os.path.join(BASE_DIR, "mozconfig-release")
21 MOZCONFIG_CUSTOM_PATH = os.path.join(BASE_DIR, "mozconfig-custom")
15 MULTI_L10N_PATH = os.path.join(BASE_DIR, "mozharness", "scripts", 22 MULTI_L10N_PATH = os.path.join(BASE_DIR, "mozharness", "scripts",
16 "multil10n.py") 23 "multil10n.py")
17 ABB_PATH = os.path.join(BASE_DIR, "adblockbrowser") 24 ABB_PATH = os.path.join(BASE_DIR, "adblockbrowser")
18 DIST_PATH = os.path.join(ABB_PATH, "obj-arm-linux-androideabi", "dist") 25 ARCH_ARM = "arm"
26 ARCH_X86 = "x86"
27 ARCH_X86_I386 = "i386"
28 DIST_STORE = "store"
29 BUILD_RELEASE = "release"
30 OBJDIR_ARM = "obj-arm-linux-androideabi"
31 OBJDIR_X86 = "obj-i386-linux-android"
19 32
20 33
21 def print_usage(): 34 def print_usage():
22 print >>sys.stderr, string.Template("""\ 35 print >>sys.stderr, string.Template("""\
23 Usage: $name build 36 Usage: $name build
24 $name sign APK_PATH 37 $name sign APK_PATH
25 $name build-and-sign\ 38 $name build-and-sign\
26 """).substitute({"name": os.path.basename(sys.argv[0])}) 39 """).substitute({"name": os.path.basename(sys.argv[0])})
27 40
28 41
29 def check_mozconfig(path, distribution_mode, build_mode): 42 def generate_mozconfig(architecture, distribution_mode, build_mode):
30 if not os.path.exists(path): 43 mozconfig_path = GENERATED_MOZCONFIG_PATH
31 raise Exception("'%s' doesn't exist, please create it." % path) 44 with open(mozconfig_path, "w+") as mozconfig:
32 45 mozconfig.write(". \"%s\"\n" % MOZCONFIG_COMMON_PATH)
33 with open(path) as file: 46 if architecture == ARCH_X86:
34 contents = file.read() 47 mozconfig.write(". \"%s\"\n" % MOZCONFIG_X86_PATH)
35 48 else:
36 if "export MOZILLA_OFFICIAL=1" not in contents: 49 mozconfig.write(". \"%s\"\n" % MOZCONFIG_ARM_PATH)
37 raise Exception( 50 if distribution_mode == DIST_STORE:
38 "'%s' doesn't seem to export MOZILLA_OFFICIAL=1, please do." % path) 51 mozconfig.write(". \"%s\"\n" % MOZCONFIG_STORE_PATH)
39 52 if build_mode == BUILD_RELEASE:
40 updater_disabled = "--disable-updater" in contents 53 mozconfig.write(". \"%s\"\n" % MOZCONFIG_RELEASE_PATH)
41 if updater_disabled and distribution_mode == "standalone": 54 mozconfig.write(". \"%s\"\n" % MOZCONFIG_CUSTOM_PATH)
42 raise Exception("'%s' seems to set --disable-updater, please don't." % p ath) 55 return mozconfig_path
43 elif not updater_disabled and distribution_mode == "store":
44 raise Exception(
45 "'%s' doesn't seem to set --disable-updater, please do." % path)
46
47 release_build = "export ABB_RELEASE_BUILD=1" in contents
48 if release_build and build_mode != "release":
49 raise Exception("'%s' shouldn't export ABB_RELEASE_BUILD=1." % path)
50 elif not release_build and build_mode == "release":
51 raise Exception("'%s' should export ABB_RELEASE_BUILD=1." % path)
52 56
53 57
54 def find_mozconfig(distribution_mode, build_mode): 58 def build(architecture, distribution_mode, build_mode, sdk_path, ndk_path):
55 mozconfig_path = os.path.join(BASE_DIR, "mozconfig-" + distribution_mode +
56 "-" + build_mode)
57 check_mozconfig(mozconfig_path, distribution_mode, build_mode)
58 return mozconfig_path
59
60
61 def build(distribution_mode, build_mode, sdk_path, ndk_path):
62 build_environment = os.environ.copy() 59 build_environment = os.environ.copy()
63 build_environment["MOZCONFIG"] = find_mozconfig(distribution_mode, build_mod e) 60 build_environment["MOZCONFIG"] = generate_mozconfig(
anton 2016/12/01 07:03:58 it might be more reliable not just remove `find_mo
diegocarloslima 2016/12/01 10:35:59 I understand your point of view, but my reasons to
61 architecture, distribution_mode, build_mode)
64 build_environment["ANDROID_SDK_PATH"] = sdk_path 62 build_environment["ANDROID_SDK_PATH"] = sdk_path
65 build_environment["ANDROID_NDK_PATH"] = ndk_path 63 build_environment["ANDROID_NDK_PATH"] = ndk_path
64 obj_dir = OBJDIR_X86 if architecture == ARCH_X86 else OBJDIR_ARM
65 build_environment["OBJDIR"] = obj_dir
66 subprocess.check_call([os.path.join(ABB_PATH, "mach"), "clobber"], 66 subprocess.check_call([os.path.join(ABB_PATH, "mach"), "clobber"],
67 env=build_environment) 67 env=build_environment)
68 subprocess.check_call([MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], 68 subprocess.check_call([MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"],
69 env=build_environment) 69 env=build_environment)
70 70
71 dist_path = os.path.join(ABB_PATH, obj_dir, "dist")
72 arch_suffix = ARCH_X86_I386 if architecture == ARCH_X86 else ARCH_ARM
71 [manifest_path] = glob.glob(os.path.join( 73 [manifest_path] = glob.glob(os.path.join(
72 DIST_PATH, "fennec-*.multi.android-arm.json")) 74 dist_path, "fennec-*.multi.android-%s.json" % arch_suffix))
73 with open(manifest_path) as manifest_file: 75 with open(manifest_path) as manifest_file:
74 manifest = json.load(manifest_file) 76 manifest = json.load(manifest_file)
75 77
76 apk_path = os.path.join(DIST_PATH, "gecko-unsigned-unaligned.apk") 78 apk_path = os.path.join(dist_path, "gecko-unsigned-unaligned.apk")
77 if build_mode == "release": 79 if build_mode == "release":
78 target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_versio n"] 80 target_apk_name = "adblockbrowser-%s-%s.apk" % (
81 manifest["moz_app_version"], architecture)
79 else: 82 else:
80 target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( 83 target_apk_name = "adblockbrowser-%s.%s-%s.apk" % (
81 manifest["moz_app_version"], manifest["buildid"]) 84 manifest["moz_app_version"], manifest["buildid"], architecture)
82 target_apk_path = os.path.join(DIST_PATH, target_apk_name) 85 target_apk_path = os.path.join(dist_path, target_apk_name)
83 shutil.copyfile(apk_path, target_apk_path) 86 shutil.copyfile(apk_path, target_apk_path)
84 87
85 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) 88 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path)
86 shutil.copyfile(manifest_path, target_manifest_path) 89 shutil.copyfile(manifest_path, target_manifest_path)
87 90
88 return target_apk_path 91 return target_apk_path
89 92
90 93
91 def sign(apk_path, key_store, key_name): 94 def sign(apk_path, key_store, key_name):
92 temp_apk_path = tempfile.NamedTemporaryFile().name 95 temp_apk_path = tempfile.NamedTemporaryFile().name
(...skipping 21 matching lines...) Expand all
114 117
115 if do_sign: 118 if do_sign:
116 if len(sys.argv) < 3: 119 if len(sys.argv) < 3:
117 print_usage() 120 print_usage()
118 sys.exit(3) 121 sys.exit(3)
119 apk_path = sys.argv[2] 122 apk_path = sys.argv[2]
120 123
121 subprocess.check_call([ENSURE_DEPENDENCIES_PATH]) 124 subprocess.check_call([ENSURE_DEPENDENCIES_PATH])
122 import config 125 import config
123 126
127 architecture = config.ARCHITECTURE
128 if architecture not in (ARCH_ARM, ARCH_X86):
129 print >>sys.stderr, "Invalid architecture, check config.py"
130 sys.exit(4)
anton 2016/12/01 07:03:58 From integration point of view (f.e. CI server - l
diegocarloslima 2016/12/01 10:35:59 Acknowledged.
131
124 distribution_mode = config.DISTRIBUTION_MODE 132 distribution_mode = config.DISTRIBUTION_MODE
125 if distribution_mode not in ("standalone", "store"): 133 if distribution_mode not in ("standalone", "store"):
126 print >>sys.stderr, "Invalid distribution mode, check config.py" 134 print >>sys.stderr, "Invalid distribution mode, check config.py"
127 sys.exit(4) 135 sys.exit(5)
128 136
129 build_mode = config.BUILD_MODE 137 build_mode = config.BUILD_MODE
130 if build_mode not in ("devbuild", "release"): 138 if build_mode not in ("devbuild", "release"):
131 print >>sys.stderr, "Invalid build mode, check config.py" 139 print >>sys.stderr, "Invalid build mode, check config.py"
132 sys.exit(5) 140 sys.exit(6)
133 141
134 if do_build: 142 if do_build:
135 apk_path = build(distribution_mode, build_mode, config.ANDROID_SDK_PATH, 143 apk_path = build(architecture, distribution_mode, build_mode,
136 config.ANDROID_NDK_PATH) 144 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH)
137 if do_sign: 145 if do_sign:
138 sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME) 146 sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME)
139 else: 147 else:
140 print apk_path 148 print apk_path
OLDNEW
« no previous file with comments | « adblockbrowser-cfg.py ('k') | config.py.sample » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld