summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/bootstrap.py
blob: 60a307145cca482a40b2857419c571025bd4dd0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import functools
import io
import logging
import os
from pathlib import Path

from mozbuild.configure import ConfigureSandbox


def _raw_sandbox(extra_args=[]):
    # Here, we don't want an existing mozconfig to interfere with what we
    # do, neither do we want the default for --enable-bootstrap (which is not
    # always on) to prevent this from doing something.
    out = io.StringIO()
    logger = logging.getLogger("moz.configure")
    handler = logging.StreamHandler(out)
    logger.addHandler(handler)
    logger.propagate = False
    sandbox = ConfigureSandbox(
        {},
        argv=["configure"]
        + ["--enable-bootstrap", f"MOZCONFIG={os.devnull}"]
        + extra_args,
        logger=logger,
    )
    return sandbox


@functools.lru_cache(maxsize=None)
def _bootstrap_sandbox():
    sandbox = _raw_sandbox()
    moz_configure = (
        Path(__file__).parent.parent.parent.parent / "build" / "moz.configure"
    )
    sandbox.include_file(str(moz_configure / "init.configure"))
    # bootstrap_search_path_order has a dependency on developer_options, which
    # is not defined in init.configure. Its value doesn't matter for us, though.
    sandbox["developer_options"] = sandbox["always"]
    sandbox.include_file(str(moz_configure / "bootstrap.configure"))
    return sandbox


def bootstrap_toolchain(toolchain_job):
    # Expand the `bootstrap_path` template for the given toolchain_job, and execute the
    # expanded function via `_value_for`, which will trigger autobootstrap.
    # Returns the path to the toolchain.
    sandbox = _bootstrap_sandbox()
    return sandbox._value_for(sandbox["bootstrap_path"](toolchain_job))


def bootstrap_all_toolchains_for(configure_args=[]):
    sandbox = _raw_sandbox(configure_args)
    moz_configure = Path(__file__).parent.parent.parent.parent / "moz.configure"
    sandbox.include_file(str(moz_configure))
    for depend in sandbox._depends.values():
        if depend.name == "bootstrap_path":
            depend.result()