• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
16from __future__ import absolute_import, division, print_function
17
18import argparse
19import os
20from pathlib import Path
21import platform
22import shutil
23
24from environment import get_default_environment
25from utils import (
26    AOSP_ROOT,
27    cmake_toolchain,
28    config_logging,
29    log_system_info,
30    run,
31)
32
33
34def main():
35  config_logging()
36  log_system_info()
37
38  parser = argparse.ArgumentParser(
39      description=(
40          "Configures the android netsim cmake project so it can be build"
41      )
42  )
43  parser.add_argument(
44      "--out_dir",
45      type=str,
46      default=Path("objs").absolute(),
47      help="The output directory",
48  )
49
50  parser.add_argument(
51      "--target",
52      type=str,
53      default=platform.system(),
54      help="The build target, defaults to current os",
55  )
56  parser.add_argument(
57      "--enable_system_rust",
58      action="store_true",
59      help="Build the netsim with the System Rust on the host machine",
60  )
61  parser.add_argument(
62      "--with_debug", action="store_true", help="Build debug instead of release"
63  )
64
65  args = parser.parse_args()
66
67  os.environ["GIT_DISCOVERY_ACROSS_FILESYSTEM"] = "1"
68  os.environ["CMAKE_EXPORT_COMPILE_COMMANDS"] = "1"
69
70  target = platform.system().lower()
71
72  if args.target:
73    target = args.target.lower()
74
75  if not os.path.isabs(args.out_dir):
76    args.out_dir = os.path.join(AOSP_ROOT, args.out_dir)
77
78  out = Path(args.out_dir)
79  if out.exists():
80    shutil.rmtree(out)
81  out.mkdir(exist_ok=True, parents=True)
82
83  cmake = shutil.which(
84      "cmake",
85      path=str(
86          AOSP_ROOT
87          / "prebuilts"
88          / "cmake"
89          / f"{platform.system().lower()}-x86"
90          / "bin"
91      ),
92  )
93  launcher = [
94      cmake,
95      f"-B{out}",
96      "-G Ninja",
97      f"-DCMAKE_TOOLCHAIN_FILE={cmake_toolchain(target)}",
98      AOSP_ROOT / "tools" / "netsim",
99  ]
100
101  # Configure
102  run(launcher, get_default_environment(AOSP_ROOT), "bld")
103
104
105if __name__ == "__main__":
106  main()
107