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