-
Notifications
You must be signed in to change notification settings - Fork 71
/
mvn_build.py
executable file
·276 lines (235 loc) · 9.15 KB
/
mvn_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
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
#
# Lima compilation script
#
# Version 1.0
#
#
# Author: FL / AN (Hacked from S. Poirier)
from multiprocessing import Pool
from argparse import ArgumentParser
import os
import sys
import shutil
import string
import time
copied_files = []
#------------------------------------------------------------------------------
# build exception
#------------------------------------------------------------------------------
class BuildError(Exception):
pass
#------------------------------------------------------------------------------
# Project directory
#------------------------------------------------------------------------------
def set_project_dir(sub_dir):
project_dir = os.path.join(current_dir, sub_dir)
os.chdir(project_dir)
#------------------------------------------------------------------------------
# Copy library
#------------------------------------------------------------------------------
def copy_file_ext(from_path, to_path, file_ext):
if not os.path.isdir(to_path):
os.makedirs(to_path)
files = os.listdir(from_path)
for file in files:
full_name = os.path.join(from_path, file)
if os.path.isfile(full_name):
root, ext = os.path.splitext(full_name)
if ext == file_ext:
shutil.copy(full_name, to_path)
file_to_copy = file + ' copied in ' + to_path
copied_files.append(file_to_copy)
#------------------------------------------------------------------------------
# Compilation
#------------------------------------------------------------------------------
def build():
rc = os.system(maven_clean_install + maven_options)
if rc != 0:
raise BuildError
#------------------------------------------------------------------------------
# Clean
#------------------------------------------------------------------------------
def clean():
rc = os.system(maven_clean)
if rc != 0:
raise BuildError
#------------------------------------------------------------------------------
# Clean all modules
#------------------------------------------------------------------------------
def clean_all():
print 'Cleaning all\n'
set_project_dir('.');clean()
set_project_dir('third-party/Processlib');clean()
for cam in camera_list:
set_project_dir('camera/'+ cam);clean()
set_project_dir('applications/tango/LimaDetector');clean()
#------------------------------------------------------------------------------
# build the LimaDetector device
#------------------------------------------------------------------------------
def build_device(target_path):
print 'Build Device LimaDetector\n'
set_project_dir('applications/tango/LimaDetector')
print "Maven command = ", maven_clean_install + maven_platform_options + maven_options
rc = os.system(maven_clean_install + maven_platform_options + maven_options)
if rc != 0:
raise BuildError
if "linux" in sys.platform:
if target_path is not None:
dest_path = os.path.join(target_path, '')
copy_file_ext(device_src_path, dest_path, '')
if "win32" in sys.platform:
if target_path is not None:
dest_path = os.path.join(target_path, '')
copy_file_ext(device_src_path, dest_path, '.exe')
copy_file_ext(device_src_path, dest_path, '.pdb')
print '\n'
#------------------------------------------------------------------------------
# build the Lima Core
#------------------------------------------------------------------------------
def build_lima_core(target_path):
print 'Build Lima\n'
set_project_dir('.')
build()
if "linux" in sys.platform:
if target_path is not None:
dest_path = os.path.join(target_path, '')
copy_file_ext(src_path, dest_path, '.so')
if "win32" in sys.platform:
if target_path is not None:
dest_path = os.path.join(target_path, '')
copy_file_ext(src_path, dest_path, '.dll')
copy_file_ext(src_path, dest_path, '.pdb')
print '\n'
#------------------------------------------------------------------------------
# build the Plugin 'plugin'
#------------------------------------------------------------------------------
def build_plugin(plugin,target_path):
"""Build the selected plugin"""
print "Building: " , plugin, "\n"
set_project_dir(plugin)
build()
if "linux" in sys.platform:
if target_path is not None:
dest_path = os.path.join(target_path, '')
copy_file_ext(src_path, dest_path, '.so')
if "win32" in sys.platform:
if target_path is not None:
dest_path = os.path.join(target_path, '')
copy_file_ext(src_path, dest_path, '.dll')
copy_file_ext(src_path, dest_path, '.pdb')
print '\n'
#------------------------------------------------------------------------------
# build all linux cameras
#------------------------------------------------------------------------------
def build_all_camera(target_path):
start=time.time()
# this take 2 min 45 sec on a quad core
if multi_proc == False:
for cam in camera_list:
build_plugin('camera/' + cam, target_path)
else:
# this take 1 min 26 sec on a quad core
pool = Pool()
for cam in camera_list:
print "multi proc: Building: " , cam, "\n"
pool.apply_async(build_plugin,('camera/' + cam, target_path))
pool.close()
pool.join()
time.strftime("%M min %S sec", time.localtime(170))
print "duration for compiling all cameras (MultiProc = ",multi_proc, ") = ", time.strftime("%M min %S sec", time.localtime(time.time() - start))
#------------------------------------------------------------------------------
# Main Entry point
#------------------------------------------------------------------------------
if __name__ == "__main__":
if "linux" in sys.platform:
platform = "linux"
camera_list = ["adsc", "aviex", "basler", "eiger", "marccd","pilatus","prosilica","simulator","xpad"]
maven_platform_options = " --file pom-linux.xml"
src_path = './target/nar/lib/i386-Linux-g++/shared/'
device_src_path = './target/nar/bin/i386-Linux-g++/'
if "win32" in sys.platform:
platform = "win32"
camera_list = ["andor", "hamamatsu", "pco","perkinelmer","roperscientific","simulator","uview"]
maven_platform_options = " --file pom-win.xml"
src_path = './target/nar/lib/x86-Windows-msvc/shared/'
device_src_path = './target/nar/bin/x86-Windows-msvc/'
print "platform : ", platform
# command line parsing
parser = ArgumentParser(description="Lima compilation script")
cams_string = ""
for cam in camera_list:
cams_string += cam + "|"
help_string = "module to compile (possible values are: all|processlib|lima|cameras|"+ cams_string+ "|device||cleanall)"
parser.add_argument("module", help=help_string)
parser.add_argument("-o","--offline", help="mvn will be offline",action="store_true")
parser.add_argument("-f","--pomfile", help="name of the pom file(for the Tango device only)")
parser.add_argument("-q","--quiet", help="mvn will be quiet", action="store_true")
parser.add_argument("-m","--multiproc", help="cameras will be compiled in multiprocessing way",action="store_true")
parser.add_argument("-d","--directory", help="automatically install Lima binaries into the specified installation directory")
args = parser.parse_args()
maven_options = ""
# manage command line option
if args.offline:
maven_options += " -o"
if args.pomfile:
maven_platform_options = " --file " + args.pomfile
if args.quiet:
maven_options += " -q"
if args.multiproc:
multi_proc = True
else:
multi_proc = False
if args.directory:
target_path = args.directory
else:
target_path = None
# variables
maven_clean_install = "mvn clean install -DenableCheckRelease=false"
maven_clean = "mvn clean"
current_dir = os.getcwd()
try:
# Build all
if args.module == 'all':
print 'BUILD ALL\n'
build_plugin('third-party/Processlib', target_path)
build_lima_core(target_path)
build_all_camera(target_path)
build_device(target_path)
# Build processlib
elif args.module == 'processlib':
print 'BUILD ProcessLib\n'
build_plugin('third-party/Processlib', target_path)
# Build device
elif args.module == 'device':
print 'BUILD Device\n'
build_device(target_path)
# Build lima
elif args.module == 'lima':
print 'BUILD Lima Core\n'
build_lima_core(target_path)
# Build cameras
elif args.module == 'cameras':
print 'BUILD All ',platform,' Cameras\n'
build_all_camera(target_path)
# Clean all
elif args.module =='cleanall':
clean_all()
# Build cam
else:
for cam in camera_list:
if args.module == cam:
build_plugin('camera/'+cam, target_path)
break
# display list of copied files, if -d option is used
if args.directory:
print '\n'
print '============================================='
print 'Modules are compiled & copied as shown below:'
print '============================================='
for file in copied_files:
print '- ',file
print '\n'
except BuildError, e:
sys.stderr.write("!!! BUILD FAILED !!!\n")