13
|
1 |
#
|
|
2 |
# Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# raptor_make module
|
|
16 |
# This module contains the classes that write and call Makefile wrappers.
|
|
17 |
#
|
|
18 |
|
|
19 |
import hashlib
|
|
20 |
import os
|
|
21 |
import random
|
|
22 |
import raptor
|
|
23 |
import raptor_timing
|
|
24 |
import raptor_utilities
|
|
25 |
import raptor_version
|
|
26 |
import raptor_data
|
|
27 |
import re
|
|
28 |
import subprocess
|
|
29 |
import time
|
|
30 |
from raptor_makefile import *
|
|
31 |
import traceback
|
|
32 |
import sys
|
|
33 |
from xml.sax.saxutils import escape
|
|
34 |
from xml.sax.saxutils import unescape
|
|
35 |
|
|
36 |
|
|
37 |
class BadMakeEngineException(Exception):
|
|
38 |
pass
|
|
39 |
|
|
40 |
def string_following(prefix, str):
|
|
41 |
"""If str starts with prefix then return the rest of str, otherwise None"""
|
|
42 |
if str.startswith(prefix):
|
|
43 |
return str[len(prefix):]
|
|
44 |
else:
|
|
45 |
return None
|
|
46 |
|
|
47 |
def XMLEscapeLog(stream):
|
|
48 |
""" A generator that reads a raptor log from a stream and performs an XML escape
|
|
49 |
on all text between tags, which is usually make output that could contain
|
|
50 |
illegal characters that upset XML-based log parsers.
|
|
51 |
This function yields "xml-safe" output line by line.
|
|
52 |
"""
|
|
53 |
inRecipe = False
|
|
54 |
|
|
55 |
for line in stream:
|
|
56 |
if line.startswith("<recipe"):
|
|
57 |
inRecipe = True
|
|
58 |
elif line.startswith("</recipe"):
|
|
59 |
inRecipe = False
|
|
60 |
|
|
61 |
# unless we are inside a "recipe", any line not starting
|
|
62 |
# with "<" is free text that must be escaped.
|
|
63 |
if inRecipe or line.startswith("<"):
|
|
64 |
yield line
|
|
65 |
else:
|
|
66 |
yield escape(line)
|
|
67 |
|
|
68 |
def AnnoFileParseOutput(annofile):
|
|
69 |
""" A generator that extracts log output from an emake annotation file,
|
|
70 |
perform an XML-unescape on it and "yields" it line by line. """
|
18
|
71 |
if isinstance(annofile,str):
|
|
72 |
af = open(annofile, "r")
|
|
73 |
else:
|
|
74 |
af = annofile
|
13
|
75 |
|
|
76 |
inOutput = False
|
|
77 |
|
|
78 |
buildid = ""
|
|
79 |
for line in af:
|
|
80 |
line = line.rstrip("\n\r")
|
|
81 |
|
|
82 |
|
|
83 |
if not inOutput:
|
|
84 |
o = string_following("<output>", line)
|
|
85 |
if not o:
|
|
86 |
o = string_following('<output src="prog">', line)
|
|
87 |
|
|
88 |
if o:
|
|
89 |
inOutput = True
|
|
90 |
yield unescape(o)+'\n'
|
|
91 |
continue
|
|
92 |
|
|
93 |
|
|
94 |
o = string_following('<build id="',line)
|
|
95 |
if o:
|
|
96 |
buildid = o[:o.find('"')]
|
|
97 |
yield "Starting build: "+buildid+"\n"
|
|
98 |
continue
|
|
99 |
|
|
100 |
o = string_following('<metric name="duration">', line)
|
|
101 |
if o:
|
|
102 |
secs = int(o[:o.find('<')])
|
|
103 |
if secs != 0:
|
|
104 |
duration = "%d:%d" % (secs/60, secs % 60)
|
|
105 |
else:
|
|
106 |
duration = "0:0"
|
|
107 |
continue
|
|
108 |
|
|
109 |
|
|
110 |
o = string_following('<metric name="clusterAvailability">', line)
|
|
111 |
if o:
|
|
112 |
availability = o[:o.find('<')]
|
|
113 |
continue
|
|
114 |
|
|
115 |
else:
|
|
116 |
end_output = line.find("</output>")
|
|
117 |
|
|
118 |
if end_output != -1:
|
|
119 |
line = line[:end_output]
|
|
120 |
inOutput = False
|
|
121 |
|
|
122 |
if line != "":
|
|
123 |
yield unescape(line)+'\n'
|
|
124 |
|
|
125 |
yield "Finished build: %s Duration: %s (m:s) Cluster availability: %s%%\n" %(buildid,duration,availability)
|
|
126 |
af.close()
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
# raptor_make module classes
|
|
131 |
|
|
132 |
class MakeEngine(object):
|
|
133 |
|
|
134 |
def __init__(self, Raptor, engine="make_engine"):
|
|
135 |
self.raptor = Raptor
|
|
136 |
self.valid = True
|
|
137 |
self.descrambler = None
|
|
138 |
self.descrambler_started = False
|
|
139 |
|
|
140 |
# look for an alias first as this gives end-users a chance to modify
|
|
141 |
# the shipped variant rather than completely replacing it.
|
|
142 |
if engine in Raptor.cache.aliases:
|
|
143 |
avar = Raptor.cache.FindNamedAlias(engine)
|
|
144 |
elif engine in Raptor.cache.variants:
|
|
145 |
avar = Raptor.cache.FindNamedVariant(engine)
|
|
146 |
else:
|
|
147 |
raise BadMakeEngineException("'%s' does not appear to be a make engine - no settings found for it" % engine)
|
|
148 |
|
|
149 |
if not avar.isDerivedFrom("make_engine", Raptor.cache):
|
|
150 |
raise BadMakeEngineException("'%s' is not a build engine (it's a variant but it does not extend 'make_engine')" % engine)
|
|
151 |
|
|
152 |
# find the variant and extract the values
|
|
153 |
try:
|
|
154 |
units = avar.GenerateBuildUnits(Raptor.cache)
|
|
155 |
evaluator = Raptor.GetEvaluator( None, units[0] , gathertools=True)
|
|
156 |
|
|
157 |
# shell
|
|
158 |
self.shellpath = evaluator.Get("DEFAULT_SHELL")
|
|
159 |
usetalon_s = evaluator.Get("USE_TALON")
|
|
160 |
self.usetalon = usetalon_s is not None and usetalon_s != ""
|
|
161 |
self.talonshell = str(evaluator.Get("TALON_SHELL"))
|
|
162 |
self.talontimeout = str(evaluator.Get("TALON_TIMEOUT"))
|
|
163 |
self.talonretries = str(evaluator.Get("TALON_RETRIES"))
|
18
|
164 |
|
|
165 |
# work around for RVCT 2.2 failed compiles
|
|
166 |
delete_on_failed_compile_s = evaluator.Get("DELETE_ON_FAILED_COMPILE")
|
|
167 |
self.delete_on_failed_compile = ""
|
|
168 |
if delete_on_failed_compile_s is not None and delete_on_failed_compile_s != "":
|
|
169 |
self.delete_on_failed_compile = "1"
|
13
|
170 |
|
|
171 |
# commands
|
|
172 |
self.initCommand = evaluator.Get("initialise")
|
|
173 |
self.buildCommand = evaluator.Get("build")
|
|
174 |
self.shutdownCommand = evaluator.Get("shutdown")
|
|
175 |
|
|
176 |
# options
|
|
177 |
self.makefileOption = evaluator.Get("makefile")
|
|
178 |
self.keepGoingOption = evaluator.Get("keep_going")
|
|
179 |
self.jobsOption = evaluator.Get("jobs")
|
|
180 |
self.defaultMakeOptions = evaluator.Get("defaultoptions")
|
|
181 |
|
|
182 |
# Logging
|
|
183 |
# copylogfromannofile means, for emake, that we should ignore
|
|
184 |
# emake's console output and instead extract output from its annotation
|
|
185 |
# file. This is a workaround for a problem where some emake
|
|
186 |
# console output is lost. The annotation file has a copy of this
|
|
187 |
# output in the "parse" job and it turns out to be uncorrupted.
|
|
188 |
self.copyLogFromAnnoFile = (evaluator.Get("copylogfromannofile") == "true")
|
|
189 |
self.annoFileName = None
|
|
190 |
|
|
191 |
if self.copyLogFromAnnoFile:
|
|
192 |
for o in self.raptor.makeOptions:
|
|
193 |
self.annoFileName = string_following("--emake-annofile=", o)
|
|
194 |
if self.annoFileName:
|
|
195 |
self.raptor.Info("annofile: " + o)
|
|
196 |
|
|
197 |
if not self.annoFileName:
|
|
198 |
self.raptor.Info("Cannot copy log from annotation file as no annotation filename was specified via the option --mo=--emake-annofile=<filename>")
|
|
199 |
self.copyLogFromAnnoFile = False
|
|
200 |
|
|
201 |
# buffering
|
|
202 |
self.scrambled = (evaluator.Get("scrambled") == "true")
|
|
203 |
|
|
204 |
# check tool versions
|
|
205 |
Raptor.CheckToolset(evaluator, avar.name)
|
|
206 |
|
|
207 |
# default targets (can vary per-invocation)
|
|
208 |
self.defaultTargets = Raptor.defaultTargets
|
|
209 |
|
|
210 |
# work out how to split up makefiles
|
|
211 |
try:
|
|
212 |
selectorNames = [ x.strip() for x in evaluator.Get("selectors").split(',') if x.strip() != "" ]
|
|
213 |
self.selectors = []
|
|
214 |
|
|
215 |
|
|
216 |
if len(selectorNames) > 0:
|
|
217 |
for name in selectorNames:
|
|
218 |
pattern = evaluator.Get(name.strip() + ".selector.iface")
|
|
219 |
target = evaluator.Get(name.strip() + ".selector.target")
|
|
220 |
ignoretargets = evaluator.Get(name.strip() + ".selector.ignoretargets")
|
|
221 |
self.selectors.append(MakefileSelector(name,pattern,target,ignoretargets))
|
|
222 |
except KeyError:
|
|
223 |
Raptor.Error("%s.selector.iface, %s.selector.target not found in make engine configuration", name, name)
|
|
224 |
self.selectors = []
|
|
225 |
|
|
226 |
except KeyError:
|
|
227 |
self.valid = False
|
|
228 |
raise BadMakeEngineException("Bad '%s' configuration found." % engine)
|
|
229 |
|
|
230 |
# there must at least be a build command...
|
|
231 |
if not self.buildCommand:
|
|
232 |
self.valid = False
|
|
233 |
raise BadMakeEngineException("No build command for '%s'"% engine)
|
|
234 |
|
|
235 |
|
|
236 |
if self.usetalon:
|
|
237 |
talon_settings="""
|
|
238 |
TALON_SHELL:=%s
|
|
239 |
TALON_TIMEOUT:=%s
|
|
240 |
TALON_RECIPEATTRIBUTES:=\
|
|
241 |
name='$$RECIPE'\
|
|
242 |
target='$$TARGET'\
|
|
243 |
host='$$HOSTNAME'\
|
|
244 |
layer='$$COMPONENT_LAYER'\
|
|
245 |
component='$$COMPONENT_NAME'\
|
|
246 |
bldinf='$$COMPONENT_META' mmp='$$PROJECT_META'\
|
|
247 |
config='$$SBS_CONFIGURATION' platform='$$PLATFORM'\
|
|
248 |
phase='$$MAKEFILE_GROUP' source='$$SOURCE'
|
|
249 |
export TALON_RECIPEATTRIBUTES TALON_SHELL TALON_TIMEOUT
|
|
250 |
USE_TALON:=%s
|
|
251 |
|
|
252 |
""" % (self.talonshell, self.talontimeout, "1")
|
|
253 |
else:
|
|
254 |
talon_settings="""
|
|
255 |
USE_TALON:=
|
|
256 |
|
|
257 |
"""
|
|
258 |
|
|
259 |
|
|
260 |
timing_start = "$(info " + \
|
|
261 |
raptor_timing.Timing.custom_string(tag = "start",
|
|
262 |
object_type = "makefile", task = "parse",
|
|
263 |
key = "$(THIS_FILENAME)",
|
|
264 |
time="$(shell date +%s.%N)").rstrip("\n") + ")"
|
|
265 |
|
|
266 |
timing_end = "$(info " + \
|
|
267 |
raptor_timing.Timing.custom_string(tag = "end",
|
|
268 |
object_type = "makefile", task = "parse",
|
|
269 |
key = "$(THIS_FILENAME)",
|
|
270 |
time="$(shell date +%s.%N)").rstrip("\n") + ")"
|
|
271 |
|
|
272 |
|
|
273 |
self.makefile_prologue = """
|
|
274 |
|
|
275 |
# generated by %s %s
|
|
276 |
|
|
277 |
HOSTPLATFORM:=%s
|
|
278 |
HOSTPLATFORM_DIR:=%s
|
|
279 |
OSTYPE:=%s
|
|
280 |
FLMHOME:=%s
|
|
281 |
SHELL:=%s
|
|
282 |
THIS_FILENAME:=$(firstword $(MAKEFILE_LIST))
|
18
|
283 |
DELETE_ON_FAILED_COMPILE:=%s
|
13
|
284 |
|
|
285 |
%s
|
|
286 |
|
|
287 |
include %s
|
|
288 |
|
|
289 |
""" % ( raptor.name, raptor_version.fullversion(),
|
|
290 |
" ".join(raptor.hostplatform),
|
|
291 |
raptor.hostplatform_dir,
|
|
292 |
self.raptor.filesystem,
|
|
293 |
str(self.raptor.systemFLM),
|
|
294 |
self.shellpath,
|
18
|
295 |
self.delete_on_failed_compile,
|
13
|
296 |
talon_settings,
|
|
297 |
self.raptor.systemFLM.Append('globals.mk') )
|
|
298 |
|
|
299 |
# Unless dependency processing has been eschewed via the CLI, use a .DEFAULT target to
|
|
300 |
# trap missing dependencies (ignoring user config files that we know are usually absent)
|
|
301 |
if not (self.raptor.noDependGenerate or self.raptor.noDependInclude):
|
|
302 |
self.makefile_prologue += """
|
|
303 |
|
|
304 |
$(FLMHOME)/user/final.mk:
|
|
305 |
$(FLMHOME)/user/default.flm:
|
|
306 |
$(FLMHOME)/user/globals.mk:
|
|
307 |
|
|
308 |
.DEFAULT::
|
|
309 |
@echo "<warning>Missing dependency detected: $@</warning>"
|
|
310 |
|
|
311 |
"""
|
|
312 |
|
|
313 |
# Only output timings if requested on CLI
|
|
314 |
if self.raptor.timing:
|
|
315 |
self.makefile_prologue += "\n# Print Start-time of Makefile parsing\n" \
|
|
316 |
+ timing_start + "\n\n"
|
|
317 |
|
|
318 |
|
|
319 |
self.makefile_epilogue = "\n\n# Print End-time of Makefile parsing\n" \
|
|
320 |
+ timing_end + "\n"
|
|
321 |
else:
|
|
322 |
self.makefile_epilogue = ""
|
|
323 |
|
|
324 |
self.makefile_epilogue += """
|
|
325 |
|
|
326 |
include %s
|
|
327 |
|
|
328 |
""" % (self.raptor.systemFLM.Append('final.mk') )
|
|
329 |
|
|
330 |
def Write(self, toplevel, specs, configs):
|
|
331 |
"""Generate a set of makefiles, or one big Makefile."""
|
|
332 |
|
|
333 |
if not self.valid:
|
|
334 |
return None
|
|
335 |
|
|
336 |
self.raptor.Debug("Writing Makefile '%s'" % (str(toplevel)))
|
|
337 |
|
|
338 |
self.toplevel = toplevel
|
|
339 |
|
|
340 |
# create the top-level makefiles
|
|
341 |
makefileset = None
|
|
342 |
|
|
343 |
try:
|
|
344 |
makefileset = MakefileSet(directory = str(toplevel.Dir()),
|
|
345 |
selectors = self.selectors,
|
|
346 |
filenamebase = str(toplevel.File()),
|
|
347 |
prologue = self.makefile_prologue,
|
|
348 |
epilogue = self.makefile_epilogue,
|
|
349 |
defaulttargets = self.defaultTargets)
|
|
350 |
|
|
351 |
# are we pruning duplicates?
|
|
352 |
self.prune = self.raptor.pruneDuplicateMakefiles
|
|
353 |
self.hashes = set()
|
|
354 |
|
|
355 |
# are we writing one Makefile or lots?
|
|
356 |
self.many = not self.raptor.writeSingleMakefile
|
|
357 |
|
|
358 |
# add a makefile for each spec under each config
|
|
359 |
config_makefileset = makefileset
|
|
360 |
for c in configs:
|
|
361 |
if self.many:
|
|
362 |
config_makefileset = makefileset.createChild(c.name)
|
|
363 |
|
|
364 |
# make sure the config_wide spec item is put out first so that it
|
|
365 |
# can affect everything.
|
|
366 |
ordered_specs=[]
|
|
367 |
config_wide_spec = None
|
|
368 |
for s in specs:
|
|
369 |
if s.name == "config_wide":
|
|
370 |
config_wide_spec = s
|
|
371 |
else:
|
|
372 |
ordered_specs.append(s)
|
|
373 |
|
|
374 |
if config_wide_spec is not None:
|
|
375 |
config_wide_spec.Configure(c, cache = self.raptor.cache)
|
|
376 |
self.WriteConfiguredSpec(config_makefileset, config_wide_spec, c, True)
|
|
377 |
|
|
378 |
for s in ordered_specs:
|
|
379 |
s.Configure(c, cache = self.raptor.cache)
|
|
380 |
self.WriteConfiguredSpec(config_makefileset, s, c, False)
|
|
381 |
|
|
382 |
makefileset.close()
|
|
383 |
except Exception,e:
|
|
384 |
tb = traceback.format_exc()
|
|
385 |
if not self.raptor.debugOutput:
|
|
386 |
tb=""
|
|
387 |
self.raptor.Error("Failed to write makefile '%s': %s : %s" % (str(toplevel),str(e),tb))
|
|
388 |
makefileset = None
|
|
389 |
|
|
390 |
return makefileset
|
|
391 |
|
|
392 |
|
|
393 |
def WriteConfiguredSpec(self, parentMakefileSet, spec, config, useAllInterfaces):
|
|
394 |
# ignore this spec if it is empty
|
|
395 |
hasInterface = spec.HasInterface()
|
|
396 |
childSpecs = spec.GetChildSpecs()
|
|
397 |
|
|
398 |
if not hasInterface and not childSpecs:
|
|
399 |
return
|
|
400 |
|
|
401 |
parameters = []
|
|
402 |
dupe = True
|
|
403 |
iface = None
|
|
404 |
guard = None
|
|
405 |
if hasInterface:
|
|
406 |
# find the Interface (it may be a ref)
|
|
407 |
try:
|
|
408 |
iface = spec.GetInterface(self.raptor.cache)
|
|
409 |
|
|
410 |
except raptor_data.MissingInterfaceError, e:
|
|
411 |
self.raptor.Error("No interface for '%s'", spec.name)
|
|
412 |
return
|
|
413 |
|
|
414 |
if iface.abstract:
|
|
415 |
self.raptor.Error("Abstract interface '%s' for '%s'",
|
|
416 |
iface.name, spec.name)
|
|
417 |
return
|
|
418 |
|
|
419 |
# we need to guard the FLM call with a hash based on all the
|
|
420 |
# parameter values so that duplicate calls cannot be made.
|
|
421 |
# So we need to find all the values before we can write
|
|
422 |
# anything out.
|
|
423 |
md5hash = hashlib.md5()
|
|
424 |
md5hash.update(iface.name)
|
|
425 |
|
|
426 |
# we need an Evaluator to get parameter values for this
|
|
427 |
# Specification in the context of this Configuration
|
|
428 |
evaluator = self.raptor.GetEvaluator(spec, config)
|
|
429 |
|
|
430 |
def addparam(k, value, default):
|
|
431 |
if value == None:
|
|
432 |
if p.default != None:
|
|
433 |
value = p.default
|
|
434 |
else:
|
|
435 |
self.raptor.Error("%s undefined for '%s'",
|
|
436 |
k, spec.name)
|
|
437 |
value = ""
|
|
438 |
|
|
439 |
parameters.append((k, value))
|
|
440 |
md5hash.update(value)
|
|
441 |
|
|
442 |
# parameters required by the interface
|
|
443 |
for p in iface.GetParams(self.raptor.cache):
|
|
444 |
val = evaluator.Resolve(p.name)
|
|
445 |
addparam(p.name,val,p.default)
|
|
446 |
|
|
447 |
# Use Patterns to fetch a group of parameters
|
|
448 |
for g in iface.GetParamGroups(self.raptor.cache):
|
|
449 |
for k,v in evaluator.ResolveMatching(g.patternre):
|
|
450 |
addparam(k,v,g.default)
|
|
451 |
|
|
452 |
hash = md5hash.hexdigest()
|
|
453 |
dupe = hash in self.hashes
|
|
454 |
|
|
455 |
self.hashes.add(hash)
|
|
456 |
|
|
457 |
# we only create a Makefile if we have a new FLM call to contribute,
|
|
458 |
# OR we are not pruning duplicates (guarding instead)
|
|
459 |
# OR we have some child specs that need something to include them.
|
|
460 |
if dupe and self.prune and not childSpecs:
|
|
461 |
return
|
|
462 |
|
|
463 |
makefileset = parentMakefileSet
|
|
464 |
# Create a new layer of makefiles?
|
|
465 |
if self.many:
|
|
466 |
makefileset = makefileset.createChild(spec.name)
|
|
467 |
|
|
468 |
if not (self.prune and dupe):
|
|
469 |
if self.prune:
|
|
470 |
guard = ""
|
|
471 |
else:
|
|
472 |
guard = "guard_" + hash
|
|
473 |
|
|
474 |
# generate the call to the FLM
|
|
475 |
if iface is not None:
|
|
476 |
makefileset.addCall(spec.name, config.name, iface.name, useAllInterfaces, iface.GetFLMIncludePath(self.raptor.cache), parameters, guard)
|
|
477 |
|
|
478 |
# recursive includes
|
|
479 |
|
|
480 |
for child in childSpecs:
|
|
481 |
self.WriteConfiguredSpec(makefileset, child, config, useAllInterfaces)
|
|
482 |
|
|
483 |
if self.many:
|
|
484 |
makefileset.close() # close child set of makefiles as we'll never see them again.
|
|
485 |
|
|
486 |
def Make(self, makefileset):
|
|
487 |
"run the make command"
|
|
488 |
|
|
489 |
if not self.valid:
|
|
490 |
return False
|
|
491 |
|
|
492 |
if self.usetalon:
|
|
493 |
# Always use Talon since it does the XML not
|
|
494 |
# just descrambling
|
|
495 |
if not self.StartTalon() and not self.raptor.keepGoing:
|
|
496 |
self.Tidy()
|
|
497 |
return False
|
|
498 |
else:
|
|
499 |
# use the descrambler if we are doing a parallel build on
|
|
500 |
# a make engine which does not buffer each agent's output
|
|
501 |
if self.raptor.jobs > 1 and self.scrambled:
|
|
502 |
self.StartDescrambler()
|
|
503 |
if not self.descrambler_started and not self.raptor.keepGoing:
|
|
504 |
self.Tidy()
|
|
505 |
return False
|
|
506 |
|
|
507 |
# run any initialisation script
|
|
508 |
if self.initCommand:
|
|
509 |
self.raptor.Info("Running %s", self.initCommand)
|
|
510 |
if os.system(self.initCommand) != 0:
|
|
511 |
self.raptor.Error("Failed in %s", self.initCommand)
|
|
512 |
self.Tidy()
|
|
513 |
return False
|
|
514 |
|
|
515 |
# Save file names to a list, to allow the order to be reversed
|
|
516 |
fileName_list = list(makefileset.makefileNames())
|
|
517 |
|
|
518 |
# Iterate through args passed to raptor, searching for CLEAN or REALLYCLEAN
|
|
519 |
clean_flag = False
|
|
520 |
for arg in self.raptor.args:
|
|
521 |
clean_flag = ("CLEAN" in self.raptor.args) or \
|
|
522 |
("REALLYCLEAN" in self.raptor.args)
|
|
523 |
|
|
524 |
# Files should be deleted in the opposite order to the order
|
|
525 |
# they were built. So reverse file order if cleaning
|
|
526 |
if clean_flag:
|
|
527 |
fileName_list.reverse()
|
|
528 |
|
|
529 |
# Report number of makefiles to be built
|
|
530 |
self.raptor.InfoDiscovery(object_type = "makefile", count = len(fileName_list))
|
|
531 |
|
|
532 |
# Process each file in turn
|
|
533 |
for makefile in fileName_list:
|
|
534 |
if not os.path.exists(makefile):
|
|
535 |
self.raptor.Info("Skipping makefile %s", makefile)
|
|
536 |
continue
|
|
537 |
self.raptor.Info("Making %s", makefile)
|
|
538 |
# assemble the build command line
|
|
539 |
command = self.buildCommand
|
|
540 |
|
|
541 |
if self.makefileOption:
|
|
542 |
command += " " + self.makefileOption + " " + ' "' + str(makefile) + '" '
|
|
543 |
|
|
544 |
if self.raptor.keepGoing and self.keepGoingOption:
|
|
545 |
command += " " + self.keepGoingOption
|
|
546 |
|
|
547 |
if self.raptor.jobs > 1 and self.jobsOption:
|
|
548 |
command += " " + self.jobsOption +" "+ str(self.raptor.jobs)
|
|
549 |
|
|
550 |
# Set default options first so that they can be overridden by
|
|
551 |
# ones set by the --mo option on the raptor commandline:
|
|
552 |
command += " " + self.defaultMakeOptions
|
|
553 |
# Can supply options on the commandline to override default settings.
|
|
554 |
if len(self.raptor.makeOptions) > 0:
|
|
555 |
for o in self.raptor.makeOptions:
|
|
556 |
if o.find(";") != -1 or o.find("\\") != -1:
|
|
557 |
command += " " + "'" + o + "'"
|
|
558 |
else:
|
|
559 |
command += " " + o
|
|
560 |
|
|
561 |
# Switch off dependency file including?
|
|
562 |
if self.raptor.noDependInclude or self.raptor.noDependGenerate:
|
|
563 |
command += " NO_DEPEND_INCLUDE=1"
|
|
564 |
|
|
565 |
# Switch off dependency file generation (and, implicitly, inclusion)?
|
|
566 |
if self.raptor.noDependGenerate:
|
|
567 |
command += " NO_DEPEND_GENERATE=1"
|
|
568 |
|
|
569 |
if self.usetalon:
|
|
570 |
# use the descrambler if we set it up
|
|
571 |
command += ' TALON_DESCRAMBLE='
|
|
572 |
if self.scrambled:
|
|
573 |
command += '1 '
|
|
574 |
else:
|
|
575 |
command += '0 '
|
|
576 |
else:
|
|
577 |
if self.descrambler_started:
|
|
578 |
command += ' DESCRAMBLE="' + self.descrambler + '"'
|
|
579 |
|
|
580 |
# use the retry mechanism if requested
|
|
581 |
if self.raptor.tries > 1:
|
|
582 |
command += ' RECIPETRIES=' + str(self.raptor.tries)
|
|
583 |
command += ' TALON_RETRIES=' + str(self.raptor.tries - 1)
|
|
584 |
|
|
585 |
# targets go at the end, if the makefile supports them
|
|
586 |
addTargets = self.raptor.targets[:]
|
|
587 |
ignoreTargets = makefileset.ignoreTargets(makefile)
|
|
588 |
if addTargets and ignoreTargets:
|
|
589 |
for target in self.raptor.targets:
|
|
590 |
if re.match(ignoreTargets, target):
|
|
591 |
addTargets.remove(target)
|
|
592 |
|
|
593 |
if addTargets:
|
|
594 |
command += " " + " ".join(addTargets)
|
|
595 |
|
|
596 |
# Send stderr to a file so that it can't mess up the log (e.g.
|
|
597 |
# clock skew messages from some build engines scatter their
|
|
598 |
# output across our xml.
|
|
599 |
stderrfilename = makefile+'.stderr'
|
|
600 |
stdoutfilename = makefile+'.stdout'
|
|
601 |
command += " 2>'%s' " % stderrfilename
|
|
602 |
|
|
603 |
# Keep a copy of the stdout too in the case of using the
|
|
604 |
# annofile - so that we can trap the problem that
|
|
605 |
# makes the copy-log-from-annofile workaround necessary
|
|
606 |
# and perhaps determine when we can remove it.
|
|
607 |
if self.copyLogFromAnnoFile:
|
|
608 |
command += " >'%s' " % stdoutfilename
|
|
609 |
|
|
610 |
# Substitute the makefile name for any occurrence of #MAKEFILE#
|
|
611 |
command = command.replace("#MAKEFILE#", str(makefile))
|
|
612 |
|
|
613 |
self.raptor.Info("Executing '%s'", command)
|
|
614 |
|
|
615 |
# execute the build.
|
|
616 |
# the actual call differs between Windows and Unix.
|
|
617 |
# bufsize=1 means "line buffered"
|
|
618 |
#
|
|
619 |
try:
|
|
620 |
# Time the build
|
|
621 |
self.raptor.InfoStartTime(object_type = "makefile",
|
|
622 |
task = "build", key = str(makefile))
|
|
623 |
|
|
624 |
makeenv=os.environ.copy()
|
|
625 |
if self.usetalon:
|
|
626 |
makeenv['TALON_RECIPEATTRIBUTES']="none"
|
|
627 |
makeenv['TALON_SHELL']=self.talonshell
|
|
628 |
makeenv['TALON_BUILDID']=str(self.buildID)
|
|
629 |
makeenv['TALON_TIMEOUT']=str(self.talontimeout)
|
|
630 |
|
|
631 |
if self.raptor.filesystem == "unix":
|
|
632 |
p = subprocess.Popen([command], bufsize=65535,
|
|
633 |
stdout=subprocess.PIPE,
|
|
634 |
stderr=subprocess.STDOUT,
|
|
635 |
close_fds=True, env=makeenv, shell=True)
|
|
636 |
else:
|
|
637 |
p = subprocess.Popen(args =
|
|
638 |
[raptor_data.ToolSet.shell, '-c', command],
|
|
639 |
bufsize=65535,
|
|
640 |
stdout=subprocess.PIPE,
|
|
641 |
stderr=subprocess.STDOUT,
|
|
642 |
shell = False,
|
|
643 |
universal_newlines=True, env=makeenv)
|
|
644 |
stream = p.stdout
|
|
645 |
|
|
646 |
inRecipe = False
|
|
647 |
|
|
648 |
if not self.copyLogFromAnnoFile:
|
|
649 |
for l in XMLEscapeLog(stream):
|
|
650 |
self.raptor.out.write(l)
|
|
651 |
|
|
652 |
returncode = p.wait()
|
|
653 |
else:
|
|
654 |
returncode = p.wait()
|
|
655 |
|
|
656 |
annofilename = self.annoFileName.replace("#MAKEFILE#", makefile)
|
|
657 |
self.raptor.Info("copylogfromannofile: Copying log from annotation file %s to work around a potential problem with the console output", annofilename)
|
|
658 |
try:
|
|
659 |
for l in XMLEscapeLog(AnnoFileParseOutput(annofilename)):
|
|
660 |
self.raptor.out.write(l)
|
|
661 |
except Exception,e:
|
|
662 |
self.raptor.Error("Couldn't complete stdout output from annofile %s for %s - '%s'", annofilename, command, str(e))
|
|
663 |
|
|
664 |
|
|
665 |
# Take all the stderr output that went into the .stderr file
|
|
666 |
# and put it back into the log, but safely so it can't mess up
|
|
667 |
# xml parsers.
|
|
668 |
try:
|
|
669 |
e = open(stderrfilename,"r")
|
|
670 |
for line in e:
|
|
671 |
self.raptor.out.write(escape(line))
|
|
672 |
e.close()
|
|
673 |
except Exception,e:
|
|
674 |
self.raptor.Error("Couldn't complete stderr output for %s - '%s'", command, str(e))
|
|
675 |
# Report end-time of the build
|
|
676 |
self.raptor.InfoEndTime(object_type = "makefile",
|
|
677 |
task = "build", key = str(makefile))
|
|
678 |
|
|
679 |
if returncode != 0 and not self.raptor.keepGoing:
|
|
680 |
self.Tidy()
|
|
681 |
return False
|
|
682 |
|
|
683 |
except Exception,e:
|
|
684 |
self.raptor.Error("Exception '%s' during '%s'", str(e), command)
|
|
685 |
self.Tidy()
|
|
686 |
# Still report end-time of the build
|
|
687 |
self.raptor.InfoEndTime(object_type = "Building", task = "Makefile",
|
|
688 |
key = str(makefile))
|
|
689 |
return False
|
|
690 |
|
|
691 |
# run any shutdown script
|
|
692 |
if self.shutdownCommand != None and self.shutdownCommand != "":
|
|
693 |
self.raptor.Info("Running %s", self.shutdownCommand)
|
|
694 |
if os.system(self.shutdownCommand) != 0:
|
|
695 |
self.raptor.Error("Failed in %s", self.shutdownCommand)
|
|
696 |
self.Tidy()
|
|
697 |
return False
|
|
698 |
|
|
699 |
self.Tidy()
|
|
700 |
return True
|
|
701 |
|
|
702 |
def Tidy(self):
|
|
703 |
if self.usetalon:
|
|
704 |
self.StopTalon()
|
|
705 |
else:
|
|
706 |
"clean up after the make command"
|
|
707 |
self.StopDescrambler()
|
|
708 |
|
|
709 |
def StartTalon(self):
|
|
710 |
# the talon command
|
|
711 |
beginning = raptor.hostplatform_dir + "/bin"
|
|
712 |
if "win" in raptor.hostplatform:
|
|
713 |
end = ".exe"
|
|
714 |
else:
|
|
715 |
end = ""
|
|
716 |
|
|
717 |
self.talonctl = str(self.raptor.home.Append(beginning, "talonctl"+end))
|
|
718 |
|
|
719 |
# generate a unique build number
|
|
720 |
random.seed()
|
|
721 |
looking = True
|
|
722 |
tries = 0
|
|
723 |
while looking and tries < 100:
|
|
724 |
self.buildID = raptor.name + str(random.getrandbits(32))
|
|
725 |
|
|
726 |
command = self.talonctl + " start"
|
|
727 |
|
|
728 |
os.environ["TALON_BUILDID"] = self.buildID
|
|
729 |
self.raptor.Info("Running %s", command)
|
|
730 |
looking = (os.system(command) != 0)
|
|
731 |
tries += 1
|
|
732 |
if looking:
|
|
733 |
self.raptor.Error("Failed to initialise the talon shell for this build")
|
|
734 |
self.talonctl = ""
|
|
735 |
return False
|
|
736 |
|
|
737 |
return True
|
|
738 |
|
|
739 |
def StopTalon(self):
|
|
740 |
if self.talonctl:
|
|
741 |
command = self.talonctl + " stop"
|
|
742 |
self.talonctl = ""
|
|
743 |
|
|
744 |
self.raptor.Info("Running %s", command)
|
|
745 |
if os.system(command) != 0:
|
|
746 |
self.raptor.Error("Failed in %s", command)
|
|
747 |
return False
|
|
748 |
|
|
749 |
return True
|
|
750 |
|
|
751 |
def StartDescrambler(self):
|
|
752 |
# the descrambler command
|
|
753 |
beginning = raptor.hostplatform_dir + "/bin"
|
|
754 |
if "win" in raptor.hostplatform:
|
|
755 |
end = ".exe"
|
|
756 |
else:
|
|
757 |
end = ""
|
|
758 |
|
|
759 |
self.descrambler = str(self.raptor.home.Append(beginning, "sbs_descramble"+end))
|
|
760 |
|
|
761 |
# generate a unique build number
|
|
762 |
random.seed()
|
|
763 |
looking = True
|
|
764 |
tries = 0
|
|
765 |
while looking and tries < 100:
|
|
766 |
buildID = raptor.name + str(random.getrandbits(32))
|
|
767 |
|
|
768 |
command = self.descrambler + " " + buildID + " start"
|
|
769 |
self.raptor.Info("Running %s", command)
|
|
770 |
looking = (os.system(command) != 0)
|
|
771 |
tries += 1
|
|
772 |
|
|
773 |
if looking:
|
|
774 |
self.raptor.Error("Failed to start the log descrambler")
|
|
775 |
self.descrambler_started = True
|
|
776 |
return False
|
|
777 |
|
|
778 |
self.descrambler_started = True
|
|
779 |
self.descrambler += " " + buildID
|
|
780 |
|
|
781 |
return True
|
|
782 |
|
|
783 |
def StopDescrambler(self):
|
|
784 |
if self.descrambler_started:
|
|
785 |
command = self.descrambler + " stop"
|
|
786 |
self.descrambler = ""
|
|
787 |
|
|
788 |
self.raptor.Info("Running %s", command)
|
|
789 |
if os.system(command) != 0:
|
|
790 |
self.raptor.Error("Failed in %s", command)
|
|
791 |
return False
|
|
792 |
return True
|
|
793 |
|
|
794 |
|
|
795 |
|
|
796 |
# raptor_make module functions
|
|
797 |
|
|
798 |
|
|
799 |
# end of the raptor_make module
|