| LEFT | RIGHT | 
|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 # This file is part of Adblock Plus <https://adblockplus.org/>, | 2 # This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3 # Copyright (C) 2006-present eyeo GmbH | 3 # Copyright (C) 2006-present eyeo GmbH | 
| 4 # | 4 # | 
| 5 # Adblock Plus is free software: you can redistribute it and/or modify | 5 # Adblock Plus is free software: you can redistribute it and/or modify | 
| 6 # it under the terms of the GNU General Public License version 3 as | 6 # it under the terms of the GNU General Public License version 3 as | 
| 7 # published by the Free Software Foundation. | 7 # published by the Free Software Foundation. | 
| 8 # | 8 # | 
| 9 # Adblock Plus is distributed in the hope that it will be useful, | 9 # Adblock Plus is distributed in the hope that it will be useful, | 
| 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 31 _GENERATED_MOZCONFIG_PATH = os.path.join(_GENERATED_PATH, "mozconfig") | 31 _GENERATED_MOZCONFIG_PATH = os.path.join(_GENERATED_PATH, "mozconfig") | 
| 32 _MOZCONFIG_COMMON_PATH = os.path.join(_BASE_DIR, "mozconfig-common") | 32 _MOZCONFIG_COMMON_PATH = os.path.join(_BASE_DIR, "mozconfig-common") | 
| 33 _MOZCONFIG_ARM_PATH = os.path.join(_BASE_DIR, "mozconfig-arm") | 33 _MOZCONFIG_ARM_PATH = os.path.join(_BASE_DIR, "mozconfig-arm") | 
| 34 _MOZCONFIG_X86_PATH = os.path.join(_BASE_DIR, "mozconfig-x86") | 34 _MOZCONFIG_X86_PATH = os.path.join(_BASE_DIR, "mozconfig-x86") | 
| 35 _MOZCONFIG_STORE_PATH = os.path.join(_BASE_DIR, "mozconfig-store") | 35 _MOZCONFIG_STORE_PATH = os.path.join(_BASE_DIR, "mozconfig-store") | 
| 36 _MOZCONFIG_RELEASE_PATH = os.path.join(_BASE_DIR, "mozconfig-release") | 36 _MOZCONFIG_RELEASE_PATH = os.path.join(_BASE_DIR, "mozconfig-release") | 
| 37 _MOZCONFIG_CUSTOM_PATH = os.path.join(_BASE_DIR, "mozconfig-custom") | 37 _MOZCONFIG_CUSTOM_PATH = os.path.join(_BASE_DIR, "mozconfig-custom") | 
| 38 _MAEMO_LOCALES_PATH = os.path.join(_ABB_PATH, "mobile", "android", "locales", | 38 _MAEMO_LOCALES_PATH = os.path.join(_ABB_PATH, "mobile", "android", "locales", | 
| 39                                    "maemo-locales") | 39                                    "maemo-locales") | 
| 40 | 40 | 
|  | 41 _L10N_BASE_PATH = os.path.join(_BASE_DIR, "l10n-central") | 
|  | 42 _LOCALE_CHANGESETS_PATH = os.path.join(_ABB_PATH, "mobile", "locales", | 
|  | 43                                        "l10n-changesets.json") | 
|  | 44 | 
| 41 _CMD_BUILD = "build" | 45 _CMD_BUILD = "build" | 
| 42 _CMD_SIGN = "sign" | 46 _CMD_SIGN = "sign" | 
| 43 _CMD_BUILD_SIGN = "build-and-sign" | 47 _CMD_BUILD_SIGN = "build-and-sign" | 
| 44 _ARCH_ARM = "arm" | 48 _ARCH_ARM = "arm" | 
| 45 _ARCH_X86 = "x86" | 49 _ARCH_X86 = "x86" | 
| 46 _ARCH_X86_I386 = "i386" | 50 _ARCH_X86_I386 = "i386" | 
| 47 _ARCHS = (_ARCH_ARM, _ARCH_X86) | 51 _ARCHS = (_ARCH_ARM, _ARCH_X86) | 
| 48 _DIST_STANDALONE = "standalone" | 52 _DIST_STANDALONE = "standalone" | 
| 49 _DIST_STORE = "store" | 53 _DIST_STORE = "store" | 
| 50 _DIST_MODES = (_DIST_STANDALONE, _DIST_STORE) | 54 _DIST_MODES = (_DIST_STANDALONE, _DIST_STORE) | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 75         else: | 79         else: | 
| 76             mozconfig.write(". \"%s\"\n" % _MOZCONFIG_ARM_PATH) | 80             mozconfig.write(". \"%s\"\n" % _MOZCONFIG_ARM_PATH) | 
| 77         if distribution_mode == _DIST_STORE: | 81         if distribution_mode == _DIST_STORE: | 
| 78             mozconfig.write(". \"%s\"\n" % _MOZCONFIG_STORE_PATH) | 82             mozconfig.write(". \"%s\"\n" % _MOZCONFIG_STORE_PATH) | 
| 79         if build_mode == _BUILD_RELEASE: | 83         if build_mode == _BUILD_RELEASE: | 
| 80             mozconfig.write(". \"%s\"\n" % _MOZCONFIG_RELEASE_PATH) | 84             mozconfig.write(". \"%s\"\n" % _MOZCONFIG_RELEASE_PATH) | 
| 81         mozconfig.write(". \"%s\"\n" % _MOZCONFIG_CUSTOM_PATH) | 85         mozconfig.write(". \"%s\"\n" % _MOZCONFIG_CUSTOM_PATH) | 
| 82         return _GENERATED_MOZCONFIG_PATH | 86         return _GENERATED_MOZCONFIG_PATH | 
| 83 | 87 | 
| 84 | 88 | 
|  | 89 def _checkout_l10n(): | 
|  | 90     with open(_LOCALE_CHANGESETS_PATH, "r") as fd: | 
|  | 91         changesets = json.load(fd) | 
|  | 92 | 
|  | 93     if not os.path.exists(_L10N_BASE_PATH): | 
|  | 94         os.makedirs(_L10N_BASE_PATH) | 
|  | 95 | 
|  | 96     l10n_base_repo = "https://hg.mozilla.org/l10n-central/%s/" | 
|  | 97     for locale in changesets.keys(): | 
|  | 98             revision = changesets[locale]["revision"] | 
|  | 99             repo_path = os.path.join(_L10N_BASE_PATH, locale) | 
|  | 100             if os.path.exists(repo_path): | 
|  | 101                 update_cmd = ["hg", "up", "-r", revision] | 
|  | 102                 if subprocess.call(update_cmd, cwd=repo_path): | 
|  | 103                     subprocess.check_call(["hg", "pull"], cwd=repo_path) | 
|  | 104                     subprocess.check_call(update_cmd, cwd=repo_path) | 
|  | 105 | 
|  | 106             else: | 
|  | 107                 repo = l10n_base_repo % locale | 
|  | 108                 subprocess.check_call(["hg", "clone", repo, "-r", revision], | 
|  | 109                                       cwd=_L10N_BASE_PATH) | 
|  | 110 | 
|  | 111 | 
| 85 def _read_locales(): | 112 def _read_locales(): | 
| 86     with open(_MAEMO_LOCALES_PATH, "r") as fd: | 113     with open(_MAEMO_LOCALES_PATH, "r") as fd: | 
| 87         lines = fd.readlines() | 114         lines = fd.readlines() | 
| 88 | 115 | 
| 89     return [line.strip() for line in lines] | 116     return [line.strip() for line in lines] | 
| 90 | 117 | 
| 91 | 118 | 
| 92 def _config_build_env(architecture, distribution_mode, build_mode, sdk_path, | 119 def _config_build_env(architecture, distribution_mode, build_mode, sdk_path, | 
| 93                       ndk_path, obj_dir, locales): | 120                       ndk_path, obj_dir, locales): | 
| 94     build_env = os.environ.copy() | 121     build_env = os.environ.copy() | 
| 95     build_env["ANDROID_SDK_PATH"] = sdk_path | 122     build_env["ANDROID_SDK_PATH"] = sdk_path | 
| 96     build_env["ANDROID_NDK_PATH"] = ndk_path | 123     build_env["ANDROID_NDK_PATH"] = ndk_path | 
| 97     mozconfig_path = _generate_mozconfig(architecture, distribution_mode, | 124     mozconfig_path = _generate_mozconfig(architecture, distribution_mode, | 
| 98                                          build_mode) | 125                                          build_mode) | 
| 99 | 126 | 
| 100     build_env["MOZCONFIG"] = mozconfig_path | 127     build_env["MOZCONFIG"] = mozconfig_path | 
| 101     build_env["OBJDIR"] = obj_dir | 128     build_env["OBJDIR"] = obj_dir | 
|  | 129     build_env["L10NBASEDIR"] = _L10N_BASE_PATH | 
| 102     build_env["MOZ_CHROME_MULTILOCALE"] = ' '.join(locales) | 130     build_env["MOZ_CHROME_MULTILOCALE"] = ' '.join(locales) | 
| 103     build_env["AB_CD"] = "multi" | 131     build_env["AB_CD"] = "multi" | 
| 104     return build_env | 132     return build_env | 
| 105 | 133 | 
| 106 | 134 | 
| 107 def _create_target_apk(architecture, distribution_mode, build_mode, obj_dir): | 135 def _create_target_apk(architecture, distribution_mode, build_mode, obj_dir): | 
| 108     dist_path = os.path.join(_ABB_PATH, obj_dir, "dist") | 136     dist_path = os.path.join(_ABB_PATH, obj_dir, "dist") | 
| 109     arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM | 137     arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM | 
| 110     [manifest_path] = glob.glob(os.path.join( | 138     [manifest_path] = glob.glob(os.path.join( | 
| 111         dist_path, "fennec-*.en-US.android-%s.json" % arch_suffix)) | 139         dist_path, "fennec-*.en-US.android-%s.json" % arch_suffix)) | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 129         manifest["moz_app_version"], build_suffix, architecture, dist_suffix) | 157         manifest["moz_app_version"], build_suffix, architecture, dist_suffix) | 
| 130 | 158 | 
| 131     target_apk_path = os.path.join(dist_path, target_apk_name) | 159     target_apk_path = os.path.join(dist_path, target_apk_name) | 
| 132     shutil.copyfile(apk_path, target_apk_path) | 160     shutil.copyfile(apk_path, target_apk_path) | 
| 133     target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) | 161     target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) | 
| 134     shutil.copyfile(manifest_path, target_manifest_path) | 162     shutil.copyfile(manifest_path, target_manifest_path) | 
| 135     return target_apk_path | 163     return target_apk_path | 
| 136 | 164 | 
| 137 | 165 | 
| 138 def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): | 166 def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): | 
|  | 167     _checkout_l10n() | 
| 139     obj_dir = _OBJDIR_X86 if architecture == _ARCH_X86 else _OBJDIR_ARM | 168     obj_dir = _OBJDIR_X86 if architecture == _ARCH_X86 else _OBJDIR_ARM | 
| 140     locales = _read_locales() | 169     locales = _read_locales() | 
| 141     build_env = _config_build_env(architecture, distribution_mode, build_mode, | 170     build_env = _config_build_env(architecture, distribution_mode, build_mode, | 
| 142                                   sdk_path, ndk_path, obj_dir, locales) | 171                                   sdk_path, ndk_path, obj_dir, locales) | 
| 143 | 172 | 
| 144     mach_path = os.path.join(_ABB_PATH, "mach") | 173     mach_path = os.path.join(_ABB_PATH, "mach") | 
| 145     subprocess.check_call([mach_path, "clobber"], env=build_env, cwd=_ABB_PATH) | 174     subprocess.check_call([mach_path, "clobber"], env=build_env, cwd=_ABB_PATH) | 
| 146     subprocess.check_call([mach_path, "build"], env=build_env, cwd=_ABB_PATH) | 175     subprocess.check_call([mach_path, "build"], env=build_env, cwd=_ABB_PATH) | 
| 147     for locale in locales: | 176     for locale in locales: | 
| 148         chrome_str = "chrome-%s" % locale | 177         chrome_str = "chrome-%s" % locale | 
| 149         subprocess.check_call([mach_path, "build", chrome_str], env=build_env, | 178         subprocess.check_call([mach_path, "build", chrome_str], env=build_env, | 
| 150                               cwd=_ABB_PATH) | 179                               cwd=_ABB_PATH) | 
| 151 | 180 | 
| 152     obj_dir_path = os.path.join(_ABB_PATH, obj_dir) | 181     obj_dir_path = os.path.join(_ABB_PATH, obj_dir) | 
| 153     import transform_locales as tl | 182     import transform_locales as tl | 
| 154     tl.transform_locales(_ABB_PATH, obj_dir_path) | 183     tl.transform_locales(_ABB_PATH, obj_dir_path) | 
| 155     # build_env["AB_CD"] = "multi" |  | 
| 156     subprocess.check_call([mach_path, "package"], env=build_env, cwd=_ABB_PATH) | 184     subprocess.check_call([mach_path, "package"], env=build_env, cwd=_ABB_PATH) | 
| 157     return _create_target_apk(architecture, distribution_mode, build_mode, | 185     return _create_target_apk(architecture, distribution_mode, build_mode, | 
| 158                               obj_dir) | 186                               obj_dir) | 
| 159 | 187 | 
| 160 | 188 | 
| 161 def _sign(apk_path, key_store, key_name, sdk_path): | 189 def _sign(apk_path, key_store, key_name, sdk_path): | 
| 162     sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot")) | 190     sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot")) | 
| 163     from android import ANDROID_BUILD_TOOLS_VERSION | 191     from android import ANDROID_BUILD_TOOLS_VERSION | 
| 164     zipalign_path = os.path.join(sdk_path, "build-tools", | 192     zipalign_path = os.path.join(sdk_path, "build-tools", | 
| 165                                  ANDROID_BUILD_TOOLS_VERSION, "zipalign") | 193                                  ANDROID_BUILD_TOOLS_VERSION, "zipalign") | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 220         sys.exit(6) | 248         sys.exit(6) | 
| 221 | 249 | 
| 222     if do_build: | 250     if do_build: | 
| 223         apk_path = _build(architecture, distribution_mode, build_mode, | 251         apk_path = _build(architecture, distribution_mode, build_mode, | 
| 224                           config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) | 252                           config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) | 
| 225     if do_sign: | 253     if do_sign: | 
| 226         _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME, | 254         _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME, | 
| 227               config.ANDROID_SDK_PATH) | 255               config.ANDROID_SDK_PATH) | 
| 228     else: | 256     else: | 
| 229         print(apk_path) | 257         print(apk_path) | 
| LEFT | RIGHT | 
|---|