forked from nicholaslu/ros2-android-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
108 lines (80 loc) · 3.89 KB
/
run.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
import argparse
from importlib.resources import path
import sys
import os
import pathlib
import urllib.request
import shutil
import subprocess
import glob
# --srcDir
# package src directory in addition to rcljava related packages.
# one of the srcDir or repoDir is required
# --repoFilePath
# repo file path in addition to rcljava's repo file.
# --soOutDir
# --jarOutDir
# --clean
def getArgs():
parser = argparse.ArgumentParser()
parser.add_argument("soOutDir", help="output directory path of .so files", type=str)
parser.add_argument("jarOutDir", help="output directory path of .jar files", type=str)
parser.add_argument("--clean", help="clean build", action='store_true')
additionalPackagesGroup = parser.add_mutually_exclusive_group()
additionalPackagesGroup.add_argument("--srcDir", help="package src directory which contains packages in addition to rcljava related packages. rcljava related packages are automatically built.", type=str)
additionalPackagesGroup.add_argument("--repoFile", help="repo file path which contains packages in addition to rcljava's repo file. rcljava related packages are automatically built.", type=str)
args = parser.parse_args()
return(args)
def setupRos2Java(workspacePath: pathlib.Path):
repoFilePath = pathlib.Path(workspacePath, "ros2_java_android.repos")
srcDirPath = pathlib.Path(workspacePath, "src")
shutil.copyfile("./ros2_java_android.repos", repoFilePath)
if not os.path.exists(srcDirPath):
os.makedirs(srcDirPath)
print('start cloning ros2java related packages')
command = f'docker run -it --rm --net=host -v {workspacePath}:/home/user/workspace ros2java-android-build vcs import --input /home/user/workspace/ros2_java_android.repos /home/user/workspace/src'
subprocess.run(command, shell=True)
def build(workspacePath: pathlib.Path):
print('start building packages')
command = f'docker run -it --rm --net=host -v {workspacePath}:/home/user/workspace ros2java-android-build /home/user/build-android.sh'
subprocess.run(command, shell=True)
def output(workspacePath: pathlib.Path, soOutPath: pathlib.Path, jarOutPath: pathlib.Path):
soFiles = [f for f in glob.glob(str(workspacePath) + "/install/**/*.so", recursive=True)]
jarFiles = [f for f in glob.glob(str(workspacePath) + "/install/**/*.jar", recursive=True)]
for file in soFiles:
filepath = pathlib.Path(file)
distFilePath = soOutPath.joinpath(filepath.name)
shutil.copyfile(file, distFilePath)
for file in jarFiles:
filepath = pathlib.Path(file)
distFilePath = jarOutPath.joinpath(filepath.name)
shutil.copyfile(file, distFilePath)
# copy stdlib
filepath = workspacePath.joinpath("libc++_shared.so")
distFilePath = soOutPath.joinpath(filepath.name)
shutil.copyfile(filepath, distFilePath)
def main():
args = getArgs()
workspacePath = pathlib.Path(pathlib.Path(__file__).resolve().parent, "tmp")
workspaceAdditionalSrcDirPath = pathlib.Path(workspacePath, "additional-src")
soOutPath = pathlib.Path(args.soOutDir).resolve()
jarOutPath = pathlib.Path(args.jarOutDir).resolve()
if workspaceAdditionalSrcDirPath.exists():
shutil.rmtree(workspaceAdditionalSrcDirPath)
if args.clean:
if os.path.exists(workspacePath):
shutil.rmtree(workspacePath)
os.makedirs(workspacePath, exist_ok=True)
os.makedirs(soOutPath, exist_ok=True)
os.makedirs(jarOutPath, exist_ok=True)
setupRos2Java(workspacePath)
if args.srcDir is not None:
additionalSrcDirPath = pathlib.Path(args.srcDir).resolve()
shutil.copytree(additionalSrcDirPath, workspaceAdditionalSrcDirPath)
if args.repoFile is not None:
# TODO: need to implement
raise NotImplementedError()
build(workspacePath)
output(workspacePath, soOutPath, jarOutPath)
if __name__ == '__main__':
main()