1#!/usr/bin/env python3 2# 3# Copyright 2023 - 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. 16from __future__ import absolute_import, division, print_function 17 18import argparse 19import logging 20import os 21from pathlib import Path 22 23from environment import get_default_environment 24from server_config import ServerConfig 25from tasks import ( 26 TASK_LIST, 27 get_tasks, 28 log_enabled_tasks, 29) 30from utils import ( 31 AOSP_ROOT, 32 config_logging, 33 create_emulator_artifact_path, 34 default_target, 35 fetch_build_chaining_artifacts, 36 is_presubmit, 37 log_system_info, 38) 39 40 41def main(): 42 config_logging() 43 log_system_info() 44 create_emulator_artifact_path() 45 46 parser = argparse.ArgumentParser( 47 description=( 48 "Configures the android netsim cmake project so it can be build" 49 ) 50 ) 51 parser.add_argument( 52 "--out_dir", 53 type=str, 54 default="tools/netsim/objs/", 55 help="The output directory", 56 ) 57 parser.add_argument( 58 "--dist_dir", type=str, default="dist/", help="The destination directory" 59 ) 60 parser.add_argument( 61 "--build-id", 62 type=str, 63 default="", 64 dest="build_id", 65 help="The netsim build number", 66 ) 67 parser.add_argument( 68 "--target", 69 type=str, 70 default=default_target(), 71 help="The build target, defaults to current os", 72 ) 73 parser.add_argument( 74 "--enable_system_rust", 75 action="store_true", 76 help="Build the netsim with the System Rust on the host machine", 77 ) 78 parser.add_argument( 79 "--with_debug", action="store_true", help="Build debug instead of release" 80 ) 81 parser.add_argument( 82 "--buildbot", action="store_true", help="Invoked by Android buildbots" 83 ) 84 parser.add_argument( 85 "--task", 86 nargs="+", 87 type=str.lower, 88 choices=[choice.lower() for choice in TASK_LIST], 89 help=( 90 "Tasks to perform (Configure, Compile, CompileInstall," 91 " InstallEmulator, RunPyTest, LocalRunAll)" 92 ), 93 ) 94 parser.add_argument( 95 "--config", 96 default="release", 97 choices=["debug", "release"], 98 help="Whether we are building a release or debug configuration.", 99 ) 100 parser.add_argument( 101 "--emulator_target", 102 type=str, 103 default="emulator-linux_x64", 104 help=( 105 "The emulator build target to install for local case, defaults to" 106 " emulator-linux_x64" 107 ), 108 ) 109 parser.add_argument( 110 "--local_emulator_dir", 111 type=str, 112 default="", 113 help=( 114 "For providing an emulator build artifact in a directory." 115 " This will install the emulator from local_emulator_dir instead of" 116 " fetching the artifacts" 117 ), 118 ) 119 120 args = parser.parse_args() 121 122 presubmit = is_presubmit(args.build_id) 123 124 # The environment of build 125 env = get_default_environment(AOSP_ROOT) 126 if args.buildbot: 127 cfg = ServerConfig(presubmit, args) 128 env = cfg.get_env() 129 130 # Set Environment Variables 131 os.environ["GIT_DISCOVERY_ACROSS_FILESYSTEM"] = "1" 132 if not args.buildbot: 133 # Able to config C++ file in vscode. 134 os.environ["CMAKE_EXPORT_COMPILE_COMMANDS"] = "1" 135 136 # Provide absolute path for args.out_dir 137 if not os.path.isabs(args.out_dir): 138 args.out_dir = os.path.join(AOSP_ROOT, args.out_dir) 139 140 # Build preparation work for buildbot 141 if args.buildbot: 142 # Fetch Emulator Artifacts 143 fetch_build_chaining_artifacts(args.out_dir, presubmit) 144 # Set the out_dir to "out/objs" 145 args.out_dir = Path(args.out_dir) / "objs" 146 147 # Obtain tasks 148 tasks = get_tasks(args, env) 149 150 # Log enabled tasks 151 log_enabled_tasks(tasks) 152 153 # Turn on sccache? 154 # if args.buildbot and cfg.sccache: 155 # launcher.append(f"-DOPTION_CCACHE=${cfg.sccache}") 156 157 # Configure 158 tasks.get("Configure").run() 159 160 # Build 161 tasks.get("Compile").run() 162 163 # Install 164 tasks.get("CompileInstall").run() 165 166 # Zip results.. 167 tasks.get("ZipArtifact").run() 168 169 # Install Emulator artifacts and Run PyTests 170 tasks.get("InstallEmulator").run() 171 tasks.get("RunPyTest").run() 172 173 174if __name__ == "__main__": 175 main() 176