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/.
7 from functools
import lru_cache
11 from android_taskgraph
import ANDROID_COMPONENTS_DIR
, FENIX_DIR
, FOCUS_DIR
14 "aar": (".aar", ".pom", "-sources.jar"),
15 "jar": (".jar", ".pom", "-sources.jar"),
17 CHECKSUMS_EXTENSIONS
= (".md5", ".sha1", ".sha256", ".sha512")
21 build_config
= _read_build_config(ANDROID_COMPONENTS_DIR
)
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"][
35 ].get("artifact-type", "aar")
36 if artifact_type
not in EXTENSIONS
:
38 "For '{}', 'artifact-type' must be one of {}".format(
39 component
, repr(EXTENSIONS
.keys())
44 extension
+ checksum_extension
45 for extension
in EXTENSIONS
[artifact_type
]
46 for checksum_extension
in ("",) + CHECKSUMS_EXTENSIONS
50 @lru_cache(maxsize
=None)
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():
69 def get_variant(build_type
, build_name
):
70 all_variants
= _get_all_variants()
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:
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
:
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
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