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: |
132 talon_settings=""" |
134 talon_settings=""" |
133 USE_TALON:= |
135 USE_TALON:= |
134 |
136 |
135 """ |
137 """ |
136 |
138 |
|
139 |
|
140 timing_start = "$(info " + \ |
|
141 raptor_timing.Timing.custom_string(tag = "start", |
|
142 object_type = "makefile", task = "parse", |
|
143 key = "$(THIS_FILENAME)", |
|
144 time="$(shell date +%s.%N)").rstrip("\n") + ")" |
|
145 |
|
146 timing_end = "$(info " + \ |
|
147 raptor_timing.Timing.custom_string(tag = "end", |
|
148 object_type = "makefile", task = "parse", |
|
149 key = "$(THIS_FILENAME)", |
|
150 time="$(shell date +%s.%N)").rstrip("\n") + ")" |
|
151 |
137 |
152 |
138 self.makefile_prologue = """ |
153 self.makefile_prologue = """ |
|
154 |
139 # generated by %s %s |
155 # generated by %s %s |
140 |
156 |
141 HOSTPLATFORM:=%s |
157 HOSTPLATFORM:=%s |
142 HOSTPLATFORM_DIR:=%s |
158 HOSTPLATFORM_DIR:=%s |
143 OSTYPE:=%s |
159 OSTYPE:=%s |
144 FLMHOME:=%s |
160 FLMHOME:=%s |
145 SHELL:=%s |
161 SHELL:=%s |
|
162 THIS_FILENAME:=$(firstword $(MAKEFILE_LIST)) |
146 |
163 |
147 %s |
164 %s |
148 |
165 |
149 include %s |
166 include %s |
150 |
167 |
151 """ % ( raptor.name, raptor_version.Version(), |
168 """ % ( raptor.name, raptor_version.fullversion(), |
152 " ".join(raptor.hostplatform), |
169 " ".join(raptor.hostplatform), |
153 raptor.hostplatform_dir, |
170 raptor.hostplatform_dir, |
154 self.raptor.filesystem, |
171 self.raptor.filesystem, |
155 str(self.raptor.systemFLM), |
172 str(self.raptor.systemFLM), |
156 self.shellpath, |
173 self.shellpath, |
157 talon_settings, |
174 talon_settings, |
158 self.raptor.systemFLM.Append('globals.mk') ) |
175 self.raptor.systemFLM.Append('globals.mk') ) |
159 |
176 |
160 |
177 # Only output timings if requested on CLI |
161 self.makefile_epilogue = """ |
178 if self.raptor.timing: |
|
179 self.makefile_prologue += "\n# Print Start-time of Makefile parsing\n" \ |
|
180 + timing_start + "\n\n" |
|
181 |
|
182 |
|
183 self.makefile_epilogue = "\n\n# Print End-time of Makefile parsing\n" \ |
|
184 + timing_end + "\n" |
|
185 else: |
|
186 self.makefile_epilogue = "" |
|
187 |
|
188 self.makefile_epilogue += """ |
162 |
189 |
163 include %s |
190 include %s |
164 |
191 |
165 """ % (self.raptor.systemFLM.Append('final.mk') ) |
192 """ % (self.raptor.systemFLM.Append('final.mk') ) |
166 |
193 |
167 def Write(self, toplevel, specs, configs): |
194 def Write(self, toplevel, specs, configs): |
168 """Generate a set of makefiles, or one big Makefile.""" |
195 """Generate a set of makefiles, or one big Makefile.""" |
169 |
196 |
170 if not self.valid: |
197 if not self.valid: |
171 return |
198 return None |
|
199 |
|
200 self.raptor.Debug("Writing Makefile '%s'" % (str(toplevel))) |
172 |
201 |
173 self.toplevel = toplevel |
202 self.toplevel = toplevel |
174 |
203 |
175 # create the top-level makefiles |
204 # create the top-level makefiles |
|
205 makefileset = None |
176 |
206 |
177 try: |
207 try: |
178 self.makefileset = MakefileSet(directory = str(toplevel.Dir()), |
208 makefileset = MakefileSet(directory = str(toplevel.Dir()), |
179 selectors = self.selectors, |
209 selectors = self.selectors, |
180 filenamebase = str(toplevel.File()), |
210 filenamebase = str(toplevel.File()), |
181 prologue = self.makefile_prologue, |
211 prologue = self.makefile_prologue, |
182 epilogue = self.makefile_epilogue, |
212 epilogue = self.makefile_epilogue, |
183 defaulttargets = self.defaultTargets) |
213 defaulttargets = self.defaultTargets) |
205 config_wide_spec = s |
234 config_wide_spec = s |
206 else: |
235 else: |
207 ordered_specs.append(s) |
236 ordered_specs.append(s) |
208 |
237 |
209 if config_wide_spec is not None: |
238 if config_wide_spec is not None: |
210 config_wide_spec.Configure(c) |
239 config_wide_spec.Configure(c, cache = self.raptor.cache) |
211 self.WriteConfiguredSpec(config_makefileset, config_wide_spec, c, True) |
240 self.WriteConfiguredSpec(config_makefileset, config_wide_spec, c, True) |
212 |
241 |
213 for s in ordered_specs: |
242 for s in ordered_specs: |
214 s.Configure(c) |
243 s.Configure(c, cache = self.raptor.cache) |
215 self.WriteConfiguredSpec(config_makefileset, s, c, False) |
244 self.WriteConfiguredSpec(config_makefileset, s, c, False) |
216 |
245 |
217 self.makefileset.close() |
246 makefileset.close() |
218 except Exception,e: |
247 except Exception,e: |
219 self.raptor.Error("Failed to write makefile '%s': %s" % (str(toplevel),str(e))) |
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 |
220 |
255 |
221 |
256 |
222 def WriteConfiguredSpec(self, parentMakefileSet, spec, config, useAllInterfaces): |
257 def WriteConfiguredSpec(self, parentMakefileSet, spec, config, useAllInterfaces): |
223 # ignore this spec if it is empty |
258 # ignore this spec if it is empty |
224 hasInterface = spec.HasInterface() |
259 hasInterface = spec.HasInterface() |
266 |
302 |
267 parameters.append((k, value)) |
303 parameters.append((k, value)) |
268 md5hash.update(value) |
304 md5hash.update(value) |
269 |
305 |
270 # parameters required by the interface |
306 # parameters required by the interface |
271 for p in iface.GetParams(): |
307 for p in iface.GetParams(self.raptor.cache): |
272 val = evaluator.Resolve(p.name) |
308 val = evaluator.Resolve(p.name) |
273 addparam(p.name,val,p.default) |
309 addparam(p.name,val,p.default) |
274 |
310 |
275 # Use Patterns to fetch a group of parameters |
311 # Use Patterns to fetch a group of parameters |
276 for g in iface.GetParamGroups(): |
312 for g in iface.GetParamGroups(self.raptor.cache): |
277 for k,v in evaluator.ResolveMatching(g.patternre): |
313 for k,v in evaluator.ResolveMatching(g.patternre): |
278 addparam(k,v,g.default) |
314 addparam(k,v,g.default) |
279 |
315 |
280 hash = md5hash.hexdigest() |
316 hash = md5hash.hexdigest() |
281 dupe = hash in self.hashes |
317 dupe = hash in self.hashes |
299 else: |
335 else: |
300 guard = "guard_" + hash |
336 guard = "guard_" + hash |
301 |
337 |
302 # generate the call to the FLM |
338 # generate the call to the FLM |
303 if iface is not None: |
339 if iface is not None: |
304 makefileset.addCall(spec.name, config.name, iface.name, useAllInterfaces, iface.GetFLMIncludePath(), parameters, guard) |
340 makefileset.addCall(spec.name, config.name, iface.name, useAllInterfaces, iface.GetFLMIncludePath(self.raptor.cache), parameters, guard) |
305 |
341 |
306 # recursive includes |
342 # recursive includes |
307 |
343 |
308 for child in childSpecs: |
344 for child in childSpecs: |
309 self.WriteConfiguredSpec(makefileset, child, config, useAllInterfaces) |
345 self.WriteConfiguredSpec(makefileset, child, config, useAllInterfaces) |
351 |
387 |
352 # Files should be deleted in the opposite order to the order |
388 # Files should be deleted in the opposite order to the order |
353 # they were built. So reverse file order if cleaning |
389 # they were built. So reverse file order if cleaning |
354 if clean_flag: |
390 if clean_flag: |
355 fileName_list.reverse() |
391 fileName_list.reverse() |
|
392 |
|
393 # Report number of makefiles to be built |
|
394 self.raptor.InfoDiscovery(object_type = "makefile", count = len(fileName_list)) |
356 |
395 |
357 # Process each file in turn |
396 # Process each file in turn |
358 for makefile in fileName_list: |
397 for makefile in fileName_list: |
359 if not os.path.exists(makefile): |
398 if not os.path.exists(makefile): |
360 self.raptor.Info("Skipping makefile %s", makefile) |
399 self.raptor.Info("Skipping makefile %s", makefile) |
399 command += ' RECIPETRIES=' + str(self.raptor.tries) |
438 command += ' RECIPETRIES=' + str(self.raptor.tries) |
400 command += ' TALON_RETRIES=' + str(self.raptor.tries - 1) |
439 command += ' TALON_RETRIES=' + str(self.raptor.tries - 1) |
401 |
440 |
402 # targets go at the end, if the makefile supports them |
441 # targets go at the end, if the makefile supports them |
403 addTargets = self.raptor.targets[:] |
442 addTargets = self.raptor.targets[:] |
404 ignoreTargets = self.makefileset.ignoreTargets(makefile) |
443 ignoreTargets = makefileset.ignoreTargets(makefile) |
405 if addTargets and ignoreTargets: |
444 if addTargets and ignoreTargets: |
406 for target in self.raptor.targets: |
445 for target in self.raptor.targets: |
407 if re.match(ignoreTargets, target): |
446 if re.match(ignoreTargets, target): |
408 addTargets.remove(target) |
447 addTargets.remove(target) |
409 |
448 |
410 if addTargets: |
449 if addTargets: |
411 command += " " + " ".join(addTargets) |
450 command += " " + " ".join(addTargets) |
|
451 |
|
452 # Substitute the makefile name for any occurrence of #MAKEFILE# |
|
453 command = command.replace("#MAKEFILE#", str(makefile)) |
412 |
454 |
413 self.raptor.Info("Executing '%s'", command) |
455 self.raptor.Info("Executing '%s'", command) |
414 |
456 |
415 # execute the build. |
457 # execute the build. |
416 # the actual call differs between Windows and Unix. |
458 # the actual call differs between Windows and Unix. |
417 # bufsize=1 means "line buffered" |
459 # bufsize=1 means "line buffered" |
418 # |
460 # |
419 try: |
461 try: |
|
462 # Time the build |
|
463 self.raptor.InfoStartTime(object_type = "makefile", |
|
464 task = "build", key = str(makefile)) |
|
465 |
420 makeenv=os.environ.copy() |
466 makeenv=os.environ.copy() |
421 if self.usetalon: |
467 if self.usetalon: |
422 makeenv['TALON_RECIPEATTRIBUTES']="none" |
468 makeenv['TALON_RECIPEATTRIBUTES']="none" |
423 makeenv['TALON_SHELL']=self.talonshell |
469 makeenv['TALON_SHELL']=self.talonshell |
424 makeenv['TALON_BUILDID']=str(self.buildID) |
470 makeenv['TALON_BUILDID']=str(self.buildID) |
442 self.raptor.out.write(line) |
488 self.raptor.out.write(line) |
443 |
489 |
444 # should be done now |
490 # should be done now |
445 returncode = p.wait() |
491 returncode = p.wait() |
446 |
492 |
|
493 # Report end-time of the build |
|
494 self.raptor.InfoEndTime(object_type = "makefile", |
|
495 task = "build", key = str(makefile)) |
447 |
496 |
448 if returncode != 0 and not self.raptor.keepGoing: |
497 if returncode != 0 and not self.raptor.keepGoing: |
449 self.Tidy() |
498 self.Tidy() |
450 return False |
499 return False |
451 |
500 |
452 except Exception,e: |
501 except Exception,e: |
453 self.raptor.Error("Exception '%s' during '%s'", str(e), command) |
502 self.raptor.Error("Exception '%s' during '%s'", str(e), command) |
454 self.Tidy() |
503 self.Tidy() |
|
504 # Still report end-time of the build |
|
505 self.raptor.InfoEnd(object_type = "Building", task = "Makefile", |
|
506 key = str(makefile)) |
455 return False |
507 return False |
456 |
508 |
457 # run any shutdown script |
509 # run any shutdown script |
458 if self.shutdownCommand != None and self.shutdownCommand != "": |
510 if self.shutdownCommand != None and self.shutdownCommand != "": |
459 self.raptor.Info("Running %s", self.shutdownCommand) |
511 self.raptor.Info("Running %s", self.shutdownCommand) |