Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / python / mozbuild / mozbuild / bootstrap.py
bloba21ad75ee4cfe329c7489356f271a27ad0a4a99b
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 file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
5 import functools
6 import io
7 import logging
8 import os
9 from pathlib import Path
11 from mozbuild.configure import ConfigureSandbox
14 def _raw_sandbox(extra_args=[]):
15 # Here, we don't want an existing mozconfig to interfere with what we
16 # do, neither do we want the default for --enable-bootstrap (which is not
17 # always on) to prevent this from doing something.
18 out = io.StringIO()
19 logger = logging.getLogger("moz.configure")
20 handler = logging.StreamHandler(out)
21 logger.addHandler(handler)
22 logger.propagate = False
23 sandbox = ConfigureSandbox(
24 {},
25 argv=["configure"]
26 + ["--enable-bootstrap", f"MOZCONFIG={os.devnull}"]
27 + extra_args,
28 logger=logger,
30 return sandbox
33 @functools.lru_cache(maxsize=None)
34 def _bootstrap_sandbox():
35 sandbox = _raw_sandbox()
36 moz_configure = (
37 Path(__file__).parent.parent.parent.parent / "build" / "moz.configure"
39 sandbox.include_file(str(moz_configure / "init.configure"))
40 sandbox.include_file(str(moz_configure / "bootstrap.configure"))
41 return sandbox
44 def bootstrap_toolchain(toolchain_job):
45 # Expand the `bootstrap_path` template for the given toolchain_job, and execute the
46 # expanded function via `_value_for`, which will trigger autobootstrap.
47 # Returns the path to the toolchain.
48 sandbox = _bootstrap_sandbox()
49 return sandbox._value_for(sandbox["bootstrap_path"](toolchain_job))
52 def bootstrap_all_toolchains_for(configure_args=[]):
53 sandbox = _raw_sandbox(configure_args)
54 moz_configure = Path(__file__).parent.parent.parent.parent / "moz.configure"
55 sandbox.include_file(str(moz_configure))
56 for depend in sandbox._depends.values():
57 if depend.name == "bootstrap_path":
58 depend.result()