Bug 1856942: part 5) Factor async loading of a sheet out of `Loader::LoadSheet`....
[gecko.git] / testing / mozharness / scripts / repackage.py
blobe26a32c1dbed54f5ff691a1326bbe3e1a24a1aee
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import os
6 import sys
8 sys.path.insert(1, os.path.dirname(sys.path[0])) # noqa - don't warn about imports
10 from mozharness.base.log import FATAL
11 from mozharness.base.script import BaseScript
14 class Repackage(BaseScript):
15 def __init__(self, require_config_file=False):
16 script_kwargs = {
17 "all_actions": [
18 "setup",
19 "repackage",
22 BaseScript.__init__(
23 self, require_config_file=require_config_file, **script_kwargs
26 def setup(self):
27 dirs = self.query_abs_dirs()
29 self._run_tooltool()
31 mar_path = os.path.join(dirs["abs_input_dir"], "mar")
32 if self._is_windows():
33 mar_path += ".exe"
34 if mar_path and os.path.exists(mar_path):
35 self.chmod(mar_path, 0o755)
36 if self.config.get("run_configure", True):
37 self._get_mozconfig()
38 self._run_configure()
40 def query_abs_dirs(self):
41 if self.abs_dirs:
42 return self.abs_dirs
43 abs_dirs = super(Repackage, self).query_abs_dirs()
44 config = self.config
46 dirs = {}
47 dirs["abs_input_dir"] = os.path.join(abs_dirs["base_work_dir"], "fetches")
48 output_dir_suffix = []
49 if config.get("locale"):
50 output_dir_suffix.append(config["locale"])
51 if config.get("repack_id"):
52 output_dir_suffix.append(config["repack_id"])
53 dirs["abs_output_dir"] = os.path.join(
54 abs_dirs["abs_work_dir"], "outputs", *output_dir_suffix
56 for key in dirs.keys():
57 if key not in abs_dirs:
58 abs_dirs[key] = dirs[key]
59 self.abs_dirs = abs_dirs
60 return self.abs_dirs
62 def repackage(self):
63 config = self.config
64 dirs = self.query_abs_dirs()
66 subst = {
67 "package-name": config["package-name"],
68 # sfx-stub is only defined for Windows targets
69 "sfx-stub": config.get("sfx-stub"),
70 "installer-tag": config["installer-tag"],
71 "stub-installer-tag": config["stub-installer-tag"],
72 "wsx-stub": config["wsx-stub"],
74 subst.update(dirs)
75 if config.get("fetch-dir"):
76 subst.update({"fetch-dir": os.path.abspath(config["fetch-dir"])})
78 # Make sure the upload dir is around.
79 self.mkdir_p(dirs["abs_output_dir"])
81 for repack_config in config["repackage_config"]:
82 command = [sys.executable, "mach", "--log-no-times", "repackage"]
83 command.extend([arg.format(**subst) for arg in repack_config["args"]])
84 for arg, filename in repack_config["inputs"].items():
85 command.extend(
87 "--{}".format(arg),
88 os.path.join(dirs["abs_input_dir"], filename),
91 command.extend(
93 "--output",
94 os.path.join(dirs["abs_output_dir"], repack_config["output"]),
97 self.run_command(
98 command=command,
99 cwd=dirs["abs_src_dir"],
100 halt_on_failure=True,
101 env=self.query_env(),
104 def _run_tooltool(self):
105 config = self.config
106 dirs = self.query_abs_dirs()
107 manifest_src = os.environ.get("TOOLTOOL_MANIFEST")
108 if not manifest_src:
109 manifest_src = config.get("tooltool_manifest_src")
110 if not manifest_src:
111 return
113 cmd = [
114 sys.executable,
115 "-u",
116 os.path.join(dirs["abs_src_dir"], "mach"),
117 "artifact",
118 "toolchain",
119 "-v",
120 "--retry",
121 "4",
122 "--artifact-manifest",
123 os.path.join(dirs["abs_src_dir"], "toolchains.json"),
125 if manifest_src:
126 cmd.extend(
128 "--tooltool-manifest",
129 os.path.join(dirs["abs_src_dir"], manifest_src),
132 cache = config.get("tooltool_cache")
133 if cache:
134 cmd.extend(["--cache-dir", cache])
135 self.info(str(cmd))
136 self.run_command(cmd, cwd=dirs["abs_src_dir"], halt_on_failure=True)
138 def _get_mozconfig(self):
139 """assign mozconfig."""
140 c = self.config
141 dirs = self.query_abs_dirs()
142 abs_mozconfig_path = ""
144 # first determine the mozconfig path
145 if c.get("src_mozconfig"):
146 self.info("Using in-tree mozconfig")
147 abs_mozconfig_path = os.path.join(dirs["abs_src_dir"], c["src_mozconfig"])
148 else:
149 self.fatal(
150 "'src_mozconfig' must be in the config "
151 "in order to determine the mozconfig."
154 # print its contents
155 self.read_from_file(abs_mozconfig_path, error_level=FATAL)
157 # finally, copy the mozconfig to a path that 'mach build' expects it to be
158 self.copyfile(
159 abs_mozconfig_path, os.path.join(dirs["abs_src_dir"], ".mozconfig")
162 def _run_configure(self):
163 dirs = self.query_abs_dirs()
164 command = [sys.executable, "mach", "--log-no-times", "configure"]
165 return self.run_command(
166 command=command,
167 cwd=dirs["abs_src_dir"],
168 output_timeout=60 * 3,
169 halt_on_failure=True,
173 if __name__ == "__main__":
174 repack = Repackage()
175 repack.run_and_exit()