-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·140 lines (109 loc) · 3.1 KB
/
build.py
File metadata and controls
executable file
·140 lines (109 loc) · 3.1 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#! /usr/bin/env python3
import os
import subprocess
import argparse
import time
import atexit
import signal
import psutil
path_root = os.path.dirname(os.path.realpath(__file__))
path_buildws = path_root + '/build_ws'
path_aplink = path_buildws + '/src/adap_parameter'
path_package = path_root + '/package'
path_direct_launch = './devel/lib/adap_parameter/'
roscore = None
def signal_recursive(process, sig=signal.SIGTERM):
try:
parent = psutil.Process(process.pid)
except psutil.NoSuchProcess:
return
children = parent.children(recursive=True)
for c in children:
print("kill process: " + str(c))
c.send_signal(sig)
process.send_signal(sig)
def roscore_start():
global roscore
roscore = subprocess.Popen(
'. devel/setup.sh && roscore',
shell=True,
cwd=path_buildws,
universal_newlines=True,
stdout=subprocess.DEVNULL,
stderr=None,
start_new_session=True)
time.sleep(1)
def roscore_stop():
global roscore
if(not (roscore is None)):
signal_recursive(roscore)
roscore.wait()
roscore = None
def make_build_ws():
os.makedirs(path_buildws + '/src', exist_ok=True)
if (not os.path.islink(path_aplink)):
os.symlink(path_package, path_aplink, True)
def link_compile_cmds():
if (not os.path.islink(path_root + '/compile_commands.json')):
os.symlink(
path_buildws + '/build/compile_commands.json',
path_root + '/compile_commands.json')
def catkin_make():
make_build_ws()
subprocess.run(
'catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DSANITIZE_ADDRESS=1',
shell=True,
cwd=path_buildws)
def build():
catkin_make()
link_compile_cmds()
def launch_launchfile(name):
if (not name.endswith('.launch')):
name += '.launch'
return subprocess.Popen(
'. devel/setup.sh && roslaunch adap_parameter ' +
name,
shell=True,
cwd=path_buildws,
universal_newlines=True,
stdout=subprocess.DEVNULL,
stderr=None,
start_new_session=True)
def launch_direct(name):
return subprocess.Popen(
'. devel/setup.sh && ' +
path_direct_launch + name,
shell=True,
cwd=path_buildws,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=None,
start_new_session=True)
def waiton(proc):
try:
print('Waiting on proc... ^C to kill it an continue.')
proc.wait()
except KeyboardInterrupt:
signal_recursive(proc, signal.SIGKILL)
time.sleep(1)
finally:
print('Done waiting on proc.')
def kill_node(node):
signal_recursive(node)
node.wait()
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument(
'-r',
'--run',
dest='run',
type=str,
required=False,
help='Automatically start a .launch file')
args = argparser.parse_args()
build()
if(args.run):
waiton(launch_launchfile(args.run))
atexit.register(roscore_stop)
if __name__ == "__main__":
main()