Bug 1889091 - Part 6: Remove "scratch" register parameter from emitPushArguments...
[gecko.git] / taskcluster / android_taskgraph / build_config.py
blob368b251e41468ded1f9ee090df915f43d357b16b
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/.
6 import os
8 import yaml
9 from taskgraph.util.memoize import memoize
11 from android_taskgraph import ANDROID_COMPONENTS_DIR, FENIX_DIR, FOCUS_DIR
13 EXTENSIONS = {
14 "aar": (".aar", ".pom", "-sources.jar"),
15 "jar": (".jar", ".pom", "-sources.jar"),
17 CHECKSUMS_EXTENSIONS = (".md5", ".sha1", ".sha256", ".sha512")
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()
28 def get_path(component):
29 return _read_build_config(ANDROID_COMPONENTS_DIR)["projects"][component]["path"]
32 def get_extensions(component):
33 artifact_type = _read_build_config(ANDROID_COMPONENTS_DIR)["projects"][
34 component
35 ].get("artifact-type", "aar")
36 if artifact_type not in EXTENSIONS:
37 raise ValueError(
38 "For '{}', 'artifact-type' must be one of {}".format(
39 component, repr(EXTENSIONS.keys())
43 return [
44 extension + checksum_extension
45 for extension in EXTENSIONS[artifact_type]
46 for checksum_extension in ("",) + CHECKSUMS_EXTENSIONS
50 @memoize
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)
56 def get_apk_based_projects():
57 return [
59 "name": "focus",
60 "path": FOCUS_DIR,
63 "name": "fenix",
64 "path": FENIX_DIR,
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
76 number_of_matching_variants = len(matching_variants)
77 if number_of_matching_variants == 0:
78 raise ValueError('No variant found for build type "{}"'.format(build_type))
79 elif number_of_matching_variants > 1:
80 raise ValueError(
81 'Too many variants found for build type "{}"": {}'.format(
82 build_type, matching_variants
86 return matching_variants.pop()
89 def _get_all_variants():
90 all_variants_including_duplicates = (
91 _read_build_config(FOCUS_DIR)["variants"]
92 + _read_build_config(FENIX_DIR)["variants"]
94 all_unique_variants = []
95 for variant in all_variants_including_duplicates:
96 if (
97 # androidTest is a special case that can't be prefixed with fenix or focus.
98 # Hence, this variant exist in both build_config and we need to expose it
99 # once only.
101 variant["build_type"] != "androidTest"
102 and variant["name"] != "androidTest"
104 or variant not in all_unique_variants
106 all_unique_variants.append(variant)
108 return all_unique_variants