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/.
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):
23 self
, require_config_file
=require_config_file
, **script_kwargs
27 dirs
= self
.query_abs_dirs()
31 mar_path
= os
.path
.join(dirs
["abs_input_dir"], "mar")
32 if self
._is
_windows
():
34 if mar_path
and os
.path
.exists(mar_path
):
35 self
.chmod(mar_path
, 0o755)
36 if self
.config
.get("run_configure", True):
40 def query_abs_dirs(self
):
43 abs_dirs
= super(Repackage
, self
).query_abs_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
64 dirs
= self
.query_abs_dirs()
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"],
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():
88 os
.path
.join(dirs
["abs_input_dir"], filename
),
94 os
.path
.join(dirs
["abs_output_dir"], repack_config
["output"]),
99 cwd
=dirs
["abs_src_dir"],
100 halt_on_failure
=True,
101 env
=self
.query_env(),
104 def _run_tooltool(self
):
106 dirs
= self
.query_abs_dirs()
107 manifest_src
= os
.environ
.get("TOOLTOOL_MANIFEST")
109 manifest_src
= config
.get("tooltool_manifest_src")
116 os
.path
.join(dirs
["abs_src_dir"], "mach"),
122 "--artifact-manifest",
123 os
.path
.join(dirs
["abs_src_dir"], "toolchains.json"),
128 "--tooltool-manifest",
129 os
.path
.join(dirs
["abs_src_dir"], manifest_src
),
132 cache
= config
.get("tooltool_cache")
134 cmd
.extend(["--cache-dir", cache
])
136 self
.run_command(cmd
, cwd
=dirs
["abs_src_dir"], halt_on_failure
=True)
138 def _get_mozconfig(self
):
139 """assign mozconfig."""
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"])
150 "'src_mozconfig' must be in the config "
151 "in order to determine the mozconfig."
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
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(
167 cwd
=dirs
["abs_src_dir"],
168 output_timeout
=60 * 3,
169 halt_on_failure
=True,
173 if __name__
== "__main__":
175 repack
.run_and_exit()