tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mach.py (2377B)


      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/.
      4 """
      5 Support for running mach tasks (via run-task)
      6 """
      7 
      8 from taskgraph.util.schema import Schema, taskref_or_string
      9 from voluptuous import Any, Optional, Required
     10 
     11 from gecko_taskgraph.transforms.job import configure_taskdesc_for_run, run_job_using
     12 
     13 mach_schema = Schema({
     14    Required("using"): "mach",
     15    # The mach command (omitting `./mach`) to run
     16    Required("mach"): taskref_or_string,
     17    # The sparse checkout profile to use. Value is the filename relative to the
     18    # directory where sparse profiles are defined (build/sparse-profiles/).
     19    Optional("sparse-profile"): Any(str, None),
     20    # if true, perform a checkout of a comm-central based branch inside the
     21    # gecko checkout
     22    Required("comm-checkout"): bool,
     23    # Prepend the specified ENV variables to the command. This can be useful
     24    # if the value of the ENV needs to be interpolated with another ENV.
     25    Optional("prepend-env"): {str: str},
     26    # Base work directory used to set up the task.
     27    Optional("workdir"): str,
     28    # Use the specified caches.
     29    Optional("use-caches"): Any(bool, [str]),
     30 })
     31 
     32 
     33 defaults = {
     34    "comm-checkout": False,
     35 }
     36 
     37 
     38 @run_job_using("docker-worker", "mach", schema=mach_schema, defaults=defaults)
     39 @run_job_using("generic-worker", "mach", schema=mach_schema, defaults=defaults)
     40 def configure_mach(config, job, taskdesc):
     41    run = job["run"]
     42    worker = job["worker"]
     43 
     44    additional_prefix = []
     45    if worker["os"] == "macosx":
     46        additional_prefix = ["LC_ALL=en_US.UTF-8", "LANG=en_US.UTF-8"]
     47 
     48    if prepend_env := run.pop("prepend-env", None):
     49        for name, value in prepend_env.items():
     50            additional_prefix.append(f"{name}={value}")
     51 
     52    command_prefix = " ".join(additional_prefix + ["./mach "])
     53 
     54    mach = run["mach"]
     55    if isinstance(mach, dict):
     56        ref, pattern = next(iter(mach.items()))
     57        command = {ref: command_prefix + pattern}
     58    else:
     59        command = command_prefix + mach
     60 
     61    # defer to the run_task implementation
     62    run["command"] = command
     63    run["cwd"] = "{checkout}"
     64    run["using"] = "run-task"
     65    del run["mach"]
     66    configure_taskdesc_for_run(config, job, taskdesc, job["worker"]["implementation"])