author | Iain Williamson <iain.williamson@nokia.com> |
Fri, 29 Jan 2010 17:36:06 +0000 | |
branch | fix |
changeset 183 | 7c04ad290aca |
parent 134 | 2648751b64b4 |
child 176 | b601167a8189 |
child 219 | c3543adfd26e |
permissions | -rw-r--r-- |
3 | 1 |
# |
2 |
# Copyright (c) 2006-2009 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 |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
23 |
import raptor_timing |
3 | 24 |
import raptor_utilities |
25 |
import raptor_version |
|
5 | 26 |
import raptor_data |
3 | 27 |
import re |
28 |
import subprocess |
|
29 |
import time |
|
30 |
from raptor_makefile import * |
|
5 | 31 |
import traceback |
32 |
import sys |
|
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
33 |
from xml.sax.saxutils import escape |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
34 |
|
3 | 35 |
|
36 |
# raptor_make module classes |
|
37 |
||
38 |
class MakeEngine(object): |
|
39 |
||
40 |
def __init__(self, Raptor): |
|
41 |
self.raptor = Raptor |
|
42 |
self.valid = True |
|
43 |
self.descrambler = None |
|
44 |
self.descrambler_started = False |
|
45 |
||
46 |
engine = Raptor.makeEngine |
|
47 |
||
48 |
# look for an alias first as this gives end-users a chance to modify |
|
49 |
# the shipped variant rather than completely replacing it. |
|
50 |
if engine in Raptor.cache.aliases: |
|
51 |
avar = Raptor.cache.FindNamedAlias(engine) |
|
52 |
elif engine in Raptor.cache.variants: |
|
53 |
avar = Raptor.cache.FindNamedVariant(engine) |
|
54 |
else: |
|
55 |
Raptor.Error("No settings found for build engine '%s'", engine) |
|
56 |
return |
|
57 |
||
58 |
# find the variant and extract the values |
|
59 |
try: |
|
5 | 60 |
units = avar.GenerateBuildUnits(Raptor.cache) |
3 | 61 |
evaluator = Raptor.GetEvaluator( None, units[0] , gathertools=True) |
62 |
||
63 |
# shell |
|
64 |
self.shellpath = evaluator.Get("DEFAULT_SHELL") |
|
65 |
usetalon_s = evaluator.Get("USE_TALON") |
|
66 |
self.usetalon = usetalon_s is not None and usetalon_s != "" |
|
67 |
self.talonshell = str(evaluator.Get("TALON_SHELL")) |
|
68 |
self.talontimeout = str(evaluator.Get("TALON_TIMEOUT")) |
|
69 |
self.talonretries = str(evaluator.Get("TALON_RETRIES")) |
|
70 |
||
71 |
# commands |
|
72 |
self.initCommand = evaluator.Get("initialise") |
|
73 |
self.buildCommand = evaluator.Get("build") |
|
74 |
self.shutdownCommand = evaluator.Get("shutdown") |
|
75 |
||
76 |
# options |
|
77 |
self.makefileOption = evaluator.Get("makefile") |
|
78 |
self.keepGoingOption = evaluator.Get("keep_going") |
|
79 |
self.jobsOption = evaluator.Get("jobs") |
|
80 |
self.defaultMakeOptions = evaluator.Get("defaultoptions") |
|
81 |
||
82 |
# buffering |
|
83 |
self.scrambled = (evaluator.Get("scrambled") == "true") |
|
84 |
||
85 |
# check tool versions |
|
86 |
Raptor.CheckToolset(evaluator, avar.name) |
|
87 |
||
88 |
# default targets (can vary per-invocation) |
|
89 |
self.defaultTargets = Raptor.defaultTargets |
|
90 |
||
91 |
# work out how to split up makefiles |
|
92 |
try: |
|
93 |
selectorNames = [ x.strip() for x in evaluator.Get("selectors").split(',') if x.strip() != "" ] |
|
94 |
self.selectors = [] |
|
95 |
||
96 |
||
97 |
if len(selectorNames) > 0: |
|
98 |
for name in selectorNames: |
|
99 |
pattern = evaluator.Get(name.strip() + ".selector.iface") |
|
100 |
target = evaluator.Get(name.strip() + ".selector.target") |
|
101 |
ignoretargets = evaluator.Get(name.strip() + ".selector.ignoretargets") |
|
102 |
self.selectors.append(MakefileSelector(name,pattern,target,ignoretargets)) |
|
103 |
except KeyError: |
|
104 |
Raptor.Error("%s.selector.iface, %s.selector.target not found in make engine configuration", name, name) |
|
105 |
self.selectors = [] |
|
106 |
||
107 |
except KeyError: |
|
108 |
Raptor.Error("Bad '%s' configuration found.", engine) |
|
109 |
self.valid = False |
|
110 |
return |
|
111 |
||
112 |
# there must at least be a build command... |
|
113 |
if not self.buildCommand: |
|
114 |
Raptor.Error("No build command for '%s'", engine) |
|
115 |
self.valid = False |
|
116 |
||
117 |
||
118 |
if self.usetalon: |
|
119 |
talon_settings=""" |
|
120 |
TALON_SHELL:=%s |
|
121 |
TALON_TIMEOUT:=%s |
|
122 |
TALON_RECIPEATTRIBUTES:=\ |
|
123 |
name='$$RECIPE'\ |
|
124 |
target='$$TARGET'\ |
|
125 |
host='$$HOSTNAME'\ |
|
126 |
layer='$$COMPONENT_LAYER'\ |
|
127 |
component='$$COMPONENT_NAME'\ |
|
128 |
bldinf='$$COMPONENT_META' mmp='$$PROJECT_META'\ |
|
129 |
config='$$SBS_CONFIGURATION' platform='$$PLATFORM'\ |
|
5 | 130 |
phase='$$MAKEFILE_GROUP' source='$$SOURCE' |
3 | 131 |
export TALON_RECIPEATTRIBUTES TALON_SHELL TALON_TIMEOUT |
132 |
USE_TALON:=%s |
|
133 |
||
134 |
""" % (self.talonshell, self.talontimeout, "1") |
|
135 |
else: |
|
136 |
talon_settings=""" |
|
137 |
USE_TALON:= |
|
138 |
||
139 |
""" |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
140 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
141 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
142 |
timing_start = "$(info " + \ |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
143 |
raptor_timing.Timing.custom_string(tag = "start", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
144 |
object_type = "makefile", task = "parse", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
145 |
key = "$(THIS_FILENAME)", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
146 |
time="$(shell date +%s.%N)").rstrip("\n") + ")" |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
147 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
148 |
timing_end = "$(info " + \ |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
149 |
raptor_timing.Timing.custom_string(tag = "end", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
150 |
object_type = "makefile", task = "parse", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
151 |
key = "$(THIS_FILENAME)", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
152 |
time="$(shell date +%s.%N)").rstrip("\n") + ")" |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
153 |
|
3 | 154 |
|
155 |
self.makefile_prologue = """ |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
156 |
|
3 | 157 |
# generated by %s %s |
158 |
||
159 |
HOSTPLATFORM:=%s |
|
160 |
HOSTPLATFORM_DIR:=%s |
|
161 |
OSTYPE:=%s |
|
162 |
FLMHOME:=%s |
|
163 |
SHELL:=%s |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
164 |
THIS_FILENAME:=$(firstword $(MAKEFILE_LIST)) |
3 | 165 |
|
166 |
%s |
|
167 |
||
168 |
include %s |
|
169 |
||
5 | 170 |
""" % ( raptor.name, raptor_version.fullversion(), |
3 | 171 |
" ".join(raptor.hostplatform), |
172 |
raptor.hostplatform_dir, |
|
173 |
self.raptor.filesystem, |
|
174 |
str(self.raptor.systemFLM), |
|
175 |
self.shellpath, |
|
176 |
talon_settings, |
|
177 |
self.raptor.systemFLM.Append('globals.mk') ) |
|
178 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
179 |
# Only output timings if requested on CLI |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
180 |
if self.raptor.timing: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
181 |
self.makefile_prologue += "\n# Print Start-time of Makefile parsing\n" \ |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
182 |
+ timing_start + "\n\n" |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
183 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
184 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
185 |
self.makefile_epilogue = "\n\n# Print End-time of Makefile parsing\n" \ |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
186 |
+ timing_end + "\n" |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
187 |
else: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
188 |
self.makefile_epilogue = "" |
3 | 189 |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
190 |
self.makefile_epilogue += """ |
3 | 191 |
|
192 |
include %s |
|
193 |
||
194 |
""" % (self.raptor.systemFLM.Append('final.mk') ) |
|
195 |
||
196 |
def Write(self, toplevel, specs, configs): |
|
197 |
"""Generate a set of makefiles, or one big Makefile.""" |
|
198 |
||
199 |
if not self.valid: |
|
5 | 200 |
return None |
201 |
||
202 |
self.raptor.Debug("Writing Makefile '%s'" % (str(toplevel))) |
|
3 | 203 |
|
204 |
self.toplevel = toplevel |
|
205 |
||
206 |
# create the top-level makefiles |
|
5 | 207 |
makefileset = None |
3 | 208 |
|
209 |
try: |
|
5 | 210 |
makefileset = MakefileSet(directory = str(toplevel.Dir()), |
3 | 211 |
selectors = self.selectors, |
212 |
filenamebase = str(toplevel.File()), |
|
213 |
prologue = self.makefile_prologue, |
|
214 |
epilogue = self.makefile_epilogue, |
|
215 |
defaulttargets = self.defaultTargets) |
|
216 |
||
217 |
# are we pruning duplicates? |
|
218 |
self.prune = self.raptor.pruneDuplicateMakefiles |
|
219 |
self.hashes = set() |
|
220 |
||
221 |
# are we writing one Makefile or lots? |
|
222 |
self.many = not self.raptor.writeSingleMakefile |
|
223 |
||
224 |
# add a makefile for each spec under each config |
|
5 | 225 |
config_makefileset = makefileset |
3 | 226 |
for c in configs: |
227 |
if self.many: |
|
5 | 228 |
config_makefileset = makefileset.createChild(c.name) |
3 | 229 |
|
230 |
# make sure the config_wide spec item is put out first so that it |
|
231 |
# can affect everything. |
|
232 |
ordered_specs=[] |
|
233 |
config_wide_spec = None |
|
234 |
for s in specs: |
|
235 |
if s.name == "config_wide": |
|
236 |
config_wide_spec = s |
|
237 |
else: |
|
238 |
ordered_specs.append(s) |
|
239 |
||
240 |
if config_wide_spec is not None: |
|
5 | 241 |
config_wide_spec.Configure(c, cache = self.raptor.cache) |
3 | 242 |
self.WriteConfiguredSpec(config_makefileset, config_wide_spec, c, True) |
243 |
||
244 |
for s in ordered_specs: |
|
5 | 245 |
s.Configure(c, cache = self.raptor.cache) |
3 | 246 |
self.WriteConfiguredSpec(config_makefileset, s, c, False) |
247 |
||
5 | 248 |
makefileset.close() |
3 | 249 |
except Exception,e: |
5 | 250 |
tb = traceback.format_exc() |
251 |
if not self.raptor.debugOutput: |
|
252 |
tb="" |
|
253 |
self.raptor.Error("Failed to write makefile '%s': %s : %s" % (str(toplevel),str(e),tb)) |
|
254 |
makefileset = None |
|
255 |
||
256 |
return makefileset |
|
3 | 257 |
|
258 |
||
259 |
def WriteConfiguredSpec(self, parentMakefileSet, spec, config, useAllInterfaces): |
|
260 |
# ignore this spec if it is empty |
|
261 |
hasInterface = spec.HasInterface() |
|
262 |
childSpecs = spec.GetChildSpecs() |
|
263 |
||
264 |
if not hasInterface and not childSpecs: |
|
265 |
return |
|
266 |
||
267 |
parameters = [] |
|
268 |
dupe = True |
|
269 |
iface = None |
|
270 |
guard = None |
|
271 |
if hasInterface: |
|
272 |
# find the Interface (it may be a ref) |
|
5 | 273 |
try: |
274 |
iface = spec.GetInterface(self.raptor.cache) |
|
3 | 275 |
|
5 | 276 |
except raptor_data.MissingInterfaceError, e: |
3 | 277 |
self.raptor.Error("No interface for '%s'", spec.name) |
278 |
return |
|
279 |
||
280 |
if iface.abstract: |
|
281 |
self.raptor.Error("Abstract interface '%s' for '%s'", |
|
282 |
iface.name, spec.name) |
|
283 |
return |
|
284 |
||
285 |
# we need to guard the FLM call with a hash based on all the |
|
286 |
# parameter values so that duplicate calls cannot be made. |
|
287 |
# So we need to find all the values before we can write |
|
288 |
# anything out. |
|
289 |
md5hash = hashlib.md5() |
|
290 |
md5hash.update(iface.name) |
|
291 |
||
292 |
# we need an Evaluator to get parameter values for this |
|
293 |
# Specification in the context of this Configuration |
|
294 |
evaluator = self.raptor.GetEvaluator(spec, config) |
|
295 |
||
296 |
def addparam(k, value, default): |
|
297 |
if value == None: |
|
298 |
if p.default != None: |
|
299 |
value = p.default |
|
300 |
else: |
|
301 |
self.raptor.Error("%s undefined for '%s'", |
|
302 |
k, spec.name) |
|
303 |
value = "" |
|
304 |
||
305 |
parameters.append((k, value)) |
|
306 |
md5hash.update(value) |
|
307 |
||
308 |
# parameters required by the interface |
|
5 | 309 |
for p in iface.GetParams(self.raptor.cache): |
3 | 310 |
val = evaluator.Resolve(p.name) |
311 |
addparam(p.name,val,p.default) |
|
312 |
||
313 |
# Use Patterns to fetch a group of parameters |
|
5 | 314 |
for g in iface.GetParamGroups(self.raptor.cache): |
3 | 315 |
for k,v in evaluator.ResolveMatching(g.patternre): |
316 |
addparam(k,v,g.default) |
|
317 |
||
318 |
hash = md5hash.hexdigest() |
|
319 |
dupe = hash in self.hashes |
|
320 |
||
321 |
self.hashes.add(hash) |
|
322 |
||
323 |
# we only create a Makefile if we have a new FLM call to contribute, |
|
324 |
# OR we are not pruning duplicates (guarding instead) |
|
325 |
# OR we have some child specs that need something to include them. |
|
326 |
if dupe and self.prune and not childSpecs: |
|
327 |
return |
|
328 |
||
329 |
makefileset = parentMakefileSet |
|
330 |
# Create a new layer of makefiles? |
|
331 |
if self.many: |
|
332 |
makefileset = makefileset.createChild(spec.name) |
|
333 |
||
334 |
if not (self.prune and dupe): |
|
335 |
if self.prune: |
|
336 |
guard = "" |
|
337 |
else: |
|
338 |
guard = "guard_" + hash |
|
339 |
||
340 |
# generate the call to the FLM |
|
341 |
if iface is not None: |
|
5 | 342 |
makefileset.addCall(spec.name, config.name, iface.name, useAllInterfaces, iface.GetFLMIncludePath(self.raptor.cache), parameters, guard) |
3 | 343 |
|
344 |
# recursive includes |
|
345 |
||
346 |
for child in childSpecs: |
|
347 |
self.WriteConfiguredSpec(makefileset, child, config, useAllInterfaces) |
|
348 |
||
349 |
if self.many: |
|
350 |
makefileset.close() # close child set of makefiles as we'll never see them again. |
|
351 |
||
352 |
def Make(self, makefileset): |
|
353 |
"run the make command" |
|
354 |
||
355 |
if not self.valid: |
|
356 |
return False |
|
357 |
||
358 |
if self.usetalon: |
|
359 |
# Always use Talon since it does the XML not |
|
360 |
# just descrambling |
|
361 |
if not self.StartTalon() and not self.raptor.keepGoing: |
|
362 |
self.Tidy() |
|
363 |
return False |
|
364 |
else: |
|
365 |
# use the descrambler if we are doing a parallel build on |
|
366 |
# a make engine which does not buffer each agent's output |
|
367 |
if self.raptor.jobs > 1 and self.scrambled: |
|
368 |
self.StartDescrambler() |
|
369 |
if not self.descrambler_started and not self.raptor.keepGoing: |
|
370 |
self.Tidy() |
|
371 |
return False |
|
372 |
||
373 |
# run any initialisation script |
|
374 |
if self.initCommand: |
|
375 |
self.raptor.Info("Running %s", self.initCommand) |
|
376 |
if os.system(self.initCommand) != 0: |
|
377 |
self.raptor.Error("Failed in %s", self.initCommand) |
|
378 |
self.Tidy() |
|
379 |
return False |
|
380 |
||
381 |
# Save file names to a list, to allow the order to be reversed |
|
5 | 382 |
fileName_list = list(makefileset.makefileNames()) |
3 | 383 |
|
384 |
# Iterate through args passed to raptor, searching for CLEAN or REALLYCLEAN |
|
385 |
clean_flag = False |
|
386 |
for arg in self.raptor.args: |
|
387 |
clean_flag = ("CLEAN" in self.raptor.args) or \ |
|
388 |
("REALLYCLEAN" in self.raptor.args) |
|
389 |
||
390 |
# Files should be deleted in the opposite order to the order |
|
391 |
# they were built. So reverse file order if cleaning |
|
392 |
if clean_flag: |
|
393 |
fileName_list.reverse() |
|
394 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
395 |
# Report number of makefiles to be built |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
396 |
self.raptor.InfoDiscovery(object_type = "makefile", count = len(fileName_list)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
397 |
|
3 | 398 |
# Process each file in turn |
399 |
for makefile in fileName_list: |
|
400 |
if not os.path.exists(makefile): |
|
401 |
self.raptor.Info("Skipping makefile %s", makefile) |
|
402 |
continue |
|
403 |
self.raptor.Info("Making %s", makefile) |
|
404 |
# assemble the build command line |
|
405 |
command = self.buildCommand |
|
406 |
||
407 |
if self.makefileOption: |
|
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
408 |
command += " " + self.makefileOption + " " + ' "' + str(makefile) + '" ' |
3 | 409 |
|
410 |
if self.raptor.keepGoing and self.keepGoingOption: |
|
411 |
command += " " + self.keepGoingOption |
|
412 |
||
413 |
if self.raptor.jobs > 1 and self.jobsOption: |
|
414 |
command += " " + self.jobsOption +" "+ str(self.raptor.jobs) |
|
415 |
||
416 |
# Set default options first so that they can be overridden by |
|
417 |
# ones set by the --mo option on the raptor commandline: |
|
418 |
command += " " + self.defaultMakeOptions |
|
419 |
# Can supply options on the commandline to override default settings. |
|
420 |
if len(self.raptor.makeOptions) > 0: |
|
122
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
421 |
for o in self.raptor.makeOptions: |
134
2648751b64b4
Use '' to protect backslashes in arguments rather than escaping. For parallel parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
130
diff
changeset
|
422 |
if o.find(";") != -1 or o.find("\\") != -1: |
122
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
423 |
command += " " + "'" + o + "'" |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
424 |
else: |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
425 |
command += " " + o |
3 | 426 |
|
427 |
# Switch off dependency file including? |
|
428 |
if self.raptor.noDependInclude: |
|
429 |
command += " NO_DEPEND_INCLUDE=1" |
|
430 |
||
431 |
if self.usetalon: |
|
432 |
# use the descrambler if we set it up |
|
433 |
command += ' TALON_DESCRAMBLE=' |
|
434 |
if self.scrambled: |
|
435 |
command += '1 ' |
|
436 |
else: |
|
437 |
command += '0 ' |
|
438 |
else: |
|
439 |
if self.descrambler_started: |
|
440 |
command += ' DESCRAMBLE="' + self.descrambler + '"' |
|
441 |
||
442 |
# use the retry mechanism if requested |
|
443 |
if self.raptor.tries > 1: |
|
444 |
command += ' RECIPETRIES=' + str(self.raptor.tries) |
|
445 |
command += ' TALON_RETRIES=' + str(self.raptor.tries - 1) |
|
446 |
||
447 |
# targets go at the end, if the makefile supports them |
|
448 |
addTargets = self.raptor.targets[:] |
|
5 | 449 |
ignoreTargets = makefileset.ignoreTargets(makefile) |
3 | 450 |
if addTargets and ignoreTargets: |
451 |
for target in self.raptor.targets: |
|
452 |
if re.match(ignoreTargets, target): |
|
453 |
addTargets.remove(target) |
|
454 |
||
455 |
if addTargets: |
|
456 |
command += " " + " ".join(addTargets) |
|
457 |
||
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
458 |
# Send stderr to a file so that it can't mess up the log (e.g. |
130
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
459 |
# clock skew messages from some build engines scatter their |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
460 |
# output across our xml. |
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
461 |
stderrfilename = makefile+'.stderr' |
122
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
462 |
command += " 2>'%s' " % stderrfilename |
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
463 |
|
5 | 464 |
# Substitute the makefile name for any occurrence of #MAKEFILE# |
465 |
command = command.replace("#MAKEFILE#", str(makefile)) |
|
466 |
||
3 | 467 |
self.raptor.Info("Executing '%s'", command) |
468 |
||
469 |
# execute the build. |
|
470 |
# the actual call differs between Windows and Unix. |
|
471 |
# bufsize=1 means "line buffered" |
|
472 |
# |
|
473 |
try: |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
474 |
# Time the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
475 |
self.raptor.InfoStartTime(object_type = "makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
476 |
task = "build", key = str(makefile)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
477 |
|
3 | 478 |
makeenv=os.environ.copy() |
479 |
if self.usetalon: |
|
480 |
makeenv['TALON_RECIPEATTRIBUTES']="none" |
|
481 |
makeenv['TALON_SHELL']=self.talonshell |
|
482 |
makeenv['TALON_BUILDID']=str(self.buildID) |
|
483 |
makeenv['TALON_TIMEOUT']=str(self.talontimeout) |
|
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
484 |
|
3 | 485 |
if self.raptor.filesystem == "unix": |
118 | 486 |
p = subprocess.Popen([command], bufsize=65535, |
487 |
stdout=subprocess.PIPE, |
|
488 |
stderr=subprocess.STDOUT, |
|
489 |
close_fds=True, env=makeenv, shell=True) |
|
3 | 490 |
else: |
118 | 491 |
p = subprocess.Popen(args = |
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
492 |
[raptor_data.ToolSet.shell, '-c', command], |
118 | 493 |
bufsize=65535, |
494 |
stdout=subprocess.PIPE, |
|
495 |
stderr=subprocess.STDOUT, |
|
496 |
shell = False, |
|
497 |
universal_newlines=True, env=makeenv) |
|
3 | 498 |
stream = p.stdout |
499 |
||
500 |
||
501 |
line = " " |
|
502 |
while line: |
|
503 |
line = stream.readline() |
|
504 |
self.raptor.out.write(line) |
|
505 |
||
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
506 |
|
3 | 507 |
# should be done now |
508 |
returncode = p.wait() |
|
509 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
510 |
# Report end-time of the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
511 |
self.raptor.InfoEndTime(object_type = "makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
512 |
task = "build", key = str(makefile)) |
3 | 513 |
|
130
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
514 |
# Take all the stderr output that went into the .stderr file |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
515 |
# and put it back into the log, but safely so it can't mess up |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
516 |
# xml parsers. |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
517 |
try: |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
518 |
e = open(stderrfilename,"r") |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
519 |
for line in e: |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
520 |
self.raptor.out.write(escape(line)) |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
521 |
e.close() |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
522 |
except Exception,e: |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
523 |
self.raptor.Error("Couldn't complete stderr output for %s - '%s'", command, str(e)) |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
524 |
|
3 | 525 |
if returncode != 0 and not self.raptor.keepGoing: |
526 |
self.Tidy() |
|
527 |
return False |
|
528 |
||
529 |
except Exception,e: |
|
530 |
self.raptor.Error("Exception '%s' during '%s'", str(e), command) |
|
531 |
self.Tidy() |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
532 |
# Still report end-time of the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
533 |
self.raptor.InfoEnd(object_type = "Building", task = "Makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
534 |
key = str(makefile)) |
3 | 535 |
return False |
536 |
||
537 |
# run any shutdown script |
|
538 |
if self.shutdownCommand != None and self.shutdownCommand != "": |
|
539 |
self.raptor.Info("Running %s", self.shutdownCommand) |
|
540 |
if os.system(self.shutdownCommand) != 0: |
|
541 |
self.raptor.Error("Failed in %s", self.shutdownCommand) |
|
542 |
self.Tidy() |
|
543 |
return False |
|
544 |
||
545 |
self.Tidy() |
|
546 |
return True |
|
547 |
||
548 |
def Tidy(self): |
|
549 |
if self.usetalon: |
|
550 |
self.StopTalon() |
|
551 |
else: |
|
552 |
"clean up after the make command" |
|
553 |
self.StopDescrambler() |
|
554 |
||
555 |
def StartTalon(self): |
|
556 |
# the talon command |
|
557 |
beginning = raptor.hostplatform_dir + "/bin" |
|
558 |
if "win" in raptor.hostplatform: |
|
559 |
end = ".exe" |
|
560 |
else: |
|
561 |
end = "" |
|
562 |
||
563 |
self.talonctl = str(self.raptor.home.Append(beginning, "talonctl"+end)) |
|
564 |
||
565 |
# generate a unique build number |
|
566 |
random.seed() |
|
567 |
looking = True |
|
568 |
tries = 0 |
|
569 |
while looking and tries < 100: |
|
570 |
self.buildID = raptor.name + str(random.getrandbits(32)) |
|
571 |
||
572 |
command = self.talonctl + " start" |
|
573 |
||
574 |
os.environ["TALON_BUILDID"] = self.buildID |
|
575 |
self.raptor.Info("Running %s", command) |
|
576 |
looking = (os.system(command) != 0) |
|
577 |
tries += 1 |
|
578 |
if looking: |
|
5 | 579 |
self.raptor.Error("Failed to initialise the talon shell for this build") |
3 | 580 |
self.talonctl = "" |
581 |
return False |
|
582 |
||
583 |
return True |
|
584 |
||
585 |
def StopTalon(self): |
|
586 |
if self.talonctl: |
|
587 |
command = self.talonctl + " stop" |
|
588 |
self.talonctl = "" |
|
589 |
||
590 |
self.raptor.Info("Running %s", command) |
|
591 |
if os.system(command) != 0: |
|
592 |
self.raptor.Error("Failed in %s", command) |
|
593 |
return False |
|
594 |
||
595 |
return True |
|
596 |
||
597 |
def StartDescrambler(self): |
|
598 |
# the descrambler command |
|
599 |
beginning = raptor.hostplatform_dir + "/bin" |
|
600 |
if "win" in raptor.hostplatform: |
|
601 |
end = ".exe" |
|
602 |
else: |
|
603 |
end = "" |
|
604 |
||
605 |
self.descrambler = str(self.raptor.home.Append(beginning, "sbs_descramble"+end)) |
|
606 |
||
607 |
# generate a unique build number |
|
608 |
random.seed() |
|
609 |
looking = True |
|
610 |
tries = 0 |
|
611 |
while looking and tries < 100: |
|
612 |
buildID = raptor.name + str(random.getrandbits(32)) |
|
613 |
||
614 |
command = self.descrambler + " " + buildID + " start" |
|
615 |
self.raptor.Info("Running %s", command) |
|
616 |
looking = (os.system(command) != 0) |
|
617 |
tries += 1 |
|
618 |
||
619 |
if looking: |
|
620 |
self.raptor.Error("Failed to start the log descrambler") |
|
621 |
self.descrambler_started = True |
|
622 |
return False |
|
623 |
||
624 |
self.descrambler_started = True |
|
625 |
self.descrambler += " " + buildID |
|
626 |
||
627 |
return True |
|
628 |
||
629 |
def StopDescrambler(self): |
|
630 |
if self.descrambler_started: |
|
631 |
command = self.descrambler + " stop" |
|
632 |
self.descrambler = "" |
|
633 |
||
634 |
self.raptor.Info("Running %s", command) |
|
635 |
if os.system(command) != 0: |
|
636 |
self.raptor.Error("Failed in %s", command) |
|
637 |
return False |
|
638 |
return True |
|
639 |
||
640 |
# raptor_make module functions |
|
641 |
||
642 |
||
643 |
# end of the raptor_make module |