| 1 |
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- |
| 2 |
# vim: set filetype=python: |
| 3 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
include("util.configure") |
| 8 |
include("checks.configure") |
| 9 |
|
| 10 |
# Make `toolkit` available when toolkit/moz.configure is not included. |
| 11 |
toolkit = dependable(None) |
| 12 |
# Likewise with `bindgen_config_paths` when |
| 13 |
# build/moz.configure/bindgen.configure is not included. |
| 14 |
bindgen_config_paths = dependable(None) |
| 15 |
|
| 16 |
|
| 17 |
@depends("--help") |
| 18 |
def build_environment(_): |
| 19 |
topobjdir = os.path.realpath(".") |
| 20 |
topsrcdir = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) |
| 21 |
dist = os.path.join(topobjdir, "dist") |
| 22 |
|
| 23 |
return namespace( |
| 24 |
topsrcdir=topsrcdir, |
| 25 |
topobjdir=topobjdir, |
| 26 |
dist=dist, |
| 27 |
) |
| 28 |
|
| 29 |
|
| 30 |
@depends(build_environment) |
| 31 |
@imports(_import="json") |
| 32 |
@imports(_from="pathlib", _import="Path") |
| 33 |
def configure_cache(build_environment): |
| 34 |
""" |
| 35 |
This cache is used to cache the results of compiler invocations |
| 36 |
between different runs of configure and save them to the disk, which |
| 37 |
results in a significant speed up of subsequent configure runs (15%-50%). |
| 38 |
|
| 39 |
It is not currently thread safe because it is just a simple dictionary |
| 40 |
wrapped in a dummy class (ConfigureCache). It could be improved to be |
| 41 |
thread safe in the future, if we ever make configure parallelized, but |
| 42 |
for now there is no advantage to doing so. |
| 43 |
""" |
| 44 |
|
| 45 |
class ConfigureCache(dict): |
| 46 |
pass |
| 47 |
|
| 48 |
cache_file = Path(build_environment.topobjdir) / "configure.cache" |
| 49 |
if cache_file.exists(): |
| 50 |
with cache_file.open() as f: |
| 51 |
cache_data = json.load(f) |
| 52 |
else: |
| 53 |
cache_data = {} |
| 54 |
|
| 55 |
cache = ConfigureCache(cache_data) |
| 56 |
cache.version_checked_compilers = set() |
| 57 |
|
| 58 |
return cache |
| 59 |
|
| 60 |
|
| 61 |
set_config("TOPSRCDIR", build_environment.topsrcdir) |
| 62 |
set_config("TOPOBJDIR", build_environment.topobjdir) |
| 63 |
set_config("DIST", build_environment.dist) |
| 64 |
|
| 65 |
option(env="MOZ_AUTOMATION", help="Enable options for automated builds") |
| 66 |
|
| 67 |
|
| 68 |
@depends("MOZ_AUTOMATION") |
| 69 |
def moz_automation(value): |
| 70 |
return bool(value) |
| 71 |
|
| 72 |
|
| 73 |
set_config("MOZ_AUTOMATION", moz_automation) |
| 74 |
|
| 75 |
option(env="MOZCONFIG", nargs=1, help="Mozconfig location") |
| 76 |
|
| 77 |
# Read user mozconfig |
| 78 |
# ============================================================== |
| 79 |
# Note: the dependency on --help is only there to always read the mozconfig, |
| 80 |
# even when --help is passed. Without this dependency, the function wouldn't |
| 81 |
# be called when --help is passed, and the mozconfig wouldn't be read. |
| 82 |
|
| 83 |
|
| 84 |
@depends("MOZCONFIG", build_environment, "--help") |
| 85 |
@imports(_from="mozbuild.mozconfig", _import="MozconfigLoader") |
| 86 |
@imports(_from="mozboot.mozconfig", _import="find_mozconfig") |
| 87 |
@imports("os") |
| 88 |
def mozconfig(mozconfig, build_env, help): |
| 89 |
# Don't read the mozconfig for the js configure (yay backwards |
| 90 |
# compatibility) |
| 91 |
# While the long term goal is that js and top-level use the same configure |
| 92 |
# and the same overall setup, including the possibility to use mozconfigs, |
| 93 |
# figuring out what we want to do wrt mozconfig vs. command line and |
| 94 |
# environment variable is not a clear-cut case, and it's more important to |
| 95 |
# fix the immediate problem mozconfig causes to js developers by |
| 96 |
# "temporarily" returning to the previous behavior of not loading the |
| 97 |
# mozconfig for the js configure. |
| 98 |
# Separately to the immediate problem for js developers, there is also the |
| 99 |
# need to not load a mozconfig when running js configure as a subconfigure. |
| 100 |
is_js_configure = "MOZ_JS_CONFIGURE" in os.environ |
| 101 |
if is_js_configure or (mozconfig and mozconfig[0] == os.devnull): |
| 102 |
return {"path": None} |
| 103 |
|
| 104 |
topsrcdir = build_env.topsrcdir |
| 105 |
loader = MozconfigLoader(topsrcdir) |
| 106 |
mozconfig = mozconfig[0] if mozconfig else None |
| 107 |
mozconfig = find_mozconfig(topsrcdir, env={"MOZCONFIG": mozconfig}) |
| 108 |
mozconfig = loader.read_mozconfig(mozconfig) |
| 109 |
|
| 110 |
return mozconfig |
| 111 |
|
| 112 |
|
| 113 |
set_config("MOZCONFIG", depends(mozconfig)(lambda m: m["path"])) |
| 114 |
|
| 115 |
|
| 116 |
# Mozilla-Build |
| 117 |
# ============================================================== |
| 118 |
option(env="MOZILLABUILD", nargs=1, help="Path to Mozilla Build (Windows-only)") |
| 119 |
|
| 120 |
option(env="CONFIG_SHELL", nargs=1, help="Path to a POSIX shell") |
| 121 |
|
| 122 |
# It feels dirty replicating this from python/mozbuild/mozbuild/mozconfig.py, |
| 123 |
# but the end goal being that the configure script would go away... |
| 124 |
|
| 125 |
|
| 126 |
@depends("CONFIG_SHELL", "MOZILLABUILD") |
| 127 |
@checking("for a shell") |
| 128 |
@imports("sys") |
| 129 |
@imports(_from="pathlib", _import="Path") |
| 130 |
def shell(value, mozillabuild): |
| 131 |
if value: |
| 132 |
return find_program(value[0]) |
| 133 |
shell = "sh" |
| 134 |
if mozillabuild: |
| 135 |
if (Path(mozillabuild[0]) / "msys2").exists(): |
| 136 |
shell = mozillabuild[0] + "/msys2/usr/bin/sh" |
| 137 |
else: |
| 138 |
shell = mozillabuild[0] + "/msys/bin/sh" |
| 139 |
if sys.platform == "win32": |
| 140 |
shell = shell + ".exe" |
| 141 |
return find_program(shell) |
| 142 |
|
| 143 |
|
| 144 |
# This defines a reasonable shell for when running with --help. |
| 145 |
# If one was passed in the environment, though, fall back to that. |
| 146 |
@depends("--help", "CONFIG_SHELL") |
| 147 |
def help_shell(help, shell): |
| 148 |
if help and not shell: |
| 149 |
return "sh" |
| 150 |
|
| 151 |
|
| 152 |
shell = help_shell | shell |
| 153 |
set_config("SHELL", shell) |
| 154 |
|
| 155 |
|
| 156 |
# Python 3 |
| 157 |
# ======== |
| 158 |
@dependable |
| 159 |
@checking("for Python 3", callback=lambda x: "%s (%s)" % (x.path, x.str_version)) |
| 160 |
@imports("sys") |
| 161 |
@imports(_from="mach.site", _import="PythonVirtualenv") |
| 162 |
@imports(_from="os.path", _import="realpath") |
| 163 |
def virtualenv_python3(): |
| 164 |
return namespace( |
| 165 |
# sys.executable is currently not updated for in-process activations. However, |
| 166 |
# sys.prefix is, so we can calculate the python executable's path from there. |
| 167 |
path=normalize_path(PythonVirtualenv(realpath(sys.prefix)).python_path), |
| 168 |
str_version=".".join(str(i) for i in sys.version_info[0:3]), |
| 169 |
) |
| 170 |
|
| 171 |
|
| 172 |
set_config("PYTHON3", virtualenv_python3.path) |
| 173 |
|
| 174 |
|
| 175 |
# Inject mozconfig options |
| 176 |
# ============================================================== |
| 177 |
# All options defined above this point can't be injected in mozconfig_options |
| 178 |
# below, so collect them. |
| 179 |
|
| 180 |
|
| 181 |
@template |
| 182 |
def early_options(): |
| 183 |
@depends("--help") |
| 184 |
@imports("__sandbox__") |
| 185 |
def early_options(_): |
| 186 |
return set(option.env for option in __sandbox__._options.values() if option.env) |
| 187 |
|
| 188 |
return early_options |
| 189 |
|
| 190 |
|
| 191 |
early_options = early_options() |
| 192 |
|
| 193 |
|
| 194 |
@depends(mozconfig, early_options, moz_automation, "--help") |
| 195 |
# This gives access to the sandbox. Don't copy this blindly. |
| 196 |
@imports("__sandbox__") |
| 197 |
@imports("os") |
| 198 |
def mozconfig_options(mozconfig, early_options, automation, help): |
| 199 |
if mozconfig["path"]: |
| 200 |
if "MOZ_AUTOMATION_MOZCONFIG" in mozconfig["env"]["added"]: |
| 201 |
if not automation: |
| 202 |
log.error( |
| 203 |
"%s directly or indirectly includes an in-tree " "mozconfig.", |
| 204 |
mozconfig["path"], |
| 205 |
) |
| 206 |
log.error( |
| 207 |
"In-tree mozconfigs make strong assumptions about " |
| 208 |
"and are only meant to be used by Mozilla " |
| 209 |
"automation." |
| 210 |
) |
| 211 |
die("Please don't use them.") |
| 212 |
helper = __sandbox__._helper |
| 213 |
log.info("Adding configure options from %s" % mozconfig["path"]) |
| 214 |
for arg in mozconfig["configure_args"]: |
| 215 |
log.info(" %s" % arg) |
| 216 |
# We could be using imply_option() here, but it has other |
| 217 |
# contraints that don't really apply to the command-line |
| 218 |
# emulation that mozconfig provides. |
| 219 |
helper.add(arg, origin="mozconfig", args=helper._args) |
| 220 |
|
| 221 |
def add(key, value): |
| 222 |
if key.isupper(): |
| 223 |
arg = "%s=%s" % (key, value) |
| 224 |
log.info(" %s" % arg) |
| 225 |
if key not in early_options: |
| 226 |
helper.add(arg, origin="mozconfig", args=helper._args) |
| 227 |
|
| 228 |
for key, value in mozconfig["env"]["added"].items(): |
| 229 |
add(key, value) |
| 230 |
os.environ[key] = value |
| 231 |
for key, (_, value) in mozconfig["env"]["modified"].items(): |
| 232 |
add(key, value) |
| 233 |
os.environ[key] = value |
| 234 |
for key, value in mozconfig["vars"]["added"].items(): |
| 235 |
add(key, value) |
| 236 |
for key, (_, value) in mozconfig["vars"]["modified"].items(): |
| 237 |
add(key, value) |
| 238 |
|
| 239 |
|
| 240 |
@depends(build_environment, "--help") |
| 241 |
@imports(_from="os.path", _import="exists") |
| 242 |
def js_package(build_env, help): |
| 243 |
return not exists(os.path.join(build_env.topsrcdir, "browser")) |
| 244 |
|
| 245 |
|
| 246 |
# Source checkout and version control integration. |
| 247 |
# ================================================ |
| 248 |
|
| 249 |
|
| 250 |
@depends(build_environment, moz_automation, js_package, "--help") |
| 251 |
@checking("for vcs source checkout") |
| 252 |
@imports("os") |
| 253 |
def vcs_checkout_type(build_env, automation, js_package, help): |
| 254 |
if os.path.exists(os.path.join(build_env.topsrcdir, ".hg")): |
| 255 |
return "hg" |
| 256 |
elif os.path.exists(os.path.join(build_env.topsrcdir, ".git")): |
| 257 |
return "git" |
| 258 |
elif automation and not js_package and not help: |
| 259 |
raise FatalCheckError( |
| 260 |
"unable to resolve VCS type; must run " |
| 261 |
"from a source checkout when MOZ_AUTOMATION " |
| 262 |
"is set" |
| 263 |
) |
| 264 |
|
| 265 |
|
| 266 |
# Resolve VCS binary for detected repository type. |
| 267 |
|
| 268 |
|
| 269 |
# TODO remove hg.exe once bug 1382940 addresses ambiguous executables case. |
| 270 |
hg = check_prog( |
| 271 |
"HG", |
| 272 |
( |
| 273 |
"hg.exe", |
| 274 |
"hg", |
| 275 |
), |
| 276 |
allow_missing=True, |
| 277 |
when=depends(vcs_checkout_type)(lambda x: x == "hg"), |
| 278 |
) |
| 279 |
git = check_prog( |
| 280 |
"GIT", |
| 281 |
("git",), |
| 282 |
allow_missing=True, |
| 283 |
when=depends(vcs_checkout_type)(lambda x: x == "git"), |
| 284 |
) |
| 285 |
|
| 286 |
|
| 287 |
@depends_if(hg) |
| 288 |
@checking("for Mercurial version") |
| 289 |
@imports("os") |
| 290 |
@imports("re") |
| 291 |
def hg_version(hg): |
| 292 |
# HGPLAIN in Mercurial 1.5+ forces stable output, regardless of set |
| 293 |
# locale or encoding. |
| 294 |
env = dict(os.environ) |
| 295 |
env["HGPLAIN"] = "1" |
| 296 |
|
| 297 |
out = check_cmd_output(hg, "--version", env=env) |
| 298 |
|
| 299 |
match = re.search(r"Mercurial Distributed SCM \(version ([^\)]+)", out) |
| 300 |
|
| 301 |
if not match: |
| 302 |
raise FatalCheckError("unable to determine Mercurial version: %s" % out) |
| 303 |
|
| 304 |
# The version string may be "unknown" for Mercurial run out of its own |
| 305 |
# source checkout or for bad builds. But LooseVersion handles it. |
| 306 |
|
| 307 |
return Version(match.group(1)) |
| 308 |
|
| 309 |
|
| 310 |
# Resolve Mercurial config items so other checks have easy access. |
| 311 |
# Do NOT set this in the config because it may contain sensitive data |
| 312 |
# like API keys. |
| 313 |
|
| 314 |
|
| 315 |
@depends_all(build_environment, hg, hg_version) |
| 316 |
@imports("os") |
| 317 |
def hg_config(build_env, hg, version): |
| 318 |
env = dict(os.environ) |
| 319 |
env["HGPLAIN"] = "1" |
| 320 |
|
| 321 |
# Warnings may get sent to stderr. But check_cmd_output() ignores |
| 322 |
# stderr if exit code is 0. And the command should always succeed if |
| 323 |
# `hg version` worked. |
| 324 |
out = check_cmd_output(hg, "config", env=env, cwd=build_env.topsrcdir) |
| 325 |
|
| 326 |
config = {} |
| 327 |
|
| 328 |
for line in out.strip().splitlines(): |
| 329 |
key, value = [s.strip() for s in line.split("=", 1)] |
| 330 |
config[key] = value |
| 331 |
|
| 332 |
return config |
| 333 |
|
| 334 |
|
| 335 |
@depends_if(git) |
| 336 |
@checking("for Git version") |
| 337 |
@imports("re") |
| 338 |
def git_version(git): |
| 339 |
out = check_cmd_output(git, "--version").rstrip() |
| 340 |
|
| 341 |
match = re.search("git version (.*)$", out) |
| 342 |
|
| 343 |
if not match: |
| 344 |
raise FatalCheckError("unable to determine Git version: %s" % out) |
| 345 |
|
| 346 |
return Version(match.group(1)) |
| 347 |
|
| 348 |
|
| 349 |
# Only set VCS_CHECKOUT_TYPE if we resolved the VCS binary. |
| 350 |
# Require resolved VCS info when running in automation so automation's |
| 351 |
# environment is more well-defined. |
| 352 |
|
| 353 |
|
| 354 |
@depends(vcs_checkout_type, hg_version, git_version, moz_automation) |
| 355 |
def exposed_vcs_checkout_type(vcs_checkout_type, hg, git, automation): |
| 356 |
if vcs_checkout_type == "hg": |
| 357 |
if hg: |
| 358 |
return "hg" |
| 359 |
|
| 360 |
if automation: |
| 361 |
raise FatalCheckError("could not resolve Mercurial binary info") |
| 362 |
|
| 363 |
elif vcs_checkout_type == "git": |
| 364 |
if git: |
| 365 |
return "git" |
| 366 |
|
| 367 |
if automation: |
| 368 |
raise FatalCheckError("could not resolve Git binary info") |
| 369 |
elif vcs_checkout_type: |
| 370 |
raise FatalCheckError("unhandled VCS type: %s" % vcs_checkout_type) |
| 371 |
|
| 372 |
|
| 373 |
set_config("VCS_CHECKOUT_TYPE", exposed_vcs_checkout_type) |
| 374 |
|
| 375 |
# The application/project to build |
| 376 |
# ============================================================== |
| 377 |
option( |
| 378 |
"--enable-application", |
| 379 |
nargs=1, |
| 380 |
env="MOZ_BUILD_APP", |
| 381 |
help="Application to build. Same as --enable-project", |
| 382 |
) |
| 383 |
|
| 384 |
|
| 385 |
@depends("--enable-application") |
| 386 |
def application(app): |
| 387 |
if app: |
| 388 |
return app |
| 389 |
|
| 390 |
|
| 391 |
imply_option("--enable-project", application) |
| 392 |
|
| 393 |
|
| 394 |
@depends(build_environment, js_package) |
| 395 |
def default_project(build_env, js_package): |
| 396 |
if js_package or build_env.topobjdir.endswith("/js/src"): |
| 397 |
return "js" |
| 398 |
return "browser" |
| 399 |
|
| 400 |
|
| 401 |
option("--enable-project", nargs=1, default=default_project, help="Project to build") |
| 402 |
|
| 403 |
|
| 404 |
# Artifact builds |
| 405 |
# ============================================================== |
| 406 |
|
| 407 |
option( |
| 408 |
"--enable-artifact-builds", |
| 409 |
env="MOZ_ARTIFACT_BUILDS", |
| 410 |
help="Download and use prebuilt binary artifacts", |
| 411 |
) |
| 412 |
|
| 413 |
|
| 414 |
@depends("--enable-artifact-builds") |
| 415 |
def artifact_builds(value): |
| 416 |
if value: |
| 417 |
return True |
| 418 |
|
| 419 |
|
| 420 |
set_config("MOZ_ARTIFACT_BUILDS", artifact_builds) |
| 421 |
|
| 422 |
# Host and target systems |
| 423 |
# ============================================================== |
| 424 |
option("--host", nargs=1, help="Define the system type performing the build") |
| 425 |
|
| 426 |
option( |
| 427 |
"--target", |
| 428 |
nargs=1, |
| 429 |
help="Define the system type where the resulting executables will be " "used", |
| 430 |
) |
| 431 |
|
| 432 |
|
| 433 |
@imports(_from="mozbuild.configure.constants", _import="Abi") |
| 434 |
@imports(_from="mozbuild.configure.constants", _import="CPU") |
| 435 |
@imports(_from="mozbuild.configure.constants", _import="CPU_bitness") |
| 436 |
@imports(_from="mozbuild.configure.constants", _import="Endianness") |
| 437 |
@imports(_from="mozbuild.configure.constants", _import="Kernel") |
| 438 |
@imports(_from="mozbuild.configure.constants", _import="OS") |
| 439 |
@imports(_from="__builtin__", _import="ValueError") |
| 440 |
def split_triplet(triplet, allow_wasi=False): |
| 441 |
# The standard triplet is defined as |
| 442 |
# CPU_TYPE-VENDOR-OPERATING_SYSTEM |
| 443 |
# There is also a quartet form: |
| 444 |
# CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM |
| 445 |
# But we can consider the "KERNEL-OPERATING_SYSTEM" as one. |
| 446 |
# Additionally, some may omit "unknown" when the vendor |
| 447 |
# is not specified and emit |
| 448 |
# CPU_TYPE-OPERATING_SYSTEM |
| 449 |
vendor = "unknown" |
| 450 |
parts = triplet.split("-", 2) |
| 451 |
if len(parts) == 3: |
| 452 |
cpu, vendor, os = parts |
| 453 |
elif len(parts) == 2: |
| 454 |
cpu, os = parts |
| 455 |
else: |
| 456 |
raise ValueError("Unexpected triplet string: %s" % triplet) |
| 457 |
|
| 458 |
# Autoconf uses config.sub to validate and canonicalize those triplets, |
| 459 |
# but the granularity of its results has never been satisfying to our |
| 460 |
# use, so we've had our own, different, canonicalization. We've also |
| 461 |
# historically not been very consistent with how we use the canonicalized |
| 462 |
# values. Hopefully, this will help us make things better. |
| 463 |
# The tests are inherited from our decades-old autoconf-based configure, |
| 464 |
# which can probably be improved/cleaned up because they are based on a |
| 465 |
# mix of uname and config.guess output, while we now only use the latter, |
| 466 |
# which presumably has a cleaner and leaner output. Let's refine later. |
| 467 |
raw_os = os = os.replace("/", "_") |
| 468 |
abi = None |
| 469 |
sub_configure_alias = triplet |
| 470 |
if "android" in os: |
| 471 |
canonical_os = "Android" |
| 472 |
canonical_kernel = "Linux" |
| 473 |
elif os.startswith("linux"): |
| 474 |
canonical_os = "GNU" |
| 475 |
canonical_kernel = "Linux" |
| 476 |
elif os.startswith("kfreebsd") and os.endswith("-gnu"): |
| 477 |
canonical_os = "GNU" |
| 478 |
canonical_kernel = "kFreeBSD" |
| 479 |
elif os.startswith("gnu"): |
| 480 |
canonical_os = canonical_kernel = "GNU" |
| 481 |
elif os.startswith("mingw") or os in ("windows-msvc", "windows-gnu"): |
| 482 |
canonical_os = canonical_kernel = "WINNT" |
| 483 |
if not os.startswith("mingw"): |
| 484 |
if os == "windows-msvc": |
| 485 |
abi = "msvc" |
| 486 |
elif os == "windows-gnu": |
| 487 |
abi = "mingw" |
| 488 |
# Many things down the line are looking for the string "mingw32" |
| 489 |
# until they are all fixed, we pretend that's the raw os we had |
| 490 |
# in the first place, even when we didn't. |
| 491 |
sub_configure_alias = sub_configure_alias[: -len(os)] + "mingw32" |
| 492 |
raw_os = "mingw32" |
| 493 |
elif os.startswith("darwin"): |
| 494 |
canonical_kernel = "Darwin" |
| 495 |
canonical_os = "OSX" |
| 496 |
elif os.startswith("ios"): |
| 497 |
canonical_kernel = "Darwin" |
| 498 |
canonical_os = "iOS" |
| 499 |
# old-configure does plenty of tests against $target and $target_os |
| 500 |
# and expects darwin for iOS, so make it happy. |
| 501 |
sub_configure_alias = sub_configure_alias[: -len(os)] + "darwin" |
| 502 |
# rust knows ios-sim, clang knows ios-simulator. We only take the |
| 503 |
# former as --target, but we need to make clang happy. |
| 504 |
if os == "ios-sim": |
| 505 |
os = "ios-simulator" |
| 506 |
elif os.startswith("dragonfly"): |
| 507 |
canonical_os = canonical_kernel = "DragonFly" |
| 508 |
elif os.startswith("freebsd"): |
| 509 |
canonical_os = canonical_kernel = "FreeBSD" |
| 510 |
elif os.startswith("netbsd"): |
| 511 |
canonical_os = canonical_kernel = "NetBSD" |
| 512 |
elif os.startswith("openbsd"): |
| 513 |
canonical_os = canonical_kernel = "OpenBSD" |
| 514 |
elif os.startswith("solaris"): |
| 515 |
canonical_os = canonical_kernel = "SunOS" |
| 516 |
elif os.startswith("wasi") and allow_wasi: |
| 517 |
canonical_os = canonical_kernel = "WASI" |
| 518 |
else: |
| 519 |
raise ValueError("Unknown OS: %s" % os) |
| 520 |
|
| 521 |
# The CPU granularity is probably not enough. Moving more things from |
| 522 |
# old-configure will tell us if we need more |
| 523 |
if cpu.endswith("86") or (cpu.startswith("i") and "86" in cpu): |
| 524 |
canonical_cpu = "x86" |
| 525 |
endianness = "little" |
| 526 |
elif cpu in ("x86_64", "ia64"): |
| 527 |
canonical_cpu = cpu |
| 528 |
endianness = "little" |
| 529 |
elif cpu in ("s390", "s390x"): |
| 530 |
canonical_cpu = cpu |
| 531 |
endianness = "big" |
| 532 |
elif cpu in ("powerpc64", "ppc64", "powerpc64le", "ppc64le"): |
| 533 |
canonical_cpu = "ppc64" |
| 534 |
endianness = "little" if "le" in cpu else "big" |
| 535 |
elif cpu in ("powerpc", "ppc", "rs6000") or cpu.startswith("powerpc"): |
| 536 |
canonical_cpu = "ppc" |
| 537 |
endianness = "big" |
| 538 |
elif cpu in ("Alpha", "alpha", "ALPHA"): |
| 539 |
canonical_cpu = "Alpha" |
| 540 |
endianness = "little" |
| 541 |
elif cpu.startswith("hppa") or cpu == "parisc": |
| 542 |
canonical_cpu = "hppa" |
| 543 |
endianness = "big" |
| 544 |
elif cpu.startswith("sparc64") or cpu.startswith("sparcv9"): |
| 545 |
canonical_cpu = "sparc64" |
| 546 |
endianness = "big" |
| 547 |
elif cpu.startswith("sparc") or cpu == "sun4u": |
| 548 |
canonical_cpu = "sparc" |
| 549 |
endianness = "big" |
| 550 |
elif cpu.startswith("arm"): |
| 551 |
canonical_cpu = "arm" |
| 552 |
endianness = "big" if cpu.startswith(("armeb", "armbe")) else "little" |
| 553 |
elif cpu in ("m68k"): |
| 554 |
canonical_cpu = "m68k" |
| 555 |
endianness = "big" |
| 556 |
elif cpu in ("mips", "mipsel"): |
| 557 |
canonical_cpu = "mips32" |
| 558 |
endianness = "little" if "el" in cpu else "big" |
| 559 |
elif cpu in ("mips64", "mips64el"): |
| 560 |
canonical_cpu = "mips64" |
| 561 |
endianness = "little" if "el" in cpu else "big" |
| 562 |
elif cpu.startswith("aarch64"): |
| 563 |
canonical_cpu = "aarch64" |
| 564 |
endianness = "little" |
| 565 |
elif cpu in ("riscv64", "riscv64gc"): |
| 566 |
canonical_cpu = "riscv64" |
| 567 |
endianness = "little" |
| 568 |
elif cpu.startswith("loongarch64"): |
| 569 |
canonical_cpu = "loongarch64" |
| 570 |
endianness = "little" |
| 571 |
elif cpu == "sh4": |
| 572 |
canonical_cpu = "sh4" |
| 573 |
endianness = "little" |
| 574 |
elif cpu == "wasm32" and allow_wasi: |
| 575 |
canonical_cpu = "wasm32" |
| 576 |
endianness = "little" |
| 577 |
else: |
| 578 |
raise ValueError("Unknown CPU type: %s" % cpu) |
| 579 |
|
| 580 |
# Toolchains, most notably for cross compilation may use cpu-os |
| 581 |
# prefixes. We need to be more specific about the LLVM target on Mac |
| 582 |
# so cross-language LTO will work correctly. |
| 583 |
|
| 584 |
if os.startswith(("darwin", "ios")): |
| 585 |
toolchain = "%s-apple-%s" % (cpu, os) |
| 586 |
else: |
| 587 |
toolchain = "%s-%s" % (cpu, os) |
| 588 |
|
| 589 |
return namespace( |
| 590 |
alias=triplet, |
| 591 |
cpu=CPU(canonical_cpu), |
| 592 |
bitness=CPU_bitness[canonical_cpu], |
| 593 |
kernel=Kernel(canonical_kernel), |
| 594 |
os=OS(canonical_os), |
| 595 |
endianness=Endianness(endianness), |
| 596 |
# For now, only report the Windows ABI. |
| 597 |
abi=abi and Abi(abi), |
| 598 |
raw_cpu=cpu, |
| 599 |
raw_os=raw_os, |
| 600 |
toolchain=toolchain, |
| 601 |
vendor=vendor, |
| 602 |
sub_configure_alias=sub_configure_alias, |
| 603 |
) |
| 604 |
|
| 605 |
|
| 606 |
# This defines a fake target/host namespace for when running with --help |
| 607 |
# If either --host or --target is passed on the command line, then fall |
| 608 |
# back to the real deal. |
| 609 |
@depends("--help", "--host", "--target") |
| 610 |
def help_host_target(help, host, target): |
| 611 |
if help and not host and not target: |
| 612 |
return namespace( |
| 613 |
alias="unknown-unknown-unknown", |
| 614 |
cpu="unknown", |
| 615 |
bitness="unknown", |
| 616 |
kernel="unknown", |
| 617 |
os="unknown", |
| 618 |
endianness="unknown", |
| 619 |
abi="unknown", |
| 620 |
raw_cpu="unknown", |
| 621 |
raw_os="unknown", |
| 622 |
toolchain="unknown-unknown", |
| 623 |
) |
| 624 |
|
| 625 |
|
| 626 |
def config_sub(shell, triplet): |
| 627 |
config_sub = os.path.join(os.path.dirname(__file__), "..", "autoconf", "config.sub") |
| 628 |
# Config.sub doesn't like the *-windows-msvc/*-windows-gnu/*-ios-sim triplets, so |
| 629 |
# munge those before and after calling config.sub. |
| 630 |
suffix = None |
| 631 |
munging = { |
| 632 |
"-windows-msvc": "-mingw32", |
| 633 |
"-windows-gnu": "-mingw32", |
| 634 |
"-ios-sim": "-ios", |
| 635 |
} |
| 636 |
for check_suffix, replacement in munging.items(): |
| 637 |
if triplet.endswith(check_suffix): |
| 638 |
suffix = check_suffix |
| 639 |
triplet = triplet[: -len(suffix)] + replacement |
| 640 |
break |
| 641 |
result = check_cmd_output(shell, config_sub, triplet).strip() |
| 642 |
if suffix: |
| 643 |
assert result.endswith(replacement) |
| 644 |
result = result[: -len(replacement)] + suffix |
| 645 |
return result |
| 646 |
|
| 647 |
|
| 648 |
@depends("--host", shell) |
| 649 |
@checking("for host system type", lambda h: h.alias) |
| 650 |
@imports("os") |
| 651 |
@imports("sys") |
| 652 |
@imports(_from="__builtin__", _import="ValueError") |
| 653 |
def real_host(value, shell): |
| 654 |
if not value and sys.platform == "win32": |
| 655 |
arch = os.environ.get("PROCESSOR_ARCHITEW6432") or os.environ.get( |
| 656 |
"PROCESSOR_ARCHITECTURE" |
| 657 |
) |
| 658 |
if arch == "AMD64": |
| 659 |
return split_triplet("x86_64-pc-windows-msvc") |
| 660 |
elif arch == "x86": |
| 661 |
return split_triplet("i686-pc-windows-msvc") |
| 662 |
elif arch == "ARM64": |
| 663 |
return split_triplet("aarch64-pc-windows-msvc") |
| 664 |
|
| 665 |
if not value: |
| 666 |
config_guess = os.path.join( |
| 667 |
os.path.dirname(__file__), "..", "autoconf", "config.guess" |
| 668 |
) |
| 669 |
|
| 670 |
# Ensure that config.guess is determining the host triplet, not the target |
| 671 |
# triplet |
| 672 |
env = os.environ.copy() |
| 673 |
env.pop("CC_FOR_BUILD", None) |
| 674 |
env.pop("HOST_CC", None) |
| 675 |
env.pop("CC", None) |
| 676 |
|
| 677 |
host = check_cmd_output(shell, config_guess, env=env).strip() |
| 678 |
try: |
| 679 |
return split_triplet(host) |
| 680 |
except ValueError: |
| 681 |
pass |
| 682 |
else: |
| 683 |
host = value[0] |
| 684 |
|
| 685 |
host = config_sub(shell, host) |
| 686 |
|
| 687 |
try: |
| 688 |
return split_triplet(host) |
| 689 |
except ValueError as e: |
| 690 |
die(e) |
| 691 |
|
| 692 |
|
| 693 |
host = help_host_target | real_host |
| 694 |
|
| 695 |
|
| 696 |
@depends("--target", real_host, shell, "--enable-project", "--enable-application") |
| 697 |
@checking("for target system type", lambda t: t.alias) |
| 698 |
@imports(_from="__builtin__", _import="ValueError") |
| 699 |
def real_target(value, host, shell, project, application): |
| 700 |
# Because --enable-project is implied by --enable-application, and |
| 701 |
# implied options are not currently handled during --help, which is |
| 702 |
# used get the build target in mozbuild.base, we manually check |
| 703 |
# whether --enable-application was given, and fall back to |
| 704 |
# --enable-project if not. Both can't be given contradictory values |
| 705 |
# under normal circumstances, so it's fine. |
| 706 |
if application: |
| 707 |
project = application[0] |
| 708 |
elif project: |
| 709 |
project = project[0] |
| 710 |
if not value: |
| 711 |
if project == "mobile/android": |
| 712 |
target_cpu, target_system = { |
| 713 |
"aarch64": ("aarch64", "android"), |
| 714 |
"x86_64": ("x86_64", "android"), |
| 715 |
}.get(host.cpu, ("arm", "androideabi")) |
| 716 |
return split_triplet(f"{target_cpu}-unknown-linux-{target_system}") |
| 717 |
if project == "mobile/ios": |
| 718 |
if (host.cpu, host.os) == ("x86_64", "OSX"): |
| 719 |
return split_triplet(f"x86_64-apple-ios") |
| 720 |
return split_triplet(f"aarch64-apple-ios-sim") |
| 721 |
return host |
| 722 |
# If --target was only given a cpu arch, expand it with the |
| 723 |
# non-cpu part of the host. For mobile/android, expand it with |
| 724 |
# unknown-linux-android. |
| 725 |
target = value[0] |
| 726 |
if "-" not in target: |
| 727 |
if project == "mobile/android": |
| 728 |
rest = "unknown-linux-android" |
| 729 |
if target.startswith("arm"): |
| 730 |
rest += "eabi" |
| 731 |
elif project == "mobile/ios": |
| 732 |
sim_suffix = "" if target == "x86_64" else "-sim" |
| 733 |
rest = f"apple-ios{sim_suffix}" |
| 734 |
else: |
| 735 |
cpu, rest = host.alias.split("-", 1) |
| 736 |
target = "-".join((target, rest)) |
| 737 |
try: |
| 738 |
return split_triplet(target) |
| 739 |
except ValueError: |
| 740 |
pass |
| 741 |
|
| 742 |
try: |
| 743 |
return split_triplet(config_sub(shell, target), allow_wasi=(project == "js")) |
| 744 |
except ValueError as e: |
| 745 |
die(e) |
| 746 |
|
| 747 |
|
| 748 |
target = help_host_target | real_target |
| 749 |
|
| 750 |
|
| 751 |
@depends(host, target) |
| 752 |
@checking("whether cross compiling") |
| 753 |
def cross_compiling(host, target): |
| 754 |
return host != target |
| 755 |
|
| 756 |
|
| 757 |
set_config("CROSS_COMPILE", cross_compiling) |
| 758 |
set_define("CROSS_COMPILE", cross_compiling) |
| 759 |
|
| 760 |
|
| 761 |
@depends(target) |
| 762 |
def have_64_bit(target): |
| 763 |
if target.bitness == 64: |
| 764 |
return True |
| 765 |
|
| 766 |
|
| 767 |
set_config("HAVE_64BIT_BUILD", have_64_bit) |
| 768 |
set_define("HAVE_64BIT_BUILD", have_64_bit) |
| 769 |
|
| 770 |
# Some third-party code bases depend on this being set for big-endians. |
| 771 |
set_define( |
| 772 |
"WORDS_BIGENDIAN", True, when=depends(target.endianness)(lambda e: e == "big") |
| 773 |
) |
| 774 |
|
| 775 |
set_config("host", host.sub_configure_alias) |
| 776 |
set_config("target", target.sub_configure_alias) |
| 777 |
|
| 778 |
|
| 779 |
# These variables are for compatibility with the current moz.builds and |
| 780 |
# old-configure. Eventually, we'll want to canonicalize better. |
| 781 |
@depends(target) |
| 782 |
def target_variables(target): |
| 783 |
if target.kernel == "kFreeBSD": |
| 784 |
os_target = "GNU/kFreeBSD" |
| 785 |
os_arch = "GNU_kFreeBSD" |
| 786 |
elif target.kernel == "Darwin" or (target.kernel == "Linux" and target.os == "GNU"): |
| 787 |
os_target = target.kernel |
| 788 |
os_arch = target.kernel |
| 789 |
else: |
| 790 |
os_target = target.os |
| 791 |
os_arch = target.kernel |
| 792 |
|
| 793 |
return namespace( |
| 794 |
OS_TARGET=str(os_target), |
| 795 |
OS_ARCH=str(os_arch), |
| 796 |
INTEL_ARCHITECTURE=target.cpu in ("x86", "x86_64") or None, |
| 797 |
) |
| 798 |
|
| 799 |
|
| 800 |
set_config("OS_TARGET", target_variables.OS_TARGET) |
| 801 |
set_config("OS_ARCH", target_variables.OS_ARCH) |
| 802 |
obsolete_config("CPU_ARCH", replacement="TARGET_CPU") |
| 803 |
set_config("INTEL_ARCHITECTURE", target_variables.INTEL_ARCHITECTURE) |
| 804 |
set_config("TARGET_CPU", target.cpu) |
| 805 |
set_config("TARGET_RAW_CPU", target.raw_cpu) |
| 806 |
set_config("TARGET_OS", target.os) |
| 807 |
set_config("TARGET_RAW_OS", target.raw_os) |
| 808 |
set_config("TARGET_KERNEL", target.kernel) |
| 809 |
set_config("TARGET_ENDIANNESS", target.endianness) |
| 810 |
|
| 811 |
|
| 812 |
@depends(host) |
| 813 |
def host_variables(host): |
| 814 |
if host.kernel == "kFreeBSD": |
| 815 |
os_arch = "GNU_kFreeBSD" |
| 816 |
else: |
| 817 |
os_arch = host.kernel |
| 818 |
return namespace( |
| 819 |
HOST_OS_ARCH=os_arch, |
| 820 |
) |
| 821 |
|
| 822 |
|
| 823 |
set_config("HOST_CPU_ARCH", host.cpu) |
| 824 |
set_config("HOST_OS_ARCH", host_variables.HOST_OS_ARCH) |
| 825 |
set_config("HOST_ALIAS", host.alias) |
| 826 |
|
| 827 |
|
| 828 |
@depends(target) |
| 829 |
def target_is_windows(target): |
| 830 |
if target.kernel == "WINNT": |
| 831 |
return True |
| 832 |
|
| 833 |
|
| 834 |
@depends(host) |
| 835 |
def host_is_windows(host): |
| 836 |
if host.kernel == "WINNT": |
| 837 |
return True |
| 838 |
|
| 839 |
|
| 840 |
set_define("_WINDOWS", target_is_windows) |
| 841 |
set_define("WIN32", target_is_windows) |
| 842 |
set_define("XP_WIN", target_is_windows) |
| 843 |
|
| 844 |
|
| 845 |
@depends(target) |
| 846 |
def target_is_unix(target): |
| 847 |
if target.kernel != "WINNT": |
| 848 |
return True |
| 849 |
|
| 850 |
|
| 851 |
set_define("XP_UNIX", target_is_unix) |
| 852 |
|
| 853 |
|
| 854 |
@depends(target) |
| 855 |
def target_is_darwin(target): |
| 856 |
if target.kernel == "Darwin": |
| 857 |
return True |
| 858 |
|
| 859 |
|
| 860 |
set_define("XP_DARWIN", target_is_darwin) |
| 861 |
|
| 862 |
|
| 863 |
@depends(target) |
| 864 |
def target_is_osx(target): |
| 865 |
if target.kernel == "Darwin" and target.os == "OSX": |
| 866 |
return True |
| 867 |
|
| 868 |
|
| 869 |
@depends(host) |
| 870 |
def host_is_osx(host): |
| 871 |
if host.os == "OSX": |
| 872 |
return True |
| 873 |
|
| 874 |
|
| 875 |
set_define("XP_MACOSX", target_is_osx) |
| 876 |
|
| 877 |
|
| 878 |
@depends(target) |
| 879 |
def target_is_ios(target): |
| 880 |
if target.kernel == "Darwin" and target.os == "iOS": |
| 881 |
return True |
| 882 |
|
| 883 |
|
| 884 |
set_define("XP_IOS", target_is_ios) |
| 885 |
|
| 886 |
|
| 887 |
@depends(target) |
| 888 |
def target_has_linux_kernel(target): |
| 889 |
if target.kernel == "Linux": |
| 890 |
return True |
| 891 |
|
| 892 |
|
| 893 |
set_define("XP_LINUX", target_has_linux_kernel) |
| 894 |
|
| 895 |
|
| 896 |
@depends(target) |
| 897 |
def target_is_linux_or_wasi(target): |
| 898 |
if (target.kernel == "Linux" and target.os == "GNU") or target.kernel == "WASI": |
| 899 |
return True |
| 900 |
|
| 901 |
|
| 902 |
@depends(target) |
| 903 |
def target_is_android(target): |
| 904 |
if target.os == "Android": |
| 905 |
return True |
| 906 |
|
| 907 |
|
| 908 |
set_define("ANDROID", target_is_android) |
| 909 |
|
| 910 |
|
| 911 |
@depends(target) |
| 912 |
def target_is_openbsd(target): |
| 913 |
if target.kernel == "OpenBSD": |
| 914 |
return True |
| 915 |
|
| 916 |
|
| 917 |
set_define("XP_OPENBSD", target_is_openbsd) |
| 918 |
|
| 919 |
|
| 920 |
@depends(target) |
| 921 |
def target_is_netbsd(target): |
| 922 |
if target.kernel == "NetBSD": |
| 923 |
return True |
| 924 |
|
| 925 |
|
| 926 |
set_define("XP_NETBSD", target_is_netbsd) |
| 927 |
|
| 928 |
|
| 929 |
@depends(target) |
| 930 |
def target_is_freebsd(target): |
| 931 |
if target.kernel == "FreeBSD": |
| 932 |
return True |
| 933 |
|
| 934 |
|
| 935 |
set_define("XP_FREEBSD", target_is_freebsd) |
| 936 |
|
| 937 |
|
| 938 |
@depends(target) |
| 939 |
def target_is_solaris(target): |
| 940 |
if target.kernel == "SunOS": |
| 941 |
return True |
| 942 |
|
| 943 |
|
| 944 |
set_define("XP_SOLARIS", target_is_solaris) |
| 945 |
|
| 946 |
|
| 947 |
@depends(target) |
| 948 |
def target_is_sparc(target): |
| 949 |
if target.cpu == "sparc64": |
| 950 |
return True |
| 951 |
|
| 952 |
|
| 953 |
set_define("SPARC64", target_is_sparc) |
| 954 |
|
| 955 |
|
| 956 |
@depends(target, when=target_is_android) |
| 957 |
def android_cpu_arch(target): |
| 958 |
d = { |
| 959 |
"aarch64": "arm64-v8a", |
| 960 |
"arm": "armeabi-v7a", |
| 961 |
"x86": "x86", |
| 962 |
"x86_64": "x86_64", |
| 963 |
} |
| 964 |
if target.cpu not in d: |
| 965 |
die(f"Cannot determine android_cpu_arch: unknown target.cpu: {target.cpu}") |
| 966 |
return d[target.cpu] |
| 967 |
|
| 968 |
|
| 969 |
set_config("ANDROID_CPU_ARCH", android_cpu_arch) |
| 970 |
|
| 971 |
|
| 972 |
@depends("--enable-project", build_environment, "--help") |
| 973 |
@imports(_from="os.path", _import="exists") |
| 974 |
def include_project_configure(project, build_env, help): |
| 975 |
if not project: |
| 976 |
die("--enable-project is required.") |
| 977 |
|
| 978 |
base_dir = build_env.topsrcdir |
| 979 |
path = os.path.join(base_dir, project[0], "moz.configure") |
| 980 |
if not exists(path): |
| 981 |
die("Cannot find project %s", project[0]) |
| 982 |
return path |
| 983 |
|
| 984 |
|
| 985 |
@depends("--enable-project") |
| 986 |
def build_project(project): |
| 987 |
return project[0] |
| 988 |
|
| 989 |
|
| 990 |
set_config("MOZ_BUILD_APP", build_project) |
| 991 |
set_define("MOZ_BUILD_APP", build_project) |
| 992 |
|
| 993 |
|
| 994 |
option(env="MOZILLA_OFFICIAL", help="Build an official release") |
| 995 |
|
| 996 |
|
| 997 |
@depends("MOZILLA_OFFICIAL") |
| 998 |
def mozilla_official(official): |
| 999 |
if official: |
| 1000 |
return True |
| 1001 |
|
| 1002 |
|
| 1003 |
set_config("MOZILLA_OFFICIAL", mozilla_official) |
| 1004 |
set_define("MOZILLA_OFFICIAL", mozilla_official) |
| 1005 |
|
| 1006 |
# Allow specifying custom paths to the version files used by the milestone() function below. |
| 1007 |
option( |
| 1008 |
"--with-version-file-path", |
| 1009 |
nargs=1, |
| 1010 |
help="Specify a custom path to app version files instead of auto-detecting", |
| 1011 |
default=None, |
| 1012 |
) |
| 1013 |
|
| 1014 |
|
| 1015 |
@depends("--with-version-file-path") |
| 1016 |
def version_path(path): |
| 1017 |
return path |
| 1018 |
|
| 1019 |
|
| 1020 |
# Allow to easily build nightly with a release / beta configuration so that we |
| 1021 |
# can have the same options we'd have on a release version. |
| 1022 |
# This is useful for performance profiling, as there are things that we don't |
| 1023 |
# enable in release (like the background hang monitor) that can affect |
| 1024 |
# performance. |
| 1025 |
option( |
| 1026 |
"--as-milestone", |
| 1027 |
help="Build with another milestone configuration (e.g., as release)", |
| 1028 |
choices=("early-beta", "late-beta", "release"), |
| 1029 |
default=None, |
| 1030 |
) |
| 1031 |
|
| 1032 |
|
| 1033 |
# set RELEASE_OR_BETA and NIGHTLY_BUILD variables depending on the cycle we're in |
| 1034 |
# The logic works like this: |
| 1035 |
# - if we have "a1" in GRE_MILESTONE, we're building Nightly (define NIGHTLY_BUILD) |
| 1036 |
# - otherwise, we're building Release/Beta (define RELEASE_OR_BETA) |
| 1037 |
@depends( |
| 1038 |
build_environment, |
| 1039 |
build_project, |
| 1040 |
version_path, |
| 1041 |
"--as-milestone", |
| 1042 |
"--help", |
| 1043 |
) |
| 1044 |
@imports(_from="__builtin__", _import="open") |
| 1045 |
@imports("os") |
| 1046 |
@imports("re") |
| 1047 |
def milestone(build_env, build_project, version_path, as_milestone, _): |
| 1048 |
versions = [] |
| 1049 |
paths = ["config/milestone.txt"] |
| 1050 |
if build_project == "js": |
| 1051 |
paths = paths * 3 |
| 1052 |
else: |
| 1053 |
paths += [ |
| 1054 |
"browser/config/version.txt", |
| 1055 |
"browser/config/version_display.txt", |
| 1056 |
] |
| 1057 |
if version_path: |
| 1058 |
version_path = version_path[0] |
| 1059 |
else: |
| 1060 |
version_path = os.path.join(build_project, "config") |
| 1061 |
for f in ("version.txt", "version_display.txt"): |
| 1062 |
f = os.path.join(version_path, f) |
| 1063 |
if not os.path.exists(os.path.join(build_env.topsrcdir, f)): |
| 1064 |
break |
| 1065 |
paths.append(f) |
| 1066 |
|
| 1067 |
for p in paths: |
| 1068 |
with open(os.path.join(build_env.topsrcdir, p), "r") as fh: |
| 1069 |
content = fh.read().splitlines() |
| 1070 |
if not content: |
| 1071 |
die("Could not find a version number in {}".format(p)) |
| 1072 |
versions.append(content[-1]) |
| 1073 |
|
| 1074 |
is_early_beta_or_earlier = None |
| 1075 |
if as_milestone: |
| 1076 |
if "a1" not in versions[0]: |
| 1077 |
# We could make this work with some effort |
| 1078 |
die("--as-milestone only works on nightly builds") |
| 1079 |
as_milestone = as_milestone[0] |
| 1080 |
as_milestone_flag = "" if as_milestone == "release" else "b1" |
| 1081 |
versions = [v.replace("a1", as_milestone_flag) for v in versions] |
| 1082 |
if as_milestone == "early-beta": |
| 1083 |
is_early_beta_or_earlier = True |
| 1084 |
|
| 1085 |
milestone, firefox_version, firefox_version_display = versions[:3] |
| 1086 |
|
| 1087 |
# version.txt content from the project directory if there is one, otherwise |
| 1088 |
# the firefox version. |
| 1089 |
app_version = versions[3] if len(versions) > 3 else firefox_version |
| 1090 |
# version_display.txt content from the project directory if there is one, |
| 1091 |
# otherwise version.txt content from the project directory, otherwise the |
| 1092 |
# firefox version for display. |
| 1093 |
app_version_display = versions[-1] if len(versions) > 3 else firefox_version_display |
| 1094 |
|
| 1095 |
is_nightly = is_release_or_beta = None |
| 1096 |
|
| 1097 |
if "a1" in milestone: |
| 1098 |
is_nightly = True |
| 1099 |
elif "a" not in milestone: |
| 1100 |
is_release_or_beta = True |
| 1101 |
|
| 1102 |
major_version = milestone.split(".")[0] |
| 1103 |
m = re.search(r"([ab]\d+)", milestone) |
| 1104 |
ab_patch = m.group(1) if m else "" |
| 1105 |
|
| 1106 |
if not as_milestone: |
| 1107 |
defines = os.path.join(build_env.topsrcdir, "build", "defines.sh") |
| 1108 |
with open(defines, "r") as fh: |
| 1109 |
for line in fh.read().splitlines(): |
| 1110 |
line = line.strip() |
| 1111 |
if not line or line.startswith("#"): |
| 1112 |
continue |
| 1113 |
name, _, value = line.partition("=") |
| 1114 |
name = name.strip() |
| 1115 |
value = value.strip() |
| 1116 |
if name != "EARLY_BETA_OR_EARLIER": |
| 1117 |
die( |
| 1118 |
"Only the EARLY_BETA_OR_EARLIER variable can be set in build/defines.sh" |
| 1119 |
) |
| 1120 |
if value and any(x in app_version_display for x in "ab"): |
| 1121 |
is_early_beta_or_earlier = True |
| 1122 |
|
| 1123 |
# Only expose the major version milestone in the UA string and hide the |
| 1124 |
# patch leve (bugs 572659 and 870868). |
| 1125 |
# |
| 1126 |
# Only expose major milestone and alpha version in the symbolversion |
| 1127 |
# string; as the name suggests, we use it for symbol versioning on Linux. |
| 1128 |
return namespace( |
| 1129 |
version=milestone, |
| 1130 |
uaversion="%s.0" % major_version, |
| 1131 |
symbolversion="%s%s" % (major_version, ab_patch), |
| 1132 |
is_nightly=is_nightly, |
| 1133 |
is_release_or_beta=is_release_or_beta, |
| 1134 |
is_early_beta_or_earlier=is_early_beta_or_earlier, |
| 1135 |
is_esr=app_version_display.endswith("esr") or None, |
| 1136 |
app_version=app_version, |
| 1137 |
app_version_display=app_version_display, |
| 1138 |
) |
| 1139 |
|
| 1140 |
|
| 1141 |
# For extensions and langpacks, we require a max version that is compatible |
| 1142 |
# across security releases. MOZ_APP_MAXVERSION is our method for doing that. |
| 1143 |
# 24.0a1 and 24.0a2 aren't affected |
| 1144 |
# 24.0 becomes 24.* |
| 1145 |
# 24.1.1 becomes 24.* |
| 1146 |
@depends(milestone.app_version, build_project) |
| 1147 |
def moz_app_maxversion(app_version, build_project): |
| 1148 |
if "a" not in app_version: |
| 1149 |
version = Version(app_version) |
| 1150 |
if build_project == "suite": |
| 1151 |
return f"{version.major}.{version.minor}.*" |
| 1152 |
else: |
| 1153 |
return f"{version.major}.*" |
| 1154 |
else: |
| 1155 |
return app_version |
| 1156 |
|
| 1157 |
|
| 1158 |
set_config("GRE_MILESTONE", milestone.version) |
| 1159 |
set_config("NIGHTLY_BUILD", milestone.is_nightly) |
| 1160 |
set_define("NIGHTLY_BUILD", milestone.is_nightly) |
| 1161 |
set_config("RELEASE_OR_BETA", milestone.is_release_or_beta) |
| 1162 |
set_define("RELEASE_OR_BETA", milestone.is_release_or_beta) |
| 1163 |
set_config("MOZ_ESR", milestone.is_esr) |
| 1164 |
set_define("MOZ_ESR", milestone.is_esr) |
| 1165 |
set_config("EARLY_BETA_OR_EARLIER", milestone.is_early_beta_or_earlier) |
| 1166 |
set_define("EARLY_BETA_OR_EARLIER", milestone.is_early_beta_or_earlier) |
| 1167 |
set_define("MOZILLA_VERSION", depends(milestone)(lambda m: '"%s"' % m.version)) |
| 1168 |
set_config("MOZILLA_VERSION", milestone.version) |
| 1169 |
set_define("MOZILLA_UAVERSION", depends(milestone)(lambda m: '"%s"' % m.uaversion)) |
| 1170 |
|
| 1171 |
set_config("MOZ_APP_VERSION", milestone.app_version) |
| 1172 |
set_config("MOZ_APP_VERSION_DISPLAY", milestone.app_version_display) |
| 1173 |
set_config("MOZ_APP_MAXVERSION", moz_app_maxversion) |
| 1174 |
|
| 1175 |
|
| 1176 |
# The app update channel is 'default' when not supplied. The value is used in |
| 1177 |
# the application's confvars.sh (and is made available to a project specific |
| 1178 |
# moz.configure). |
| 1179 |
option( |
| 1180 |
"--enable-update-channel", |
| 1181 |
nargs=1, |
| 1182 |
help="Select application update channel", |
| 1183 |
default="default", |
| 1184 |
) |
| 1185 |
|
| 1186 |
|
| 1187 |
@depends("--enable-update-channel") |
| 1188 |
def update_channel(channel): |
| 1189 |
if not channel or channel[0] == "": |
| 1190 |
return "default" |
| 1191 |
return channel[0].lower() |
| 1192 |
|
| 1193 |
|
| 1194 |
set_config("MOZ_UPDATE_CHANNEL", update_channel) |
| 1195 |
set_define("MOZ_UPDATE_CHANNEL", update_channel) |
| 1196 |
|
| 1197 |
|
| 1198 |
option( |
| 1199 |
env="MOZBUILD_STATE_PATH", |
| 1200 |
nargs=1, |
| 1201 |
help="Path to a persistent state directory for the build system " |
| 1202 |
"and related tools", |
| 1203 |
) |
| 1204 |
|
| 1205 |
|
| 1206 |
@depends("MOZBUILD_STATE_PATH", "--help") |
| 1207 |
@imports("os") |
| 1208 |
def mozbuild_state_path(path, _): |
| 1209 |
if path: |
| 1210 |
return normalize_path(path[0]) |
| 1211 |
return normalize_path(os.path.expanduser(os.path.join("~", ".mozbuild"))) |
| 1212 |
|
| 1213 |
|
| 1214 |
@depends("MOZILLABUILD", shell, host_is_windows) |
| 1215 |
@imports(_from="pathlib", _import="Path") |
| 1216 |
def mozillabuild_bin_paths(mozillabuild, shell, host_is_windows): |
| 1217 |
paths = [] |
| 1218 |
if not mozillabuild or not host_is_windows: |
| 1219 |
return paths |
| 1220 |
paths.append(os.path.dirname(shell)) |
| 1221 |
paths.append(str(Path(mozillabuild[0]) / "bin")) |
| 1222 |
return paths |
| 1223 |
|
| 1224 |
|
| 1225 |
@depends(mozillabuild_bin_paths) |
| 1226 |
@imports("os") |
| 1227 |
def prefer_mozillabuild_path(mozillabuild_bin_paths): |
| 1228 |
return mozillabuild_bin_paths + os.environ["PATH"].split(os.pathsep) |
| 1229 |
|
| 1230 |
|
| 1231 |
# milestone.is_nightly corresponds to cases NIGHTLY_BUILD is set. |
| 1232 |
|
| 1233 |
|
| 1234 |
@depends(milestone) |
| 1235 |
def enabled_in_nightly(milestone): |
| 1236 |
return milestone.is_nightly |
| 1237 |
|
| 1238 |
|
| 1239 |
# Check if we need the 32-bit Linux SSE2 error dialog |
| 1240 |
# =================================================== |
| 1241 |
option( |
| 1242 |
env="MOZ_LINUX_32_SSE2_STARTUP_ERROR", |
| 1243 |
help="Add code to perform startup checks to warn if SSE2 is not available", |
| 1244 |
default=moz_automation, |
| 1245 |
when=target_is_unix & depends(target)(lambda target: target.cpu == "x86"), |
| 1246 |
) |
| 1247 |
set_config( |
| 1248 |
"MOZ_LINUX_32_SSE2_STARTUP_ERROR", True, when="MOZ_LINUX_32_SSE2_STARTUP_ERROR" |
| 1249 |
) |
| 1250 |
|
| 1251 |
|
| 1252 |
# Branding |
| 1253 |
# ============================================================== |
| 1254 |
option( |
| 1255 |
"--with-app-basename", |
| 1256 |
env="MOZ_APP_BASENAME", |
| 1257 |
nargs=1, |
| 1258 |
help="Typically stays consistent for multiple branded versions of a " |
| 1259 |
'given application (e.g. Aurora and Firefox both use "Firefox"), but ' |
| 1260 |
"may vary for full rebrandings (e.g. Iceweasel). Used for " |
| 1261 |
'application.ini\'s "Name" field, which controls profile location in ' |
| 1262 |
'the absence of a "Profile" field (see below), and various system ' |
| 1263 |
"integration hooks (Unix remoting, Windows MessageWindow name, etc", |
| 1264 |
) |
| 1265 |
|
| 1266 |
|
| 1267 |
@depends("--with-app-basename", target_is_android) |
| 1268 |
def moz_app_basename(value, target_is_android): |
| 1269 |
if value: |
| 1270 |
return value[0] |
| 1271 |
if target_is_android: |
| 1272 |
return "Fennec" |
| 1273 |
return "Firefox" |
| 1274 |
|
| 1275 |
|
| 1276 |
set_config( |
| 1277 |
"MOZ_APP_BASENAME", |
| 1278 |
moz_app_basename, |
| 1279 |
when=depends(build_project)(lambda p: p != "js"), |
| 1280 |
) |
| 1281 |
|
| 1282 |
|
| 1283 |
@depends("MOZILLABUILD", when=host_is_windows) |
| 1284 |
@checking("for MozillaBuild directory") |
| 1285 |
@imports("os") |
| 1286 |
def mozillabuild_dir(mozillabuild): |
| 1287 |
if mozillabuild and os.path.exists(mozillabuild[0]): |
| 1288 |
return mozillabuild[0] |
| 1289 |
|
| 1290 |
|
| 1291 |
@depends_if(mozillabuild_dir) |
| 1292 |
@checking("for MozillaBuild version") |
| 1293 |
@imports(_from="__builtin__", _import="Exception") |
| 1294 |
@imports(_from="__builtin__", _import="open") |
| 1295 |
def mozillabuild_version(mozillabuild_dir): |
| 1296 |
try: |
| 1297 |
with open(os.path.join(mozillabuild_dir, "VERSION"), "r") as fh: |
| 1298 |
return Version(fh.readline().strip()) |
| 1299 |
except Exception as e: |
| 1300 |
die(e) |
| 1301 |
|
| 1302 |
|
| 1303 |
@depends_if(mozillabuild_version) |
| 1304 |
def valid_mozillabuild_version(mozillabuild_version): |
| 1305 |
if mozillabuild_version < Version("4.0"): |
| 1306 |
die( |
| 1307 |
f"Please upgrade MozillaBuild. You can find a recent version at: https://wiki.mozilla.org/MozillaBuild" |
| 1308 |
) |
| 1309 |
|
| 1310 |
|
| 1311 |
# old-school options for controlling install step |
| 1312 |
# ============================================================== |
| 1313 |
option( |
| 1314 |
"--prefix", |
| 1315 |
nargs=1, |
| 1316 |
metavar="PREFIX", |
| 1317 |
default="/usr/local", |
| 1318 |
help="Install files using PREFIX as root directory", |
| 1319 |
) |
| 1320 |
set_config("prefix", depends("--prefix")(lambda prefix: prefix[0])) |
| 1321 |
|
| 1322 |
# Unlike autoconf, we don't offer these as a customisation point. |
| 1323 |
set_config("exec_prefix", depends("--prefix")(lambda prefix: prefix[0])) |
| 1324 |
set_config("datadir", depends("--prefix")(lambda prefix: f"{prefix[0]}/share")) |
| 1325 |
set_config("bindir", depends("--prefix")(lambda prefix: f"{prefix[0]}/bin")) |
| 1326 |
set_config("sbindir", depends("--prefix")(lambda prefix: f"{prefix[0]}/sbin")) |
| 1327 |
set_config("infodir", depends("--prefix")(lambda prefix: f"{prefix[0]}/info")) |
| 1328 |
set_config("libexec", depends("--prefix")(lambda prefix: f"{prefix[0]}/libexec")) |
| 1329 |
set_config("localstatedir", depends("--prefix")(lambda prefix: f"{prefix[0]}/var")) |
| 1330 |
set_config("sharedstatedir", depends("--prefix")(lambda prefix: f"{prefix[0]}/com")) |
| 1331 |
set_config("sysconfdir", depends("--prefix")(lambda prefix: f"{prefix[0]}/etc")) |
| 1332 |
set_config("mandir", depends("--prefix")(lambda prefix: f"{prefix[0]}/man")) |
| 1333 |
set_config("oldincludedir", depends("--prefix")(lambda prefix: f"{prefix[0]}/include")) |
| 1334 |
set_config("top_srcdir", build_environment.topsrcdir) |
| 1335 |
set_config("program_transform_name", "s,x,x,") |
| 1336 |
|
| 1337 |
option( |
| 1338 |
"--includedir", |
| 1339 |
nargs=1, |
| 1340 |
metavar="DIR", |
| 1341 |
default=depends("--prefix")(lambda prefix: f"{prefix[0]}/include"), |
| 1342 |
help="C header files in DIR", |
| 1343 |
) |
| 1344 |
set_config("includedir", depends("--includedir")(lambda idir: idir[0])) |
| 1345 |
|
| 1346 |
option( |
| 1347 |
"--libdir", |
| 1348 |
nargs=1, |
| 1349 |
metavar="DIR", |
| 1350 |
default=depends("--prefix")(lambda prefix: f"{prefix[0]}/lib"), |
| 1351 |
help="Object code libraries in DIR", |
| 1352 |
) |
| 1353 |
set_config("libdir", depends("--libdir")(lambda ldir: ldir[0])) |