forked from minhanghuang/CyberRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
258 lines (228 loc) · 8.69 KB
/
install.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env python3
import subprocess
import os
import argparse
import time
class Install:
def __init__(self, platform, install_prefix) -> None:
"""init: get the current path, the home path, the dowload path, the install path
Args:
platform (_type_): _description_
install_prefix (_type_): _description_
"""
self._machine = platform
self._home_path = os.path.expanduser("~")
self._current_path = os.path.abspath(os.path.dirname(__file__))
self._dowload_path = os.path.join(self._current_path, "third_party")
self._install_prefix = os.path.join(self._current_path, "install")
if (install_prefix != "install"):
self._install_prefix = install_prefix
if not os.path.exists(self._install_prefix):
os.makedirs(self._install_prefix)
self.environment = self._load_environment()
def _load_environment(self):
''' In case of cross-compilation, we need to load the environment setup file
return: env
'''
env = os.environ.copy()
return env
def _cmd(self, command):
"""执行系统命令,使用指定的环境变量"""
print("[command] {}".format(command))
subprocess.run(command, shell=True, env=self.environment)
def start(self):
"""start setup and clone respositories
"""
self._clone_setup()
self._clone_nlohmann_json()
self._clone_tinyxml2()
self._clone_gfamily()
self._clone_dds()
def _clone_github_repo(self, repo_url, repo_name, *args):
"""clone github repo
Args:
repo_url (string): _description_
repo_name (string): _description_
Returns:
_type_: _description_
"""
dowload_path = os.path.join(self._dowload_path, repo_name)
if os.path.exists(dowload_path):
print("repo exists: {}".format(dowload_path))
return None
command = "git clone {} {}".format(
repo_url,
dowload_path
)
for arg in args:
command += " " + arg
print("clone: {}".format(command))
subprocess.run(command, shell=True)
def _cmd(self, command):
"""执行系统命令
Args:
command (_type_): _description_
"""
print("[command] {}".format(command))
subprocess.run(command, shell=True)
def _clone_setup(self):
"""setup env
"""
self._clone_github_repo(
"https://gh-proxy.com/https://github.com/minhanghuang/setup.git",
"setup",
"--depth=1"
)
os.chdir(os.path.join(self._dowload_path, "setup"))
self._cmd("mkdir -p build")
os.chdir("build")
self._cmd(
"cmake -DCMAKE_INSTALL_PREFIX={} ..".format(self._install_prefix))
self._cmd("make install -j$(nproc)")
os.chdir(self._current_path)
def _clone_nlohmann_json(self):
"""json
"""
self._clone_github_repo(
"https://gh-proxy.com/https://github.com/nlohmann/json.git",
"nlohmann_json",
"--depth=1"
)
os.chdir(os.path.join(self._dowload_path, "nlohmann_json"))
self._cmd("mkdir -p build")
os.chdir("build")
self._cmd(
"cmake -DCMAKE_INSTALL_PREFIX={} -DBUILD_SHARED_LIBS=ON ..".format(self._install_prefix))
self._cmd("make install -j$(nproc)")
os.chdir(self._current_path)
def _clone_tinyxml2(self):
"""tinyxml2
"""
self._clone_github_repo(
"https://gh-proxy.com/https://github.com/leethomason/tinyxml2.git",
"tinyxml2",
"--single-branch",
"--branch=8.0.0",
"--depth=1"
)
os.chdir(os.path.join(self._dowload_path, "tinyxml2"))
self._cmd("mkdir -p build")
os.chdir("build")
self._cmd(
"cmake -DCMAKE_INSTALL_PREFIX={} -DBUILD_SHARED_LIBS=ON ..".format(self._install_prefix))
self._cmd("make install -j$(nproc)")
os.chdir(self._current_path)
def _clone_gfamily(self):
"""gflags and glog and googletest
"""
self._clone_github_repo(
"https://gh-proxy.com/https://github.com/gflags/gflags.git",
"gflags",
"--single-branch",
"--branch=v2.2.0",
"--depth=1"
)
self._clone_github_repo(
"https://gh-proxy.com/https://github.com/google/glog.git",
"glog",
"--single-branch",
"--branch=v0.4.0",
"--depth=1"
)
self._clone_github_repo(
"https://gh-proxy.com/https://github.com/google/googletest.git",
"googletest",
"--single-branch",
"--branch=release-1.10.0",
"--depth=1"
)
# self._clone_github_repo(
# "https://github.com/protocolbuffers/protobuf.git",
# "protobuf",
# "--single-branch",
# "--branch=v3.14.0",
# "--depth=1"
# )
os.chdir(os.path.join(self._dowload_path, "gflags"))
self._cmd("mkdir -p build")
os.chdir("build")
self._cmd(
"cmake -DCMAKE_CXX_FLAGS='-fPIC' -DCMAKE_INSTALL_PREFIX={} -DBUILD_SHARED_LIBS=ON ..".format(
self._install_prefix))
self._cmd("make install -j$(nproc)")
os.chdir(self._current_path)
os.chdir(os.path.join(self._dowload_path, "glog"))
self._cmd("mkdir -p build")
os.chdir("build")
self._cmd(
"cmake -DCMAKE_CXX_FLAGS='-fPIC' -DCMAKE_INSTALL_PREFIX={} -DBUILD_SHARED_LIBS=ON ..".format(
self._install_prefix))
self._cmd("make install -j$(nproc)")
os.chdir(self._current_path)
os.chdir(os.path.join(self._dowload_path, "googletest"))
self._cmd("mkdir -p build")
os.chdir("build")
self._cmd(
"cmake -DCMAKE_CXX_FLAGS='-fPIC -w' -DCMAKE_INSTALL_PREFIX={} -DBUILD_SHARED_LIBS=ON ..".format(
self._install_prefix))
self._cmd("make install -j$(nproc)")
os.chdir(self._current_path)
# os.chdir(os.path.join(self._dowload_path, "protobuf"))
# os.chdir("cmake")
# self._cmd("mkdir -p build")
# os.chdir("build")
# self._cmd(
# "cmake -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX={} ..".format(
# self._install_prefix))
# self._cmd("make install -j$(nproc)")
# os.chdir(self._current_path)
def _clone_dds(self):
# self._clone_github_repo(
# "https://github.com/eProsima/Fast-RTPS.git",
# "Fast-RTPS",
# "--single-branch",
# "--branch=v1.5.0",
# "--depth=1"
# )
# os.chdir(os.path.join(self._dowload_path, "Fast-RTPS"))
# self._cmd("git submodule update --init")
# self._cmd("patch -p1 < {}".format(os.path.join(self._current_path,
# "scripts/FastRTPS_1.5.0.patch")))
# self._cmd("mkdir -p build")
# self._cmd(
# "cmake -DEPROSIMA_BUILD=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX={} ..".format(
# self._install_prefix))
# os.chdir(self._current_path)
# 根据平台下载对应版本的dds
dds_name = "fast-rtps-1.5.0-1.prebuilt.x86_64.tar.gz"
if "x86_64" == self._machine:
pass
else:
dds_name = "fast-rtps-1.5.0-1.prebuilt.aarch64.tar.gz"
if not os.path.exists(os.path.join(self._dowload_path, dds_name)):
self._cmd(
"wget -t 10 {} -P {}".format(
"https://apollo-system.cdn.bcebos.com/archive/6.0/{}".format(dds_name),
self._dowload_path),
)
os.chdir(self._dowload_path)
self._cmd("tar -zxvf {}".format(dds_name))
self._cmd("cp -r fast-rtps-1.5.0-1/* {}".format(self._install_prefix))
self._cmd("rm -rf fast-rtps-1.5.0-1/")
os.chdir(self._current_path)
def parse_config():
"""parse config
Returns:
_type_: _description_
"""
parser = argparse.ArgumentParser(description="install")
parser.add_argument("--platform", type=str, default="x86_64", help="platform")
parser.add_argument("--install_prefix", type=str, default="install", help="install prefix")
args = parser.parse_args()
return args
if __name__ == "__main__":
args = parse_config()
print(f"args.platform: {args.platform}, args.install_prefix: {args.install_prefix}")
time.sleep(3)
install = Install(args.platform, args.install_prefix)
install.start()