tor-browser

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

build_config.py (3146B)


      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 
      6 import os
      7 from functools import cache
      8 
      9 import yaml
     10 
     11 from android_taskgraph import ANDROID_COMPONENTS_DIR, FENIX_DIR, FOCUS_DIR
     12 
     13 EXTENSIONS = {
     14    "aar": (".aar", ".pom", "-sources.jar"),
     15    "jar": (".jar", ".pom", "-sources.jar"),
     16 }
     17 CHECKSUMS_EXTENSIONS = (".md5", ".sha1", ".sha256", ".sha512")
     18 
     19 
     20 def get_components():
     21    build_config = _read_build_config(ANDROID_COMPONENTS_DIR)
     22    return [
     23        {"name": name, "path": project["path"], "shouldPublish": project["publish"]}
     24        for (name, project) in build_config["projects"].items()
     25    ]
     26 
     27 
     28 def get_path(component):
     29    return _read_build_config(ANDROID_COMPONENTS_DIR)["projects"][
     30        f"components:{component}"
     31    ]["path"]
     32 
     33 
     34 def get_extensions(component):
     35    artifact_type = _read_build_config(ANDROID_COMPONENTS_DIR)["projects"][
     36        f"components:{component}"
     37    ].get("artifact-type", "aar")
     38    if artifact_type not in EXTENSIONS:
     39        raise ValueError(
     40            f"For '{component}', 'artifact-type' must be one of {repr(EXTENSIONS.keys())}"
     41        )
     42 
     43    return [
     44        extension + checksum_extension
     45        for extension in EXTENSIONS[artifact_type]
     46        for checksum_extension in ("",) + CHECKSUMS_EXTENSIONS
     47    ]
     48 
     49 
     50 @cache
     51 def _read_build_config(root_dir):
     52    with open(os.path.join(root_dir, ".buildconfig.yml"), "rb") as f:
     53        return yaml.safe_load(f)
     54 
     55 
     56 def get_apk_based_projects():
     57    return [
     58        {
     59            "name": "focus",
     60            "path": FOCUS_DIR,
     61        },
     62        {
     63            "name": "fenix",
     64            "path": FENIX_DIR,
     65        },
     66    ]
     67 
     68 
     69 def get_variant(build_type, build_name):
     70    all_variants = _get_all_variants()
     71    matching_variants = [
     72        variant
     73        for variant in all_variants
     74        if variant["build_type"] == build_type and variant["name"] == build_name
     75    ]
     76    number_of_matching_variants = len(matching_variants)
     77    if number_of_matching_variants == 0:
     78        raise ValueError(f'No variant found for build type "{build_type}"')
     79    elif number_of_matching_variants > 1:
     80        raise ValueError(
     81            f'Too many variants found for build type "{build_type}"": {matching_variants}'
     82        )
     83 
     84    return matching_variants.pop()
     85 
     86 
     87 def _get_all_variants():
     88    all_variants_including_duplicates = (
     89        _read_build_config(FOCUS_DIR)["variants"]
     90        + _read_build_config(FENIX_DIR)["variants"]
     91    )
     92    all_unique_variants = []
     93    for variant in all_variants_including_duplicates:
     94        if (
     95            # androidTest is a special case that can't be prefixed with fenix or focus.
     96            # Hence, this variant exist in both build_config and we need to expose it
     97            # once only.
     98            (
     99                variant["build_type"] != "androidTest"
    100                and variant["name"] != "androidTest"
    101            )
    102            or variant not in all_unique_variants
    103        ):
    104            all_unique_variants.append(variant)
    105 
    106    return all_unique_variants