1#!/usr/bin/env python3 2# 3# Copyright 2024 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the', help="License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an', help="AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import logging 18import platform 19from typing import Mapping 20 21from tasks.compile_install_task import CompileInstallTask 22from tasks.compile_task import CompileTask 23from tasks.configure_task import ConfigureTask 24from tasks.install_emulator_task import InstallEmulatorTask 25from tasks.run_pytest_task import RunPyTestTask 26from tasks.run_test_task import RunTestTask 27from tasks.task import Task 28from tasks.zip_artifact_task import ZipArtifactTask 29 30TASK_LIST = [ 31 "Configure", 32 "Compile", 33 "CompileInstall", 34 "RunTest", 35 "ZipArtifact", 36 "InstallEmulator", 37 "RunPyTest", 38 "LocalRunAll", 39] 40 41 42def log_enabled_tasks(tasks): 43 enabled_tasks = [ 44 task_name for task_name, task in tasks.items() if task.enabled 45 ] 46 logging.info(f"Enabled Tasks are {enabled_tasks}") 47 48 49def get_tasks(args, env) -> Mapping[str, Task]: 50 """A list of tasks that should be executed""" 51 52 # Mapping of tasks 53 tasks = { 54 "Configure": ConfigureTask(args, env), 55 "Compile": CompileTask(args, env), 56 "CompileInstall": CompileInstallTask(args, env), 57 "RunTest": RunTestTask(args, env), 58 "ZipArtifact": ZipArtifactTask(args), 59 "InstallEmulator": InstallEmulatorTask(args), 60 "RunPyTest": RunPyTestTask(args), 61 } 62 63 # Enable all tasks for buidlbots 64 if args.buildbot: 65 for task_name in [ 66 "Configure", 67 "CompileInstall", 68 "RunTest", 69 "ZipArtifact", 70 "InstallEmulator", 71 "RunPyTest", 72 ]: 73 tasks[task_name].enable(True) 74 return tasks 75 76 if args.task: 77 # Enable user specified tasks 78 for args_task_name in args.task: 79 if args_task_name.lower() == "localrunall": 80 # We don't need installation process when running locally 81 for task_name in [ 82 "Configure", 83 "Compile", 84 "RunTest", 85 "InstallEmulator", 86 "RunPyTest", 87 ]: 88 tasks[task_name].enable(True) 89 break 90 elif args_task_name.lower() == "configure": 91 tasks["Configure"].enable(True) 92 elif args_task_name.lower() == "compile": 93 tasks["Compile"].enable(True) 94 elif args_task_name.lower() == "compileinstall": 95 tasks["CompileInstall"].enable(True) 96 elif args_task_name.lower() == "runtest": 97 tasks["RunTest"].enable(True) 98 elif args_task_name.lower() == "zipartifact": 99 tasks["ZipArtifact"].enable(True) 100 elif args_task_name.lower() == "installemulator": 101 tasks["InstallEmulator"].enable(True) 102 elif args_task_name.lower() == "fullbuild": 103 tasks["Configure"].enable(True) 104 tasks["Compile"].enable(True) 105 tasks["InstallEmulator"].enable(True) 106 elif args_task_name.lower() == "runpytest": 107 tasks["RunPyTest"].enable(True) 108 else: 109 logging.error(f"Unknown task: {args_task_name}") 110 else: 111 # If task argument isn't passed, only enable ConfigureTask 112 tasks["Configure"].enable(True) 113 return tasks 114