author | timothy.murphy@nokia.com |
Mon, 18 Jan 2010 16:15:37 +0000 | |
branch | wip |
changeset 129 | ab4f8683701c |
parent 122 | 816955f04aaa |
child 130 | 4f2ae0d78608 |
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: |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
422 |
if o.find(";") != -1: |
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 |
elif o.find("\\") != -1: |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
425 |
command += " " + o.replace("\\","\\\\") |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
426 |
else: |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
427 |
command += " " + o |
3 | 428 |
|
429 |
# Switch off dependency file including? |
|
430 |
if self.raptor.noDependInclude: |
|
431 |
command += " NO_DEPEND_INCLUDE=1" |
|
432 |
||
433 |
if self.usetalon: |
|
434 |
# use the descrambler if we set it up |
|
435 |
command += ' TALON_DESCRAMBLE=' |
|
436 |
if self.scrambled: |
|
437 |
command += '1 ' |
|
438 |
else: |
|
439 |
command += '0 ' |
|
440 |
else: |
|
441 |
if self.descrambler_started: |
|
442 |
command += ' DESCRAMBLE="' + self.descrambler + '"' |
|
443 |
||
444 |
# use the retry mechanism if requested |
|
445 |
if self.raptor.tries > 1: |
|
446 |
command += ' RECIPETRIES=' + str(self.raptor.tries) |
|
447 |
command += ' TALON_RETRIES=' + str(self.raptor.tries - 1) |
|
448 |
||
449 |
# targets go at the end, if the makefile supports them |
|
450 |
addTargets = self.raptor.targets[:] |
|
5 | 451 |
ignoreTargets = makefileset.ignoreTargets(makefile) |
3 | 452 |
if addTargets and ignoreTargets: |
453 |
for target in self.raptor.targets: |
|
454 |
if re.match(ignoreTargets, target): |
|
455 |
addTargets.remove(target) |
|
456 |
||
457 |
if addTargets: |
|
458 |
command += " " + " ".join(addTargets) |
|
459 |
||
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
460 |
# Send stderr to a file so that it can't mess up the log (e.g. |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
461 |
# clock skew messages from some build engines. |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
462 |
stderrfilename = makefile+'.stderr' |
122
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
463 |
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
|
464 |
|
5 | 465 |
# Substitute the makefile name for any occurrence of #MAKEFILE# |
466 |
command = command.replace("#MAKEFILE#", str(makefile)) |
|
467 |
||
3 | 468 |
self.raptor.Info("Executing '%s'", command) |
469 |
||
470 |
# execute the build. |
|
471 |
# the actual call differs between Windows and Unix. |
|
472 |
# bufsize=1 means "line buffered" |
|
473 |
# |
|
474 |
try: |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
475 |
# Time the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
476 |
self.raptor.InfoStartTime(object_type = "makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
477 |
task = "build", key = str(makefile)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
478 |
|
3 | 479 |
makeenv=os.environ.copy() |
480 |
if self.usetalon: |
|
481 |
makeenv['TALON_RECIPEATTRIBUTES']="none" |
|
482 |
makeenv['TALON_SHELL']=self.talonshell |
|
483 |
makeenv['TALON_BUILDID']=str(self.buildID) |
|
484 |
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
|
485 |
|
3 | 486 |
if self.raptor.filesystem == "unix": |
118 | 487 |
p = subprocess.Popen([command], bufsize=65535, |
488 |
stdout=subprocess.PIPE, |
|
489 |
stderr=subprocess.STDOUT, |
|
490 |
close_fds=True, env=makeenv, shell=True) |
|
3 | 491 |
else: |
118 | 492 |
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
|
493 |
[raptor_data.ToolSet.shell, '-c', command], |
118 | 494 |
bufsize=65535, |
495 |
stdout=subprocess.PIPE, |
|
496 |
stderr=subprocess.STDOUT, |
|
497 |
shell = False, |
|
498 |
universal_newlines=True, env=makeenv) |
|
3 | 499 |
stream = p.stdout |
500 |
||
501 |
||
502 |
line = " " |
|
503 |
while line: |
|
504 |
line = stream.readline() |
|
505 |
self.raptor.out.write(line) |
|
506 |
||
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
507 |
try: |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
508 |
e = open(stderrfilename,"r") |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
509 |
for line in e: |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
510 |
self.raptor.out.write(escape(line)) |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
511 |
e.close() |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
512 |
except Exception,e: |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
513 |
self.raptor.Error("Couldn't complete stderr output for %s - '%s'", str(e), command) |
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
514 |
|
3 | 515 |
# should be done now |
516 |
returncode = p.wait() |
|
517 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
518 |
# Report end-time of the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
519 |
self.raptor.InfoEndTime(object_type = "makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
520 |
task = "build", key = str(makefile)) |
3 | 521 |
|
522 |
if returncode != 0 and not self.raptor.keepGoing: |
|
523 |
self.Tidy() |
|
524 |
return False |
|
525 |
||
526 |
except Exception,e: |
|
527 |
self.raptor.Error("Exception '%s' during '%s'", str(e), command) |
|
528 |
self.Tidy() |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
529 |
# Still report end-time of the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
530 |
self.raptor.InfoEnd(object_type = "Building", task = "Makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
531 |
key = str(makefile)) |
3 | 532 |
return False |
533 |
||
534 |
# run any shutdown script |
|
535 |
if self.shutdownCommand != None and self.shutdownCommand != "": |
|
536 |
self.raptor.Info("Running %s", self.shutdownCommand) |
|
537 |
if os.system(self.shutdownCommand) != 0: |
|
538 |
self.raptor.Error("Failed in %s", self.shutdownCommand) |
|
539 |
self.Tidy() |
|
540 |
return False |
|
541 |
||
542 |
self.Tidy() |
|
543 |
return True |
|
544 |
||
545 |
def Tidy(self): |
|
546 |
if self.usetalon: |
|
547 |
self.StopTalon() |
|
548 |
else: |
|
549 |
"clean up after the make command" |
|
550 |
self.StopDescrambler() |
|
551 |
||
552 |
def StartTalon(self): |
|
553 |
# the talon command |
|
554 |
beginning = raptor.hostplatform_dir + "/bin" |
|
555 |
if "win" in raptor.hostplatform: |
|
556 |
end = ".exe" |
|
557 |
else: |
|
558 |
end = "" |
|
559 |
||
560 |
self.talonctl = str(self.raptor.home.Append(beginning, "talonctl"+end)) |
|
561 |
||
562 |
# generate a unique build number |
|
563 |
random.seed() |
|
564 |
looking = True |
|
565 |
tries = 0 |
|
566 |
while looking and tries < 100: |
|
567 |
self.buildID = raptor.name + str(random.getrandbits(32)) |
|
568 |
||
569 |
command = self.talonctl + " start" |
|
570 |
||
571 |
os.environ["TALON_BUILDID"] = self.buildID |
|
572 |
self.raptor.Info("Running %s", command) |
|
573 |
looking = (os.system(command) != 0) |
|
574 |
tries += 1 |
|
575 |
if looking: |
|
5 | 576 |
self.raptor.Error("Failed to initialise the talon shell for this build") |
3 | 577 |
self.talonctl = "" |
578 |
return False |
|
579 |
||
580 |
return True |
|
581 |
||
582 |
def StopTalon(self): |
|
583 |
if self.talonctl: |
|
584 |
command = self.talonctl + " stop" |
|
585 |
self.talonctl = "" |
|
586 |
||
587 |
self.raptor.Info("Running %s", command) |
|
588 |
if os.system(command) != 0: |
|
589 |
self.raptor.Error("Failed in %s", command) |
|
590 |
return False |
|
591 |
||
592 |
return True |
|
593 |
||
594 |
def StartDescrambler(self): |
|
595 |
# the descrambler command |
|
596 |
beginning = raptor.hostplatform_dir + "/bin" |
|
597 |
if "win" in raptor.hostplatform: |
|
598 |
end = ".exe" |
|
599 |
else: |
|
600 |
end = "" |
|
601 |
||
602 |
self.descrambler = str(self.raptor.home.Append(beginning, "sbs_descramble"+end)) |
|
603 |
||
604 |
# generate a unique build number |
|
605 |
random.seed() |
|
606 |
looking = True |
|
607 |
tries = 0 |
|
608 |
while looking and tries < 100: |
|
609 |
buildID = raptor.name + str(random.getrandbits(32)) |
|
610 |
||
611 |
command = self.descrambler + " " + buildID + " start" |
|
612 |
self.raptor.Info("Running %s", command) |
|
613 |
looking = (os.system(command) != 0) |
|
614 |
tries += 1 |
|
615 |
||
616 |
if looking: |
|
617 |
self.raptor.Error("Failed to start the log descrambler") |
|
618 |
self.descrambler_started = True |
|
619 |
return False |
|
620 |
||
621 |
self.descrambler_started = True |
|
622 |
self.descrambler += " " + buildID |
|
623 |
||
624 |
return True |
|
625 |
||
626 |
def StopDescrambler(self): |
|
627 |
if self.descrambler_started: |
|
628 |
command = self.descrambler + " stop" |
|
629 |
self.descrambler = "" |
|
630 |
||
631 |
self.raptor.Info("Running %s", command) |
|
632 |
if os.system(command) != 0: |
|
633 |
self.raptor.Error("Failed in %s", command) |
|
634 |
return False |
|
635 |
return True |
|
636 |
||
637 |
# raptor_make module functions |
|
638 |
||
639 |
||
640 |
# end of the raptor_make module |