Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | # Generate xpi for the simulator addon by: |
michael@0 | 6 | # - building a special gaia profile for it, as we need: |
michael@0 | 7 | # * more languages, and, |
michael@0 | 8 | # * less apps |
michael@0 | 9 | # than b2g desktop's one |
michael@0 | 10 | # - retrieve usefull app version metadata from the build system |
michael@0 | 11 | # - finally, use addon sdk's cfx tool to build the addon xpi |
michael@0 | 12 | # that ships: |
michael@0 | 13 | # * a small firefox addon registering to the app manager |
michael@0 | 14 | # * b2g desktop runtime |
michael@0 | 15 | # * gaia profile |
michael@0 | 16 | |
michael@0 | 17 | import sys, os, re, subprocess |
michael@0 | 18 | from mozbuild.preprocessor import Preprocessor |
michael@0 | 19 | from mozbuild.base import MozbuildObject |
michael@0 | 20 | from mozbuild.util import ensureParentDir |
michael@0 | 21 | from zipfile import ZipFile |
michael@0 | 22 | from distutils.version import LooseVersion |
michael@0 | 23 | |
michael@0 | 24 | ftp_root_path = "/pub/mozilla.org/labs/fxos-simulator" |
michael@0 | 25 | UPDATE_LINK = "https://ftp.mozilla.org" + ftp_root_path + "/%(update_path)s/%(xpi_name)s" |
michael@0 | 26 | UPDATE_URL = "https://ftp.mozilla.org" + ftp_root_path + "/%(update_path)s/update.rdf" |
michael@0 | 27 | XPI_NAME = "fxos-simulator-%(version)s-%(platform)s.xpi" |
michael@0 | 28 | |
michael@0 | 29 | class GaiaBuilder(object): |
michael@0 | 30 | def __init__(self, build, gaia_path): |
michael@0 | 31 | self.build = build |
michael@0 | 32 | self.gaia_path = gaia_path |
michael@0 | 33 | |
michael@0 | 34 | def clean(self): |
michael@0 | 35 | self.build._run_make(target="clean", directory=self.gaia_path) |
michael@0 | 36 | |
michael@0 | 37 | def profile(self, env): |
michael@0 | 38 | self.build._run_make(target="profile", directory=self.gaia_path, num_jobs=1, silent=False, append_env=env) |
michael@0 | 39 | |
michael@0 | 40 | def override_prefs(self, srcfile): |
michael@0 | 41 | # Note that each time we call `make profile` in gaia, a fresh new pref file is created |
michael@0 | 42 | # cat srcfile >> profile/user.js |
michael@0 | 43 | with open(os.path.join(self.gaia_path, "profile", "user.js"), "a") as userJs: |
michael@0 | 44 | userJs.write(open(srcfile).read()) |
michael@0 | 45 | |
michael@0 | 46 | def process_package_overload(src, dst, version, app_buildid): |
michael@0 | 47 | ensureParentDir(dst) |
michael@0 | 48 | # First replace numeric version like '1.3' |
michael@0 | 49 | # Then replace with 'slashed' version like '1_4' |
michael@0 | 50 | # Finally set the full length addon version like 1.3.20131230 |
michael@0 | 51 | # (reduce the app build id to only the build date |
michael@0 | 52 | # as addon manager doesn't handle big ints in addon versions) |
michael@0 | 53 | defines = { |
michael@0 | 54 | "NUM_VERSION": version, |
michael@0 | 55 | "SLASH_VERSION": version.replace(".", "_"), |
michael@0 | 56 | "FULL_VERSION": ("%s.%s" % (version, app_buildid[:8])) |
michael@0 | 57 | } |
michael@0 | 58 | pp = Preprocessor(defines=defines) |
michael@0 | 59 | pp.do_filter("substitution") |
michael@0 | 60 | with open(dst, "w") as output: |
michael@0 | 61 | with open(src, "r") as input: |
michael@0 | 62 | pp.processFile(input=input, output=output) |
michael@0 | 63 | |
michael@0 | 64 | def add_dir_to_zip(zip, top, pathInZip, blacklist=()): |
michael@0 | 65 | zf = ZipFile(zip, "a") |
michael@0 | 66 | for dirpath, subdirs, files in os.walk(top): |
michael@0 | 67 | dir_relpath = os.path.relpath(dirpath, top) |
michael@0 | 68 | if dir_relpath.startswith(blacklist): |
michael@0 | 69 | continue |
michael@0 | 70 | zf.write(dirpath, os.path.join(pathInZip, dir_relpath)) |
michael@0 | 71 | for filename in files: |
michael@0 | 72 | relpath = os.path.join(dir_relpath, filename) |
michael@0 | 73 | if relpath in blacklist: |
michael@0 | 74 | continue |
michael@0 | 75 | zf.write(os.path.join(dirpath, filename), |
michael@0 | 76 | os.path.join(pathInZip, relpath)) |
michael@0 | 77 | zf.close() |
michael@0 | 78 | |
michael@0 | 79 | def main(platform): |
michael@0 | 80 | build = MozbuildObject.from_environment() |
michael@0 | 81 | topsrcdir = build.topsrcdir |
michael@0 | 82 | distdir = build.distdir |
michael@0 | 83 | |
michael@0 | 84 | srcdir = os.path.join(topsrcdir, "b2g", "simulator") |
michael@0 | 85 | |
michael@0 | 86 | app_buildid = open(os.path.join(build.topobjdir, "config", "buildid")).read().strip() |
michael@0 | 87 | |
michael@0 | 88 | # The simulator uses a shorter version string, |
michael@0 | 89 | # it only keeps the major version digits A.B |
michael@0 | 90 | # whereas MOZ_B2G_VERSION is A.B.C.D |
michael@0 | 91 | b2g_version = build.config_environment.defines["MOZ_B2G_VERSION"].replace('"', '') |
michael@0 | 92 | version = ".".join(str(n) for n in LooseVersion(b2g_version).version[0:2]) |
michael@0 | 93 | |
michael@0 | 94 | # Build a gaia profile specific to the simulator in order to: |
michael@0 | 95 | # - disable the FTU |
michael@0 | 96 | # - set custom prefs to enable devtools debugger server |
michael@0 | 97 | # - set custom settings to disable lockscreen and screen timeout |
michael@0 | 98 | # - only ship production apps |
michael@0 | 99 | gaia_path = build.config_environment.substs["GAIADIR"] |
michael@0 | 100 | builder = GaiaBuilder(build, gaia_path) |
michael@0 | 101 | builder.clean() |
michael@0 | 102 | env = { |
michael@0 | 103 | "NOFTU": "1", |
michael@0 | 104 | "GAIA_APP_TARGET": "production", |
michael@0 | 105 | "SETTINGS_PATH": os.path.join(srcdir, "custom-settings.json") |
michael@0 | 106 | } |
michael@0 | 107 | builder.profile(env) |
michael@0 | 108 | builder.override_prefs(os.path.join(srcdir, "custom-prefs.js")) |
michael@0 | 109 | |
michael@0 | 110 | # Substitute version strings in the package manifest overload file |
michael@0 | 111 | manifest_overload = os.path.join(build.topobjdir, "b2g", "simulator", "package-overload.json") |
michael@0 | 112 | process_package_overload(os.path.join(srcdir, "package-overload.json.in"), |
michael@0 | 113 | manifest_overload, |
michael@0 | 114 | version, |
michael@0 | 115 | app_buildid) |
michael@0 | 116 | |
michael@0 | 117 | # Build the simulator addon xpi |
michael@0 | 118 | xpi_name = XPI_NAME % {"version": version, "platform": platform} |
michael@0 | 119 | xpi_path = os.path.join(distdir, xpi_name) |
michael@0 | 120 | |
michael@0 | 121 | update_path = "%s/%s" % (version, platform) |
michael@0 | 122 | update_link = UPDATE_LINK % {"update_path": update_path, "xpi_name": xpi_name} |
michael@0 | 123 | update_url = UPDATE_URL % {"update_path": update_path} |
michael@0 | 124 | subprocess.check_call([ |
michael@0 | 125 | build.virtualenv_manager.python_path, os.path.join(topsrcdir, "addon-sdk", "source", "bin", "cfx"), "xpi", \ |
michael@0 | 126 | "--pkgdir", srcdir, \ |
michael@0 | 127 | "--manifest-overload", manifest_overload, \ |
michael@0 | 128 | "--strip-sdk", \ |
michael@0 | 129 | "--update-link", update_link, \ |
michael@0 | 130 | "--update-url", update_url, \ |
michael@0 | 131 | "--static-args", "{\"label\": \"Firefox OS %s\"}" % version, \ |
michael@0 | 132 | "--output-file", xpi_path \ |
michael@0 | 133 | ]) |
michael@0 | 134 | |
michael@0 | 135 | # Ship b2g-desktop, but prevent its gaia profile to be shipped in the xpi |
michael@0 | 136 | add_dir_to_zip(xpi_path, os.path.join(distdir, "b2g"), "b2g", ("gaia", "B2G.app/Contents/MacOS/gaia")) |
michael@0 | 137 | # Then ship our own gaia profile |
michael@0 | 138 | add_dir_to_zip(xpi_path, os.path.join(gaia_path, "profile"), "profile") |
michael@0 | 139 | |
michael@0 | 140 | if __name__ == '__main__': |
michael@0 | 141 | if 2 != len(sys.argv): |
michael@0 | 142 | print("""Usage: |
michael@0 | 143 | python {0} MOZ_PKG_PLATFORM |
michael@0 | 144 | """.format(sys.argv[0])) |
michael@0 | 145 | sys.exit(1) |
michael@0 | 146 | main(*sys.argv[1:]) |
michael@0 | 147 |