-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
executable file
·75 lines (55 loc) · 2.27 KB
/
build.py
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
#!/usr/bin/env python3
import argparse
import os
import platform
import shutil
import subprocess as sp
import sys
from pathlib import Path
RPI_TOOLCHAIN = "cmake/toolchains/aarch64-linux.cmake"
def get_source_dir() -> Path:
return Path(__file__).parent.resolve()
def build_ros2(args, build_suffix) -> None:
ros2_ws = get_source_dir() / "ros2"
if args.rpi:
setup_bash_file = "/sysroot/opt/ros/iron/setup.bash"
toolchain_arg = f"--cmake-args -DCMAKE_TOOLCHAIN_FILE={get_source_dir() / RPI_TOOLCHAIN}"
else:
setup_bash_file = "/opt/ros/iron/setup.bash"
toolchain_arg = ""
build_dir = f"build-{build_suffix}"
install_dir = f"install-{build_suffix}"
if args.clean:
shutil.rmtree(ros2_ws / build_dir, ignore_errors=True)
shutil.rmtree(ros2_ws / install_dir, ignore_errors=True)
sp.check_call(f"source {setup_bash_file} && colcon build --cmake-force-configure "
f"--build-base {build_dir} --install-base {install_dir} {toolchain_arg}",
cwd=ros2_ws, shell=True, executable='/bin/bash')
def build_qt(args, build_suffix) -> None:
build_dir = Path(f"build-{build_suffix}").resolve()
if args.clean:
shutil.rmtree(build_dir, ignore_errors=True)
build_dir.mkdir(exist_ok=True)
if args.rpi:
command = f"cmake {get_source_dir()} --toolchain {get_source_dir() / RPI_TOOLCHAIN}"
else:
command = f"cmake {get_source_dir()}"
sp.check_call(command, cwd=build_dir, shell=True)
sp.check_call("make", cwd=build_dir)
def main(args) -> None:
if args.rpi:
build_suffix = "aarch64-linux"
else:
build_suffix = f"{platform.processor()}-{platform.system().lower()}"
build_qt(args, build_suffix)
build_ros2(args, build_suffix)
if __name__ == "__main__":
if not os.getenv("DOCKER_ENV"):
print("You are not in docker!")
sys.exit(0)
parser = argparse.ArgumentParser(description='Build options')
parser.add_argument('--rpi', default=False, action='store_true',
help='Собрать проект под Raspberry')
parser.add_argument('--clean', default=False, action='store_true',
help='Пересборка таргетов')
main(parser.parse_args())