author | Richard Taylor <richard.i.taylor@nokia.com> |
Wed, 17 Feb 2010 16:53:22 +0000 | |
branch | fix |
changeset 232 | 4b2787756a35 |
parent 226 | 59f343577f92 |
child 355 | 24d0baf736db |
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 |
||
224
c037b5dccbab
Ensure that a .DEFAULT target isn't used when --no-depend-include is in play.
Jon Chatten
parents:
220
diff
changeset
|
181 |
# Unless dependency processing has been eschewed via the CLI, use a .DEFAULT target to |
219 | 182 |
# trap missing dependencies (ignoring user config files that we know are usually absent) |
225
d401dbd3a410
Ensure that parallel parsing sbs calls pass on --no-depend-generate and --no-depend-include (as these influence makefile generation).
Jon Chatten
parents:
224
diff
changeset
|
183 |
if not (self.raptor.noDependGenerate or self.raptor.noDependInclude): |
219 | 184 |
self.makefile_prologue += """ |
225
d401dbd3a410
Ensure that parallel parsing sbs calls pass on --no-depend-generate and --no-depend-include (as these influence makefile generation).
Jon Chatten
parents:
224
diff
changeset
|
185 |
|
219 | 186 |
$(FLMHOME)/user/final.mk: |
187 |
$(FLMHOME)/user/default.flm: |
|
188 |
$(FLMHOME)/user/globals.mk: |
|
189 |
||
225
d401dbd3a410
Ensure that parallel parsing sbs calls pass on --no-depend-generate and --no-depend-include (as these influence makefile generation).
Jon Chatten
parents:
224
diff
changeset
|
190 |
.DEFAULT:: |
219 | 191 |
@echo "<warning>Missing dependency detected: $@</warning>" |
192 |
||
193 |
""" |
|
194 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
195 |
# Only output timings if requested on CLI |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
196 |
if self.raptor.timing: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
197 |
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
|
198 |
+ timing_start + "\n\n" |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
199 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
200 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
201 |
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
|
202 |
+ timing_end + "\n" |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
203 |
else: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
204 |
self.makefile_epilogue = "" |
3 | 205 |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
206 |
self.makefile_epilogue += """ |
3 | 207 |
|
208 |
include %s |
|
209 |
||
210 |
""" % (self.raptor.systemFLM.Append('final.mk') ) |
|
211 |
||
212 |
def Write(self, toplevel, specs, configs): |
|
213 |
"""Generate a set of makefiles, or one big Makefile.""" |
|
214 |
||
215 |
if not self.valid: |
|
5 | 216 |
return None |
217 |
||
218 |
self.raptor.Debug("Writing Makefile '%s'" % (str(toplevel))) |
|
3 | 219 |
|
220 |
self.toplevel = toplevel |
|
221 |
||
222 |
# create the top-level makefiles |
|
5 | 223 |
makefileset = None |
3 | 224 |
|
225 |
try: |
|
5 | 226 |
makefileset = MakefileSet(directory = str(toplevel.Dir()), |
3 | 227 |
selectors = self.selectors, |
228 |
filenamebase = str(toplevel.File()), |
|
229 |
prologue = self.makefile_prologue, |
|
230 |
epilogue = self.makefile_epilogue, |
|
231 |
defaulttargets = self.defaultTargets) |
|
232 |
||
233 |
# are we pruning duplicates? |
|
234 |
self.prune = self.raptor.pruneDuplicateMakefiles |
|
235 |
self.hashes = set() |
|
236 |
||
237 |
# are we writing one Makefile or lots? |
|
238 |
self.many = not self.raptor.writeSingleMakefile |
|
239 |
||
240 |
# add a makefile for each spec under each config |
|
5 | 241 |
config_makefileset = makefileset |
3 | 242 |
for c in configs: |
243 |
if self.many: |
|
5 | 244 |
config_makefileset = makefileset.createChild(c.name) |
3 | 245 |
|
246 |
# make sure the config_wide spec item is put out first so that it |
|
247 |
# can affect everything. |
|
248 |
ordered_specs=[] |
|
249 |
config_wide_spec = None |
|
250 |
for s in specs: |
|
251 |
if s.name == "config_wide": |
|
252 |
config_wide_spec = s |
|
253 |
else: |
|
254 |
ordered_specs.append(s) |
|
255 |
||
256 |
if config_wide_spec is not None: |
|
5 | 257 |
config_wide_spec.Configure(c, cache = self.raptor.cache) |
3 | 258 |
self.WriteConfiguredSpec(config_makefileset, config_wide_spec, c, True) |
259 |
||
260 |
for s in ordered_specs: |
|
5 | 261 |
s.Configure(c, cache = self.raptor.cache) |
3 | 262 |
self.WriteConfiguredSpec(config_makefileset, s, c, False) |
263 |
||
5 | 264 |
makefileset.close() |
3 | 265 |
except Exception,e: |
5 | 266 |
tb = traceback.format_exc() |
267 |
if not self.raptor.debugOutput: |
|
268 |
tb="" |
|
269 |
self.raptor.Error("Failed to write makefile '%s': %s : %s" % (str(toplevel),str(e),tb)) |
|
270 |
makefileset = None |
|
271 |
||
272 |
return makefileset |
|
3 | 273 |
|
274 |
||
275 |
def WriteConfiguredSpec(self, parentMakefileSet, spec, config, useAllInterfaces): |
|
276 |
# ignore this spec if it is empty |
|
277 |
hasInterface = spec.HasInterface() |
|
278 |
childSpecs = spec.GetChildSpecs() |
|
279 |
||
280 |
if not hasInterface and not childSpecs: |
|
281 |
return |
|
282 |
||
283 |
parameters = [] |
|
284 |
dupe = True |
|
285 |
iface = None |
|
286 |
guard = None |
|
287 |
if hasInterface: |
|
288 |
# find the Interface (it may be a ref) |
|
5 | 289 |
try: |
290 |
iface = spec.GetInterface(self.raptor.cache) |
|
3 | 291 |
|
5 | 292 |
except raptor_data.MissingInterfaceError, e: |
3 | 293 |
self.raptor.Error("No interface for '%s'", spec.name) |
294 |
return |
|
295 |
||
296 |
if iface.abstract: |
|
297 |
self.raptor.Error("Abstract interface '%s' for '%s'", |
|
298 |
iface.name, spec.name) |
|
299 |
return |
|
300 |
||
301 |
# we need to guard the FLM call with a hash based on all the |
|
302 |
# parameter values so that duplicate calls cannot be made. |
|
303 |
# So we need to find all the values before we can write |
|
304 |
# anything out. |
|
305 |
md5hash = hashlib.md5() |
|
306 |
md5hash.update(iface.name) |
|
307 |
||
308 |
# we need an Evaluator to get parameter values for this |
|
309 |
# Specification in the context of this Configuration |
|
310 |
evaluator = self.raptor.GetEvaluator(spec, config) |
|
311 |
||
312 |
def addparam(k, value, default): |
|
313 |
if value == None: |
|
314 |
if p.default != None: |
|
315 |
value = p.default |
|
316 |
else: |
|
317 |
self.raptor.Error("%s undefined for '%s'", |
|
318 |
k, spec.name) |
|
319 |
value = "" |
|
320 |
||
321 |
parameters.append((k, value)) |
|
322 |
md5hash.update(value) |
|
323 |
||
324 |
# parameters required by the interface |
|
5 | 325 |
for p in iface.GetParams(self.raptor.cache): |
3 | 326 |
val = evaluator.Resolve(p.name) |
327 |
addparam(p.name,val,p.default) |
|
328 |
||
329 |
# Use Patterns to fetch a group of parameters |
|
5 | 330 |
for g in iface.GetParamGroups(self.raptor.cache): |
3 | 331 |
for k,v in evaluator.ResolveMatching(g.patternre): |
332 |
addparam(k,v,g.default) |
|
333 |
||
334 |
hash = md5hash.hexdigest() |
|
335 |
dupe = hash in self.hashes |
|
336 |
||
337 |
self.hashes.add(hash) |
|
338 |
||
339 |
# we only create a Makefile if we have a new FLM call to contribute, |
|
340 |
# OR we are not pruning duplicates (guarding instead) |
|
341 |
# OR we have some child specs that need something to include them. |
|
342 |
if dupe and self.prune and not childSpecs: |
|
343 |
return |
|
344 |
||
345 |
makefileset = parentMakefileSet |
|
346 |
# Create a new layer of makefiles? |
|
347 |
if self.many: |
|
348 |
makefileset = makefileset.createChild(spec.name) |
|
349 |
||
350 |
if not (self.prune and dupe): |
|
351 |
if self.prune: |
|
352 |
guard = "" |
|
353 |
else: |
|
354 |
guard = "guard_" + hash |
|
355 |
||
356 |
# generate the call to the FLM |
|
357 |
if iface is not None: |
|
5 | 358 |
makefileset.addCall(spec.name, config.name, iface.name, useAllInterfaces, iface.GetFLMIncludePath(self.raptor.cache), parameters, guard) |
3 | 359 |
|
360 |
# recursive includes |
|
361 |
||
362 |
for child in childSpecs: |
|
363 |
self.WriteConfiguredSpec(makefileset, child, config, useAllInterfaces) |
|
364 |
||
365 |
if self.many: |
|
366 |
makefileset.close() # close child set of makefiles as we'll never see them again. |
|
367 |
||
368 |
def Make(self, makefileset): |
|
369 |
"run the make command" |
|
370 |
||
371 |
if not self.valid: |
|
372 |
return False |
|
373 |
||
374 |
if self.usetalon: |
|
375 |
# Always use Talon since it does the XML not |
|
376 |
# just descrambling |
|
377 |
if not self.StartTalon() and not self.raptor.keepGoing: |
|
378 |
self.Tidy() |
|
379 |
return False |
|
380 |
else: |
|
381 |
# use the descrambler if we are doing a parallel build on |
|
382 |
# a make engine which does not buffer each agent's output |
|
383 |
if self.raptor.jobs > 1 and self.scrambled: |
|
384 |
self.StartDescrambler() |
|
385 |
if not self.descrambler_started and not self.raptor.keepGoing: |
|
386 |
self.Tidy() |
|
387 |
return False |
|
388 |
||
389 |
# run any initialisation script |
|
390 |
if self.initCommand: |
|
391 |
self.raptor.Info("Running %s", self.initCommand) |
|
392 |
if os.system(self.initCommand) != 0: |
|
393 |
self.raptor.Error("Failed in %s", self.initCommand) |
|
394 |
self.Tidy() |
|
395 |
return False |
|
396 |
||
397 |
# Save file names to a list, to allow the order to be reversed |
|
5 | 398 |
fileName_list = list(makefileset.makefileNames()) |
3 | 399 |
|
400 |
# Iterate through args passed to raptor, searching for CLEAN or REALLYCLEAN |
|
401 |
clean_flag = False |
|
402 |
for arg in self.raptor.args: |
|
403 |
clean_flag = ("CLEAN" in self.raptor.args) or \ |
|
404 |
("REALLYCLEAN" in self.raptor.args) |
|
405 |
||
406 |
# Files should be deleted in the opposite order to the order |
|
407 |
# they were built. So reverse file order if cleaning |
|
408 |
if clean_flag: |
|
409 |
fileName_list.reverse() |
|
410 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
411 |
# Report number of makefiles to be built |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
412 |
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
|
413 |
|
3 | 414 |
# Process each file in turn |
415 |
for makefile in fileName_list: |
|
416 |
if not os.path.exists(makefile): |
|
417 |
self.raptor.Info("Skipping makefile %s", makefile) |
|
418 |
continue |
|
419 |
self.raptor.Info("Making %s", makefile) |
|
420 |
# assemble the build command line |
|
421 |
command = self.buildCommand |
|
422 |
||
423 |
if self.makefileOption: |
|
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
424 |
command += " " + self.makefileOption + " " + ' "' + str(makefile) + '" ' |
3 | 425 |
|
426 |
if self.raptor.keepGoing and self.keepGoingOption: |
|
427 |
command += " " + self.keepGoingOption |
|
428 |
||
429 |
if self.raptor.jobs > 1 and self.jobsOption: |
|
430 |
command += " " + self.jobsOption +" "+ str(self.raptor.jobs) |
|
431 |
||
432 |
# Set default options first so that they can be overridden by |
|
433 |
# ones set by the --mo option on the raptor commandline: |
|
434 |
command += " " + self.defaultMakeOptions |
|
435 |
# Can supply options on the commandline to override default settings. |
|
436 |
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
|
437 |
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
|
438 |
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
|
439 |
command += " " + "'" + o + "'" |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
440 |
else: |
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
441 |
command += " " + o |
3 | 442 |
|
443 |
# Switch off dependency file including? |
|
220
f7d68ecb923e
Add support for NO_DEPEND_GENERATE to makefile calls and respond accordingly in FLMs.
Jon Chatten
parents:
219
diff
changeset
|
444 |
if self.raptor.noDependInclude or self.raptor.noDependGenerate: |
3 | 445 |
command += " NO_DEPEND_INCLUDE=1" |
446 |
||
220
f7d68ecb923e
Add support for NO_DEPEND_GENERATE to makefile calls and respond accordingly in FLMs.
Jon Chatten
parents:
219
diff
changeset
|
447 |
# Switch off dependency file generation (and, implicitly, inclusion)? |
f7d68ecb923e
Add support for NO_DEPEND_GENERATE to makefile calls and respond accordingly in FLMs.
Jon Chatten
parents:
219
diff
changeset
|
448 |
if self.raptor.noDependGenerate: |
f7d68ecb923e
Add support for NO_DEPEND_GENERATE to makefile calls and respond accordingly in FLMs.
Jon Chatten
parents:
219
diff
changeset
|
449 |
command += " NO_DEPEND_GENERATE=1" |
f7d68ecb923e
Add support for NO_DEPEND_GENERATE to makefile calls and respond accordingly in FLMs.
Jon Chatten
parents:
219
diff
changeset
|
450 |
|
3 | 451 |
if self.usetalon: |
452 |
# use the descrambler if we set it up |
|
453 |
command += ' TALON_DESCRAMBLE=' |
|
454 |
if self.scrambled: |
|
455 |
command += '1 ' |
|
456 |
else: |
|
457 |
command += '0 ' |
|
458 |
else: |
|
459 |
if self.descrambler_started: |
|
460 |
command += ' DESCRAMBLE="' + self.descrambler + '"' |
|
461 |
||
462 |
# use the retry mechanism if requested |
|
463 |
if self.raptor.tries > 1: |
|
464 |
command += ' RECIPETRIES=' + str(self.raptor.tries) |
|
465 |
command += ' TALON_RETRIES=' + str(self.raptor.tries - 1) |
|
466 |
||
467 |
# targets go at the end, if the makefile supports them |
|
468 |
addTargets = self.raptor.targets[:] |
|
5 | 469 |
ignoreTargets = makefileset.ignoreTargets(makefile) |
3 | 470 |
if addTargets and ignoreTargets: |
471 |
for target in self.raptor.targets: |
|
472 |
if re.match(ignoreTargets, target): |
|
473 |
addTargets.remove(target) |
|
474 |
||
475 |
if addTargets: |
|
476 |
command += " " + " ".join(addTargets) |
|
477 |
||
121
5e5ae3e212b3
Stderr to a file - avoid xml problems in error messages.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
118
diff
changeset
|
478 |
# 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
|
479 |
# 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
|
480 |
# 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
|
481 |
stderrfilename = makefile+'.stderr' |
122
816955f04aaa
Protect some parameters from bash, e.g. ";" and "\"
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
121
diff
changeset
|
482 |
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
|
483 |
|
5 | 484 |
# Substitute the makefile name for any occurrence of #MAKEFILE# |
485 |
command = command.replace("#MAKEFILE#", str(makefile)) |
|
486 |
||
3 | 487 |
self.raptor.Info("Executing '%s'", command) |
488 |
||
489 |
# execute the build. |
|
490 |
# the actual call differs between Windows and Unix. |
|
491 |
# bufsize=1 means "line buffered" |
|
492 |
# |
|
493 |
try: |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
494 |
# Time the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
495 |
self.raptor.InfoStartTime(object_type = "makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
496 |
task = "build", key = str(makefile)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
497 |
|
3 | 498 |
makeenv=os.environ.copy() |
499 |
if self.usetalon: |
|
500 |
makeenv['TALON_RECIPEATTRIBUTES']="none" |
|
501 |
makeenv['TALON_SHELL']=self.talonshell |
|
502 |
makeenv['TALON_BUILDID']=str(self.buildID) |
|
503 |
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
|
504 |
|
3 | 505 |
if self.raptor.filesystem == "unix": |
118 | 506 |
p = subprocess.Popen([command], bufsize=65535, |
507 |
stdout=subprocess.PIPE, |
|
508 |
stderr=subprocess.STDOUT, |
|
509 |
close_fds=True, env=makeenv, shell=True) |
|
3 | 510 |
else: |
118 | 511 |
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
|
512 |
[raptor_data.ToolSet.shell, '-c', command], |
118 | 513 |
bufsize=65535, |
514 |
stdout=subprocess.PIPE, |
|
515 |
stderr=subprocess.STDOUT, |
|
516 |
shell = False, |
|
517 |
universal_newlines=True, env=makeenv) |
|
3 | 518 |
stream = p.stdout |
519 |
||
176
b601167a8189
sf bug 1519: unescaped entities in XML logs (from make errors)
Richard Taylor <richard.i.taylor@nokia.com>
parents:
134
diff
changeset
|
520 |
inRecipe = False |
3 | 521 |
line = " " |
522 |
while line: |
|
523 |
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
|
524 |
|
b601167a8189
sf bug 1519: unescaped entities in XML logs (from make errors)
Richard Taylor <richard.i.taylor@nokia.com>
parents:
134
diff
changeset
|
525 |
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
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
|
b601167a8189
sf bug 1519: unescaped entities in XML logs (from make errors)
Richard Taylor <richard.i.taylor@nokia.com>
parents:
134
diff
changeset
|
530 |
# 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
|
531 |
# 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
|
532 |
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
|
533 |
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
|
534 |
else: |
b601167a8189
sf bug 1519: unescaped entities in XML logs (from make errors)
Richard Taylor <richard.i.taylor@nokia.com>
parents:
134
diff
changeset
|
535 |
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
|
536 |
|
3 | 537 |
# should be done now |
538 |
returncode = p.wait() |
|
539 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
540 |
# Report end-time of the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
541 |
self.raptor.InfoEndTime(object_type = "makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
542 |
task = "build", key = str(makefile)) |
3 | 543 |
|
130
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
544 |
# 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
|
545 |
# 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
|
546 |
# xml parsers. |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
547 |
try: |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
548 |
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
|
549 |
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
|
550 |
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
|
551 |
e.close() |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
552 |
except Exception,e: |
4f2ae0d78608
fix: add .stderr dumfile to log *after* make engine has exited.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
122
diff
changeset
|
553 |
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
|
554 |
|
3 | 555 |
if returncode != 0 and not self.raptor.keepGoing: |
556 |
self.Tidy() |
|
557 |
return False |
|
558 |
||
559 |
except Exception,e: |
|
560 |
self.raptor.Error("Exception '%s' during '%s'", str(e), command) |
|
561 |
self.Tidy() |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
562 |
# Still report end-time of the build |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
563 |
self.raptor.InfoEnd(object_type = "Building", task = "Makefile", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
5
diff
changeset
|
564 |
key = str(makefile)) |
3 | 565 |
return False |
566 |
||
567 |
# run any shutdown script |
|
568 |
if self.shutdownCommand != None and self.shutdownCommand != "": |
|
569 |
self.raptor.Info("Running %s", self.shutdownCommand) |
|
570 |
if os.system(self.shutdownCommand) != 0: |
|
571 |
self.raptor.Error("Failed in %s", self.shutdownCommand) |
|
572 |
self.Tidy() |
|
573 |
return False |
|
574 |
||
575 |
self.Tidy() |
|
576 |
return True |
|
577 |
||
578 |
def Tidy(self): |
|
579 |
if self.usetalon: |
|
580 |
self.StopTalon() |
|
581 |
else: |
|
582 |
"clean up after the make command" |
|
583 |
self.StopDescrambler() |
|
584 |
||
585 |
def StartTalon(self): |
|
586 |
# the talon command |
|
587 |
beginning = raptor.hostplatform_dir + "/bin" |
|
588 |
if "win" in raptor.hostplatform: |
|
589 |
end = ".exe" |
|
590 |
else: |
|
591 |
end = "" |
|
592 |
||
593 |
self.talonctl = str(self.raptor.home.Append(beginning, "talonctl"+end)) |
|
594 |
||
595 |
# generate a unique build number |
|
596 |
random.seed() |
|
597 |
looking = True |
|
598 |
tries = 0 |
|
599 |
while looking and tries < 100: |
|
600 |
self.buildID = raptor.name + str(random.getrandbits(32)) |
|
601 |
||
602 |
command = self.talonctl + " start" |
|
603 |
||
604 |
os.environ["TALON_BUILDID"] = self.buildID |
|
605 |
self.raptor.Info("Running %s", command) |
|
606 |
looking = (os.system(command) != 0) |
|
607 |
tries += 1 |
|
608 |
if looking: |
|
5 | 609 |
self.raptor.Error("Failed to initialise the talon shell for this build") |
3 | 610 |
self.talonctl = "" |
611 |
return False |
|
612 |
||
613 |
return True |
|
614 |
||
615 |
def StopTalon(self): |
|
616 |
if self.talonctl: |
|
617 |
command = self.talonctl + " stop" |
|
618 |
self.talonctl = "" |
|
619 |
||
620 |
self.raptor.Info("Running %s", command) |
|
621 |
if os.system(command) != 0: |
|
622 |
self.raptor.Error("Failed in %s", command) |
|
623 |
return False |
|
624 |
||
625 |
return True |
|
626 |
||
627 |
def StartDescrambler(self): |
|
628 |
# the descrambler command |
|
629 |
beginning = raptor.hostplatform_dir + "/bin" |
|
630 |
if "win" in raptor.hostplatform: |
|
631 |
end = ".exe" |
|
632 |
else: |
|
633 |
end = "" |
|
634 |
||
635 |
self.descrambler = str(self.raptor.home.Append(beginning, "sbs_descramble"+end)) |
|
636 |
||
637 |
# generate a unique build number |
|
638 |
random.seed() |
|
639 |
looking = True |
|
640 |
tries = 0 |
|
641 |
while looking and tries < 100: |
|
642 |
buildID = raptor.name + str(random.getrandbits(32)) |
|
643 |
||
644 |
command = self.descrambler + " " + buildID + " start" |
|
645 |
self.raptor.Info("Running %s", command) |
|
646 |
looking = (os.system(command) != 0) |
|
647 |
tries += 1 |
|
648 |
||
649 |
if looking: |
|
650 |
self.raptor.Error("Failed to start the log descrambler") |
|
651 |
self.descrambler_started = True |
|
652 |
return False |
|
653 |
||
654 |
self.descrambler_started = True |
|
655 |
self.descrambler += " " + buildID |
|
656 |
||
657 |
return True |
|
658 |
||
659 |
def StopDescrambler(self): |
|
660 |
if self.descrambler_started: |
|
661 |
command = self.descrambler + " stop" |
|
662 |
self.descrambler = "" |
|
663 |
||
664 |
self.raptor.Info("Running %s", command) |
|
665 |
if os.system(command) != 0: |
|
666 |
self.raptor.Error("Failed in %s", command) |
|
667 |
return False |
|
668 |
return True |
|
669 |
||
670 |
# raptor_make module functions |
|
671 |
||
672 |
||
673 |
# end of the raptor_make module |