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