tor-browser

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

target_tasks.py (3030B)


      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 from taskgraph.target_tasks import register_target_task, target_tasks_default
      6 
      7 
      8 def filter_build_type(build_types, task):
      9    if "o" in build_types and "opt" in task.attributes["build_type"]:
     10        return True
     11    if "d" in build_types and "debug" in task.attributes["build_type"]:
     12        return True
     13 
     14 
     15 PLATFORM_ALIASES = {
     16    "aarch64-make": "aarch64",
     17    "linux": "linux32",
     18    "linux-fuzz": "linux32",
     19    "linux64-fips": "linux64",
     20    "linux64-fuzz": "linux64",
     21    "linux64-make": "linux64",
     22    "linux-make": "linux32",
     23    "win64-make": "windows2022-64",
     24    "win-make": "windows2022-32",
     25    "win64": "windows2022-64",
     26    "win": "windows2022-32",
     27    "mac": "macosx64",
     28    "mac-make": "macosx64",
     29 }
     30 
     31 
     32 def filter_platform(platform, task):
     33    if "build_platform" not in task.attributes:
     34        return False
     35    if platform == "all":
     36        return True
     37    task_platform = task.attributes["build_platform"]
     38    # Check the platform name.
     39    keep = task_platform == PLATFORM_ALIASES.get(platform, platform)
     40    # Additional checks.
     41    if platform == "linux64-fips":
     42        keep &= task.attributes["fips"]
     43    elif (
     44        platform == "linux64-make"
     45        or platform == "linux-make"
     46        or platform == "win64-make"
     47        or platform == "win-make"
     48        or platform == "aarch64-make"
     49        or platform == "mac-make"
     50    ):
     51        keep &= task.attributes["make"]
     52    elif platform == "linux64-fuzz" or platform == "linux-fuzz":
     53        keep &= task.attributes["fuzz"]
     54    return keep
     55 
     56 
     57 def filter_try_syntax(options, task):
     58    symbol = task.task["extra"]["treeherder"]["symbol"].lower()
     59    group = task.task["extra"]["treeherder"].get("groupSymbol", "").lower()
     60 
     61    # Filter tools. We can immediately return here as those
     62    # are not affected by platform or build type selectors.
     63    if task.kind == "tools":
     64        return any(t in options["tools"] for t in ["all", symbol])
     65 
     66    # Filter unit tests.
     67    if task.kind == "test":
     68        tests = {"all", symbol}
     69        if group in ("cipher", "ssl"):
     70            tests.add(group)
     71        if not any(t in options["unittests"] for t in tests):
     72            return False
     73 
     74    # Filter extra builds.
     75    if group == "builds" and not options["extra"]:
     76        return False
     77 
     78    # Filter by platform.
     79    if not any(filter_platform(platform, task) for platform in options["platforms"]):
     80        return False
     81 
     82    # Finally, filter by build type.
     83    return filter_build_type(options["builds"], task)
     84 
     85 
     86 @register_target_task("nss_try_tasks")
     87 def target_tasks_try(full_task_graph, parameters, graph_config):
     88    if not parameters["try_options"]:
     89        return target_tasks_default(full_task_graph, parameters, graph_config)
     90    return [
     91        t.label
     92        for t in full_task_graph
     93        if filter_try_syntax(parameters["try_options"], t)
     94    ]