forked from Parrot-Developers/ARSDKBuildUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDK3Build.py
executable file
·354 lines (311 loc) · 11.6 KB
/
SDK3Build.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env python
'''
Copyright (C) 2014 Parrot SA
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Parrot nor the names
of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
'''
# PYTHON_ARGCOMPLETE_OK
#Generic imports
import os
import sys
import subprocess
import shutil
try:
import argcomplete
hasArgComplete = True
except ImportError:
hasArgComplete = False
MYDIR=os.path.abspath(os.path.dirname(sys.argv[0]))
if '' == MYDIR:
MYDIR=os.getcwd()
sys.path.append('%(MYDIR)s/Utils/Python' % locals())
#Custom imports
from xml.dom.minidom import parseString
from ARFuncs import *
from time import localtime, strftime
from Common_GitUtils import *
import commandLine
import xmlreader
import time
start = time.time()
DEBUG_MODE = False
#
# Init the log file
#
ARInitLogFile()
#
# Get extra xml dirs
#
xmlDirs = [ MYDIR ]
try:
extraXmlDirs = os.environ['ARSDK_EXTRA_XML_DIRS'].split(':')
xmlDirs.extend(extraXmlDirs)
xmlDirs.remove('')
except:
pass
#
# Parse XML
#
(repos, targets, prebuilts, libraries, binaries) = xmlreader.parseAll(xmlDirs)
if DEBUG_MODE:
ARPrint ('Debug mode enabled : dump XML contents')
repos.dump()
targets.dump()
prebuilts.dump()
libraries.dump()
binaries.dump()
EXIT(0)
#
# Parse command line args
#
parser = commandLine.CommandLineParser(targets, libraries, binaries)
if hasArgComplete:
argcomplete.autocomplete(parser.parser)
parser.parse(sys.argv)
#
# Dump command line args into log file
#
parser.dump()
#
# Export useful tools if available
# (e.g. colormake)
#
ARMakeArgs = '-j ' + str(parser.threads)
ARSetEnvIfExists('ARMAKE', 'colormake', 'make', args=ARMakeArgs)
# Import targets functions for library/binary/doc
# This block will try to import the functions for all targets declared in targets.xml file
# Adding a new target requires the following modifications :
# 1> Add the target in targets.xml filr
# 2> Adapt libraries.xml / binaries.xml to support this target
# 3> Create the Target_BuildLibrary.py script in Utils/Python dir
# -> This file must contain a Target_BuildLibrary(target, lib, clean=False, debug=False) function
# 4> (Optionnal) Create the Target_BuildBinary.py script in Utils/Python dir
# -> This file must contain a Target_BuildBinary(target, bin, clean=False, debug=False) function
# 5> (Optionnal) Create the Target_GenLibraryDoc.py script in Utils/Python dir
# -> This file must contain a Target_GenLibraryDoc(target, lib, clean=False) function
BUILD_LIB_FUNCS = {}
BUILD_BIN_FUNCS = {}
GEN_DOC_FUNCS = {}
for t in targets.list:
try:
_name = t.name + '_BuildLibrary'
_module = __import__ (_name)
BUILD_LIB_FUNCS[t.name] = getattr (_module, _name)
except ImportError:
pass
try:
_name = t.name + '_BuildBinary'
_module = __import__ (_name)
BUILD_BIN_FUNCS[t.name] = getattr (_module, _name)
except ImportError:
pass
try:
_name = t.name + '_GenLibraryDoc'
_module = __import__ (_name)
GEN_DOC_FUNCS[t.name] = getattr (_module, _name)
except ImportError:
pass
#
# Do force clean if needed
#
if parser.isForceClean:
ARLog("Force clean !")
TARGETDIR = '%(MYDIR)s/Targets' % locals()
ARDeleteIfExists (TARGETDIR)
# Do all-cleanup if needed
if parser.isForceCleanup:
allRepoDirs=[]
for repo in repos.list:
if not repo.ext:
allRepoDirs.append(repo.getDir())
cleanScript = '%(MYDIR)s/Utils/cleanupSDKRepo.bash' % locals()
ARExecute(cleanScript + ' ' + ARListAsBashArg(allRepoDirs))
exit(0)
#
# Do all repo work:
# - Clone non existant repositories
# - Checkout the requested branch/tag/commit
# - If on a branch, pull it
#
if not parser.noGit:
checkAllReposUpToDate(repos, MYDIR, parser.repoBaseUrl, parser.defaultBaseRepoUrl, extraScripts=parser.extraGitScripts)
else:
ARLog('Skipping git checks')
if parser.doNothing:
ARLog('Nothing to be done')
exit(0)
# Android case --> Force minimum api level and target api level
ARSetEnv('AR_ANDROID_MIN_VERSION', '14')
ARSetEnv('AR_ANDROID_API_VERSION', '19')
#
# Actual build loop
#
allOk = True
for target in parser.activeTargets:
libraries.clearCache()
binaries.clearCache()
if parser.activeLibs:
if target.name in BUILD_LIB_FUNCS:
for lib in parser.activeLibs:
if not BUILD_LIB_FUNCS[target.name](target, lib, clean=parser.isClean, debug=parser.isDebug, nodeps=parser.noDeps, inhouse=parser.isInHouse, requestedArchs=parser.archs):
allOk = False
else:
ARLog('Unable to build libraries for target %(target)s' % locals())
if parser.genDoc and not parser.isClean:
if target.name in GEN_DOC_FUNCS:
for lib in parser.activeLibs:
GEN_DOC_FUNCS[target.name](target, lib)
TargetDocIndexScript = ARPathFromHere('Utils/generateDocIndex.bash')
TargetDocIndexPath = ARPathFromHere('Targets/%(target)s/Build/Doc' % locals())
ARExecute('%(TargetDocIndexScript)s %(TargetDocIndexPath)s %(target)s' % locals())
else:
ARLog('Unable to generate documentation for target %(target)s' % locals())
if parser.activeBins:
if target.name in BUILD_BIN_FUNCS:
for bin in parser.activeBins:
if not BUILD_BIN_FUNCS[target.name](target, bin, clean=parser.isClean, debug=parser.isDebug, nodeps=parser.noDeps, inhouse=parser.isInHouse, requestedArchs=parser.archs):
target.failed = True
allOk = False
else:
ARLog('Unable to build binaries for target %(target)s' % locals())
for scrinfo in target.postbuildScripts:
scr = scrinfo['path']
if allOk:
if not ARExecute(scr + ' >/dev/null 2>&1', failOnError=False):
ARPrint('Error while running ' + scr + '. Run manually to see the output')
target.failed = True
scrinfo['done'] = False
allOk=False
else:
scrinfo['done'] = True
if not allOk:
break
if parser.installDoc and allOk:
DocCopyScript = ARPathFromHere('Utils/copyDoc.bash')
for target in parser.activeTargets:
ARExecute ('%(DocCopyScript)s %(target)s' % locals())
hasColors = ARExecute('tput colors >/dev/null 2>&1', failOnError=False, printErrorMessage=False)
if ARExistsInPath('stty'):
termSizeStr = ARExecuteGetStdout(['stty', 'size'], failOnError=False, printErrorMessage=False)
termSizeArr = termSizeStr.split(' ')
try:
termCols = int(termSizeArr[1]) - 1
except:
termCols = 80
else:
termCols = 80
class logcolors:
FAIL = '\033[31m' if hasColors else 'FA:'
PASS = '\033[32m' if hasColors else 'OK:'
REQ = '\033[33m' if hasColors else 'ND:'
NONE = '\033[34m' if hasColors else 'NR:'
UNAI = '\033[30m' if hasColors else 'NA:'
DEF = '\033[39m' if hasColors else ''
def SDKPrintStatus(msg, available, requested, tried, built, padToLen=20, newline=False, currentCol=0, baseCol=0):
colorLen = 3 if not hasColors else 0
padLen = padToLen - len(msg)
while padLen <= 0:
padLen += padToLen
printLen = len(msg) + padLen + colorLen
futureCol = currentCol + printLen
if futureCol > termCols:
newline = True
if newline:
ARPrint('')
ARPrint(' '*baseCol, True)
futureCol = printLen + baseCol
if not available:
ARPrint(logcolors.UNAI, True)
elif not requested and not tried:
ARPrint(logcolors.NONE, True)
elif not tried:
ARPrint(logcolors.REQ, True)
elif not built:
ARPrint(logcolors.FAIL, True)
else:
ARPrint(logcolors.PASS, True)
ARPrint(msg, True)
if padLen > 0:
ARPrint(' '*padLen, True)
ARPrint(logcolors.DEF, True)
return futureCol
ARPrint('')
ARPrint('Status :')
ARPrint(' --> Legend : ' + logcolors.FAIL + 'FAIL ' + logcolors.PASS + 'PASS ' + logcolors.REQ + 'NOT_BUILT ' + logcolors.NONE + 'NOT_REQUESTED ' + logcolors.UNAI + 'NOT_AVAILABLE ' + logcolors.DEF)
ARPrint(' --> Binaries are postfixed with `*`')
ARPrint(' --> Postbuild scripts are postfixed with `+`')
ARPrint('')
offset = 13 if hasColors else 16
for t in targets.list:
targetRequested = t in parser.activeTargets
targetTried = bool(t.triedToBuildLibraries)
targetBuilt = len(t.alreadyBuiltLibraries) == len(t.triedToBuildLibraries) and not t.failed
SDKPrintStatus(t.name, True, targetRequested, targetTried, targetBuilt, padToLen=10)
ARPrint(' : ', True)
count=offset
first=False
for l in libraries.list:
libAvailable = l.isAvailableForTarget(t)
libRequested = l in parser.activeLibs and targetRequested
libTried = t.hasTriedToBuild(l)
libBuilt = t.hasAlreadyBuilt(l)
count = SDKPrintStatus(l.name, libAvailable, libRequested, libTried, libBuilt, padToLen=20, newline=first, currentCol=count, baseCol=offset)
first=False
first=True
for b in binaries.list:
binAvailable = b.isAvailableForTarget(t)
binRequested = b in parser.activeBins and targetRequested
binTried = t.hasTriedToBuildBinary(b)
binBuilt = t.hasAlreadyBuiltBinary(b)
count = SDKPrintStatus(b.name + '*', binAvailable, binRequested, binTried, binBuilt, padToLen=20, newline=first, currentCol=count, baseCol=offset)
first=False
first=True
for scrinfo in t.postbuildScripts:
scrAvailable = True
scrRequescted = targetRequested
scrTried = scrinfo['done'] is not None
scrBuilt = bool(scrinfo['done'])
count = SDKPrintStatus(scrinfo['name'] + '+', scrAvailable, scrRequescted, scrTried, scrBuilt, padToLen=20, newline=first, currentCol=count, baseCol=offset)
first=False
ARPrint('')
ARPrint('')
ARLog('End of build')
if not allOk:
ARLog('-- Errors were found during build ! --')
end = time.time()
seconds = int(end - start)
hours, tmp = divmod(seconds, 3600)
minutes, seconds = divmod(tmp, 60)
strh=''
strm=''
strs = str(seconds) + 's'
if hours > 0:
strh = str(hours) + 'h '
strm = str(minutes) + 'm '
if minutes > 0:
strm = str(minutes) + 'm '
ARLog('Build took %(strh)s%(strm)s%(strs)s' % locals())
sys.exit (0 if allOk else 1)