18 |
18 |
19 import hashlib |
19 import hashlib |
20 import os |
20 import os |
21 import random |
21 import random |
22 import raptor |
22 import raptor |
23 import raptor_data |
|
24 import raptor_utilities |
23 import raptor_utilities |
25 import raptor_version |
24 import raptor_version |
|
25 import raptor_data |
26 import re |
26 import re |
27 import subprocess |
27 import subprocess |
28 import time |
28 import time |
29 from raptor_makefile import * |
29 from raptor_makefile import * |
|
30 import raptor_version |
|
31 import traceback |
|
32 import sys |
30 |
33 |
31 # raptor_make module classes |
34 # raptor_make module classes |
32 |
35 |
33 class MakeEngine(object): |
36 class MakeEngine(object): |
34 |
37 |
35 def __init__(self, Raptor): |
38 def __init__(self, Raptor): |
36 self.raptor = Raptor |
39 self.raptor = Raptor |
37 self.valid = True |
40 self.valid = True |
38 self.makefileset = None |
|
39 self.descrambler = None |
41 self.descrambler = None |
40 self.descrambler_started = False |
42 self.descrambler_started = False |
41 |
43 |
42 engine = Raptor.makeEngine |
44 engine = Raptor.makeEngine |
43 |
45 |
51 Raptor.Error("No settings found for build engine '%s'", engine) |
53 Raptor.Error("No settings found for build engine '%s'", engine) |
52 return |
54 return |
53 |
55 |
54 # find the variant and extract the values |
56 # find the variant and extract the values |
55 try: |
57 try: |
56 units = avar.GenerateBuildUnits() |
58 units = avar.GenerateBuildUnits(Raptor.cache) |
57 evaluator = Raptor.GetEvaluator( None, units[0] , gathertools=True) |
59 evaluator = Raptor.GetEvaluator( None, units[0] , gathertools=True) |
58 |
60 |
59 # shell |
61 # shell |
60 self.shellpath = evaluator.Get("DEFAULT_SHELL") |
62 self.shellpath = evaluator.Get("DEFAULT_SHELL") |
61 usetalon_s = evaluator.Get("USE_TALON") |
63 usetalon_s = evaluator.Get("USE_TALON") |
121 host='$$HOSTNAME'\ |
123 host='$$HOSTNAME'\ |
122 layer='$$COMPONENT_LAYER'\ |
124 layer='$$COMPONENT_LAYER'\ |
123 component='$$COMPONENT_NAME'\ |
125 component='$$COMPONENT_NAME'\ |
124 bldinf='$$COMPONENT_META' mmp='$$PROJECT_META'\ |
126 bldinf='$$COMPONENT_META' mmp='$$PROJECT_META'\ |
125 config='$$SBS_CONFIGURATION' platform='$$PLATFORM'\ |
127 config='$$SBS_CONFIGURATION' platform='$$PLATFORM'\ |
126 phase='$$MAKEFILE_GROUP' source='$$SOURCE |
128 phase='$$MAKEFILE_GROUP' source='$$SOURCE' |
127 export TALON_RECIPEATTRIBUTES TALON_SHELL TALON_TIMEOUT |
129 export TALON_RECIPEATTRIBUTES TALON_SHELL TALON_TIMEOUT |
128 USE_TALON:=%s |
130 USE_TALON:=%s |
129 |
131 |
130 """ % (self.talonshell, self.talontimeout, "1") |
132 """ % (self.talonshell, self.talontimeout, "1") |
131 else: |
133 else: |
146 |
148 |
147 %s |
149 %s |
148 |
150 |
149 include %s |
151 include %s |
150 |
152 |
151 """ % ( raptor.name, raptor_version.Version(), |
153 """ % ( raptor.name, raptor_version.fullversion(), |
152 " ".join(raptor.hostplatform), |
154 " ".join(raptor.hostplatform), |
153 raptor.hostplatform_dir, |
155 raptor.hostplatform_dir, |
154 self.raptor.filesystem, |
156 self.raptor.filesystem, |
155 str(self.raptor.systemFLM), |
157 str(self.raptor.systemFLM), |
156 self.shellpath, |
158 self.shellpath, |
166 |
168 |
167 def Write(self, toplevel, specs, configs): |
169 def Write(self, toplevel, specs, configs): |
168 """Generate a set of makefiles, or one big Makefile.""" |
170 """Generate a set of makefiles, or one big Makefile.""" |
169 |
171 |
170 if not self.valid: |
172 if not self.valid: |
171 return |
173 return None |
|
174 |
|
175 self.raptor.Debug("Writing Makefile '%s'" % (str(toplevel))) |
172 |
176 |
173 self.toplevel = toplevel |
177 self.toplevel = toplevel |
174 |
178 |
175 # create the top-level makefiles |
179 # create the top-level makefiles |
|
180 makefileset = None |
176 |
181 |
177 try: |
182 try: |
178 self.makefileset = MakefileSet(directory = str(toplevel.Dir()), |
183 makefileset = MakefileSet(directory = str(toplevel.Dir()), |
179 selectors = self.selectors, |
184 selectors = self.selectors, |
180 filenamebase = str(toplevel.File()), |
185 filenamebase = str(toplevel.File()), |
181 prologue = self.makefile_prologue, |
186 prologue = self.makefile_prologue, |
182 epilogue = self.makefile_epilogue, |
187 epilogue = self.makefile_epilogue, |
183 defaulttargets = self.defaultTargets) |
188 defaulttargets = self.defaultTargets) |
188 |
193 |
189 # are we writing one Makefile or lots? |
194 # are we writing one Makefile or lots? |
190 self.many = not self.raptor.writeSingleMakefile |
195 self.many = not self.raptor.writeSingleMakefile |
191 |
196 |
192 # add a makefile for each spec under each config |
197 # add a makefile for each spec under each config |
193 config_makefileset = self.makefileset |
198 config_makefileset = makefileset |
194 |
|
195 for c in configs: |
199 for c in configs: |
196 if self.many: |
200 if self.many: |
197 config_makefileset = self.makefileset.createChild(c.name) |
201 config_makefileset = makefileset.createChild(c.name) |
198 |
202 |
199 # make sure the config_wide spec item is put out first so that it |
203 # make sure the config_wide spec item is put out first so that it |
200 # can affect everything. |
204 # can affect everything. |
201 ordered_specs=[] |
205 ordered_specs=[] |
202 config_wide_spec = None |
206 config_wide_spec = None |
205 config_wide_spec = s |
209 config_wide_spec = s |
206 else: |
210 else: |
207 ordered_specs.append(s) |
211 ordered_specs.append(s) |
208 |
212 |
209 if config_wide_spec is not None: |
213 if config_wide_spec is not None: |
210 config_wide_spec.Configure(c) |
214 config_wide_spec.Configure(c, cache = self.raptor.cache) |
211 self.WriteConfiguredSpec(config_makefileset, config_wide_spec, c, True) |
215 self.WriteConfiguredSpec(config_makefileset, config_wide_spec, c, True) |
212 |
216 |
213 for s in ordered_specs: |
217 for s in ordered_specs: |
214 s.Configure(c) |
218 s.Configure(c, cache = self.raptor.cache) |
215 self.WriteConfiguredSpec(config_makefileset, s, c, False) |
219 self.WriteConfiguredSpec(config_makefileset, s, c, False) |
216 |
220 |
217 self.makefileset.close() |
221 makefileset.close() |
218 except Exception,e: |
222 except Exception,e: |
219 self.raptor.Error("Failed to write makefile '%s': %s" % (str(toplevel),str(e))) |
223 tb = traceback.format_exc() |
|
224 if not self.raptor.debugOutput: |
|
225 tb="" |
|
226 self.raptor.Error("Failed to write makefile '%s': %s : %s" % (str(toplevel),str(e),tb)) |
|
227 makefileset = None |
|
228 |
|
229 return makefileset |
220 |
230 |
221 |
231 |
222 def WriteConfiguredSpec(self, parentMakefileSet, spec, config, useAllInterfaces): |
232 def WriteConfiguredSpec(self, parentMakefileSet, spec, config, useAllInterfaces): |
223 # ignore this spec if it is empty |
233 # ignore this spec if it is empty |
224 hasInterface = spec.HasInterface() |
234 hasInterface = spec.HasInterface() |
231 dupe = True |
241 dupe = True |
232 iface = None |
242 iface = None |
233 guard = None |
243 guard = None |
234 if hasInterface: |
244 if hasInterface: |
235 # find the Interface (it may be a ref) |
245 # find the Interface (it may be a ref) |
236 iface = spec.GetInterface() |
246 try: |
237 |
247 iface = spec.GetInterface(self.raptor.cache) |
238 if iface == None: |
248 |
|
249 except raptor_data.MissingInterfaceError, e: |
239 self.raptor.Error("No interface for '%s'", spec.name) |
250 self.raptor.Error("No interface for '%s'", spec.name) |
240 return |
251 return |
241 |
252 |
242 if iface.abstract: |
253 if iface.abstract: |
243 self.raptor.Error("Abstract interface '%s' for '%s'", |
254 self.raptor.Error("Abstract interface '%s' for '%s'", |
266 |
277 |
267 parameters.append((k, value)) |
278 parameters.append((k, value)) |
268 md5hash.update(value) |
279 md5hash.update(value) |
269 |
280 |
270 # parameters required by the interface |
281 # parameters required by the interface |
271 for p in iface.GetParams(): |
282 for p in iface.GetParams(self.raptor.cache): |
272 val = evaluator.Resolve(p.name) |
283 val = evaluator.Resolve(p.name) |
273 addparam(p.name,val,p.default) |
284 addparam(p.name,val,p.default) |
274 |
285 |
275 # Use Patterns to fetch a group of parameters |
286 # Use Patterns to fetch a group of parameters |
276 for g in iface.GetParamGroups(): |
287 for g in iface.GetParamGroups(self.raptor.cache): |
277 for k,v in evaluator.ResolveMatching(g.patternre): |
288 for k,v in evaluator.ResolveMatching(g.patternre): |
278 addparam(k,v,g.default) |
289 addparam(k,v,g.default) |
279 |
290 |
280 hash = md5hash.hexdigest() |
291 hash = md5hash.hexdigest() |
281 dupe = hash in self.hashes |
292 dupe = hash in self.hashes |
299 else: |
310 else: |
300 guard = "guard_" + hash |
311 guard = "guard_" + hash |
301 |
312 |
302 # generate the call to the FLM |
313 # generate the call to the FLM |
303 if iface is not None: |
314 if iface is not None: |
304 makefileset.addCall(spec.name, config.name, iface.name, useAllInterfaces, iface.GetFLMIncludePath(), parameters, guard) |
315 makefileset.addCall(spec.name, config.name, iface.name, useAllInterfaces, iface.GetFLMIncludePath(self.raptor.cache), parameters, guard) |
305 |
316 |
306 # recursive includes |
317 # recursive includes |
307 |
318 |
308 for child in childSpecs: |
319 for child in childSpecs: |
309 self.WriteConfiguredSpec(makefileset, child, config, useAllInterfaces) |
320 self.WriteConfiguredSpec(makefileset, child, config, useAllInterfaces) |
339 self.raptor.Error("Failed in %s", self.initCommand) |
350 self.raptor.Error("Failed in %s", self.initCommand) |
340 self.Tidy() |
351 self.Tidy() |
341 return False |
352 return False |
342 |
353 |
343 # Save file names to a list, to allow the order to be reversed |
354 # Save file names to a list, to allow the order to be reversed |
344 fileName_list = list(self.makefileset.makefileNames()) |
355 fileName_list = list(makefileset.makefileNames()) |
345 |
356 |
346 # Iterate through args passed to raptor, searching for CLEAN or REALLYCLEAN |
357 # Iterate through args passed to raptor, searching for CLEAN or REALLYCLEAN |
347 clean_flag = False |
358 clean_flag = False |
348 for arg in self.raptor.args: |
359 for arg in self.raptor.args: |
349 clean_flag = ("CLEAN" in self.raptor.args) or \ |
360 clean_flag = ("CLEAN" in self.raptor.args) or \ |
399 command += ' RECIPETRIES=' + str(self.raptor.tries) |
410 command += ' RECIPETRIES=' + str(self.raptor.tries) |
400 command += ' TALON_RETRIES=' + str(self.raptor.tries - 1) |
411 command += ' TALON_RETRIES=' + str(self.raptor.tries - 1) |
401 |
412 |
402 # targets go at the end, if the makefile supports them |
413 # targets go at the end, if the makefile supports them |
403 addTargets = self.raptor.targets[:] |
414 addTargets = self.raptor.targets[:] |
404 ignoreTargets = self.makefileset.ignoreTargets(makefile) |
415 ignoreTargets = makefileset.ignoreTargets(makefile) |
405 if addTargets and ignoreTargets: |
416 if addTargets and ignoreTargets: |
406 for target in self.raptor.targets: |
417 for target in self.raptor.targets: |
407 if re.match(ignoreTargets, target): |
418 if re.match(ignoreTargets, target): |
408 addTargets.remove(target) |
419 addTargets.remove(target) |
409 |
420 |
410 if addTargets: |
421 if addTargets: |
411 command += " " + " ".join(addTargets) |
422 command += " " + " ".join(addTargets) |
|
423 |
|
424 # Substitute the makefile name for any occurrence of #MAKEFILE# |
|
425 command = command.replace("#MAKEFILE#", str(makefile)) |
412 |
426 |
413 self.raptor.Info("Executing '%s'", command) |
427 self.raptor.Info("Executing '%s'", command) |
414 |
428 |
415 # execute the build. |
429 # execute the build. |
416 # the actual call differs between Windows and Unix. |
430 # the actual call differs between Windows and Unix. |