build_config.py (2636B)
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 from taskgraph.loader.transform import loader as base_loader 7 from taskgraph.util.templates import merge 8 9 from ..build_config import get_apk_based_projects, get_components 10 11 12 def components_loader(kind, path, config, params, loaded_tasks, write_artifacts): 13 """Loader that yields one task per android-component. 14 15 Android-components are read from android-component/.buildconfig.yml 16 """ 17 config["tasks"] = _get_components_tasks(config) 18 return base_loader(kind, path, config, params, loaded_tasks, write_artifacts) 19 20 21 def components_and_apks_loader( 22 kind, path, config, params, loaded_tasks, write_artifacts 23 ): 24 """Loader that yields one task per android-component and per apk-based project. 25 26 For instance focus-android yields one task. 27 Config is read from various .buildconfig.yml files. 28 29 Additional tasks can be provided in the kind.yml under the key `tasks`. 30 """ 31 32 components_tasks = _get_components_tasks(config, for_build_type="regular") 33 apks_tasks = _get_apks_tasks(config) 34 config["tasks"] = merge(config["tasks"], components_tasks, apks_tasks) 35 return base_loader(kind, path, config, params, loaded_tasks, write_artifacts) 36 37 38 def get_component_name(component): 39 prefix, _, name = component["name"].partition(":") 40 if prefix == "components": 41 return name 42 return component["name"] 43 44 45 def _get_components_tasks(config, for_build_type=None): 46 not_for_components = config.get("not-for-components", []) 47 tasks = { 48 "{}{}".format( 49 "" if build_type == "regular" else build_type + "-", 50 get_component_name(component), 51 ): { 52 "attributes": { 53 "build-type": build_type, 54 "component": get_component_name(component), 55 "gradle-project": component["name"], 56 } 57 } 58 for component in get_components() 59 for build_type in ("regular", "nightly", "beta", "release") 60 if ( 61 get_component_name(component) not in not_for_components 62 and (component["shouldPublish"] or build_type == "regular") 63 and (for_build_type is None or build_type == for_build_type) 64 ) 65 } 66 67 return tasks 68 69 70 def _get_apks_tasks(config): 71 not_for_apks = config.get("not-for-apks", []) 72 tasks = { 73 apk["name"]: {} 74 for apk in get_apk_based_projects() 75 if apk["name"] not in not_for_apks 76 } 77 return tasks