-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·77 lines (53 loc) · 2.23 KB
/
Copy pathbuild.py
File metadata and controls
executable file
·77 lines (53 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
"""Build C++ modules via CMake.
Ensures a consistent build tree at ``build/<CONNEXTDDS_ARCH>/`` and
forwards any extra arguments to ``cmake --build``.
Usage:
python3 build.py # configure + build all
python3 build.py --target ArmController # build a specific target
python3 build.py --target module-01 # build all Module 01 targets
"""
from __future__ import annotations
import platform
import subprocess
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent / "resource" / "python"))
from scripts import platform_setup
PROJECT_ROOT = Path(__file__).resolve().parent
BUILD_DIR = PROJECT_ROOT / "build" / platform_setup.get_connextdds_arch()
def _windows_cmake_platform() -> str | None:
"""Map a Connext architecture string to a CMake Visual Studio platform.
Connext Windows arch names commonly begin with ``x64`` or ``i86``.
``x64`` maps to the Visual Studio ``x64`` platform, while the 32-bit
variants map to ``Win32``.
"""
if platform.system() != "Windows":
return None
arch = platform_setup.get_connextdds_arch().lower()
if arch.startswith("x64"):
return "x64"
if arch.startswith(("i86", "x86")):
return "Win32"
return None
def configure_command(args: list[str] | None = None) -> list[str]:
args = args or []
command = ["cmake", "-S", str(PROJECT_ROOT), "-B", str(BUILD_DIR)] + args
platform_arg = _windows_cmake_platform()
if platform_arg and not any(argument in ("-A", "--platform") for argument in args):
command.extend(["-A", platform_arg])
return command
def build_command(args: list[str] | None = None) -> list[str]:
args = args or []
command = ["cmake", "--build", str(BUILD_DIR)] + args
if platform.system() == "Windows" and "--config" not in command:
command.extend(["--config", "Release"])
return command
def main() -> None:
BUILD_DIR.mkdir(parents=True, exist_ok=True)
args = sys.argv[1:]
idx = args.index("--") if "--" in args else len(args)
subprocess.run(configure_command(args=args[:idx]), check=True)
subprocess.run(build_command(args=args[idx + 1 :]), check=True)
if __name__ == "__main__":
main()