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 17from pathlib import Path 18import platform 19import shutil 20from tasks.task import Task 21from utils import (AOSP_ROOT, cmake_toolchain, run) 22 23 24class ConfigureTask(Task): 25 BUILDCONFIG = { 26 "debug": "-DCMAKE_BUILD_TYPE=Debug", 27 "release": "-DCMAKE_BUILD_TYPE=Release", 28 } 29 30 def __init__(self, args, env): 31 super().__init__("Configure") 32 self.out = Path(args.out_dir) 33 self.env = env 34 if args.target: 35 self.target = args.target.lower() 36 else: 37 self.target = platform.system().lower() 38 self.build_config = self.BUILDCONFIG[args.config] 39 40 def do_run(self): 41 if self.out.exists(): 42 shutil.rmtree(self.out) 43 self.out.mkdir(exist_ok=True, parents=True) 44 cmake = shutil.which( 45 "cmake", 46 path=str( 47 AOSP_ROOT 48 / "prebuilts" 49 / "cmake" 50 / f"{platform.system().lower()}-x86" 51 / "bin" 52 ), 53 ) 54 launcher = [ 55 cmake, 56 f"-B{self.out}", 57 "-G Ninja", 58 self.build_config, 59 f"-DCMAKE_TOOLCHAIN_FILE={cmake_toolchain(self.target)}", 60 AOSP_ROOT / "tools" / "netsim", 61 ] 62 63 run(launcher, self.env, "bld") 64 return True 65