1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """ IO module for SystemDefinitionFile.
21 - Allow convertion to m,a
22 """
23 import re
24 import sys
25 import os
26 import buildtools
27 import sysdef.api
28
30 """ Cleanup the path to transfer it to the makefile.
31 This is needed for echo command for example.
32 """
33 result = os.path.join(os.environ['EPOCROOT'], path)
34 result = re.sub(r'(.*(?:\\\\)*)\\$', r'\1\\\\', result)
35 return result
36
38 """ Cleanup the path to transfer it to the makefile.
39 This is needed for echo command for example.
40 """
41 result = re.sub(r'%EPOCROOT%', '', path)
42 return result
43
44
46 return re.sub(r'(.*(?:\\\\)*)\\\s*$', r'\1\\\\', cmd)
47
49 """ Precede special characters with a caret so
50 that they can output with the DOS echo command
51 """
52 result = re.sub(r'\|', r'^|', cmd)
53 result = re.sub(r'&', r'^&', result)
54 result = re.sub(r'>', r'^>', result)
55 result = re.sub(r'<', r'^<', result)
56 return result
57
59 return "perl -e \"print '++ %s '.localtime().\\\"\\n\\\"\"" % title
60
62 return "perl -e \"use Time::HiRes; print '+++ HiRes %s '.Time::HiRes::time().\\\"\\n\\\";\"" % title
63
65 """ This function is used to determined if the command is using -c/-w/-what/-check flag. """
66 return re.match(r'abld\s+(\w+\s+)*(-c(heck)?|-w(hat)?)(\s+.*)?', command) != None
67
69 return re.sub("\s", "_", name)
70
71
75
77 self._fileOut.write("# Generated makefile\n")
78 for option in sdf._options:
79 self._fileOut.write("%s := %s\n\n" % (option, sdf._options[option].filteredOption))
80 for cf in sdf._configurations:
81 self._configuration_to_makefile(sdf._configurations[cf])
82
99
101 output = ""
102 if isinstance(task.job, sysdef.api.BuildLayer):
103 if len(task.job.targetList) > 0:
104 output += "%s-buildLayer-%s:" % (task.job.config.target, task.job.target)
105 for target in task.job.targetList:
106 output += " $(foreach UNIT,$(%s-UNITLIST),$(UNIT)-command-%s-%s)" % (task.job.config.target, task.job.target, target.target)
107 output += "\n\n"
108 for target in task.job.targetList:
109 if is_abld_what_or_check_command(task.job.command):
110 command = "%s %s" % (task.job.command, target.abldTarget)
111 else:
112 command = "%s $(KEEPGOING) %s" % (task.job.command, target.abldTarget)
113 output += "%%-command-%s-%s:\n" % (task.job.target, target.target)
114 output += "\t@echo === Stage=%s == $*\n" % task.job.target
115 output += "\t@echo --- ElectricCloud Executed ID %s\n" % command_to_makefile(command_to_echo(command))
116 output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(command))
117 output += "\t-@%s\n" % get_localtime_command()
118 output += "\t-@%s\n" % get_hires_command()
119 output += "\t@echo Chdir $*\n"
120 output += "\t-@cd $* && %s\n" % command_to_makefile(command)
121 output += "\t-@%s\n" % get_localtime_command("End")
122 output += "\t-@%s\n" % get_localtime_command("Finished at")
123 else:
124 if not is_abld_what_or_check_command(task.job.command):
125 command = "%s $(KEEPGOING)" % task.job.command
126 else:
127 command = task.job.command
128 output += "%s-buildLayer-%s: $(foreach UNIT,$(%s-UNITLIST),$(UNIT)-command-%s)\n\n" % (task.job.config.target, task.job.target, task.job.config.target, task.job.target)
129 output += "%%-command-%s:\n" % task.job.target
130 output += "\t@echo === Stage=%s == $*\n" % task.job.target
131 output += "\t@echo --- ElectricCloud Executed ID %s\n" % command_to_makefile(command_to_echo(command))
132 output += "\t@echo -- %s\n" % re.sub(r'\|', r'^|', command)
133 output += "\t-@%s\n" % get_localtime_command()
134 output += "\t-@%s\n" % get_hires_command()
135 output += "\t@echo Chdir $*\n"
136 output += "\t-@cd $* && %s\n" % command_to_makefile(command)
137 output += "\t-@%s\n" % get_localtime_command("End")
138 output += "\t-@%s\n\n" % get_localtime_command("Finished at")
139
140 return output
141
167
168
237
239 output = ""
240 if isinstance(task.job, sysdef.api.BuildLayer):
241
242
243 glist = []
244 for unitlist in task.job.config.unitlistrefs:
245 glist.append("$(UNITLIST_%s)" % to_target(unitlist.name))
246 for layer in task.job.config.layerrefs:
247 glist.append("$(LAYER_%s)" % to_target(layer.name))
248
249 if len(task.job.targetList) > 0:
250
251 if not self._buildlayer_target_dep(task.job) in self._command_targets:
252 self._command_targets[self._buildlayer_target_dep(task.job)] = True
253 output += "%s:" % self._buildlayer_target_dep(task.job)
254 if task.job.unitParallel:
255 for target in task.job.targetList:
256 output += " $(foreach unit,$(call filter-unitlist,%s),$(unit)-command-%s-%s)" % (" ".join(glist), self._buildlayer_target(task.job), to_target(target.name))
257 output += "\n\n"
258 else:
259 output += " ; "
260 for target in task.job.targetList:
261 output += " $(foreach unit,$(call filter-unitlist,%s),$(call serialize,$(unit)-command-%s-%s))" % (" ".join(glist), self._buildlayer_target(task.job), to_target(target.name))
262 output += "\n\n"
263
264
265 for target in task.job.targetList:
266 target_name = "%%-command-%s-%s" % (self._buildlayer_target(task.job), to_target(target.name))
267 if not target_name in self._command_targets:
268 self._command_targets[target_name] = True
269 if is_abld_what_or_check_command(task.job.command):
270 command = "%s %s" % (task.job.command, target.abldTarget)
271 else:
272 command = "%s $(KEEPGOING) %s" % (task.job.command, target.abldTarget)
273 output += "%s:\n" % target_name
274 output += "\t@echo === Stage=%s == $(call get_unit_name,$*)\n" % self._buildlayer_target(task.job)
275 output += "\t@echo --- ElectricCloud Executed ID $(call get_unit_name,$*)\n"
276 output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(command))
277 output += "\t-@%s\n" % get_localtime_command()
278 output += "\t-@%s\n" % get_hires_command()
279 output += "\t@echo Chdir $(call get_unit_path,$*)\n"
280 output += "\t-@cd $(call get_unit_path,$*) && %s\n" % command_to_makefile(command)
281 output += "\t-@%s\n" % get_localtime_command("End")
282 output += "\t-@%s\n" % get_localtime_command("Finished at")
283 output += "\n\n"
284 else:
285 if not self._buildlayer_target_dep(task.job) in self._command_targets:
286 self._command_targets[self._buildlayer_target_dep(task.job)] = True
287 if task.job.unitParallel:
288 output += "%s: $(foreach unit,$(call filter-unitlist,%s),$(unit)-command-%s)\n\n" % (self._buildlayer_target_dep(task.job),
289 " ".join(glist),
290 self._buildlayer_target(task.job))
291 else:
292 output += "%s: ; $(foreach unit,$(call filter-unitlist,%s),$(call serialize,$(unit)-command-%s))\n\n" % (self._buildlayer_target_dep(task.job),
293 " ".join(glist),
294 self._buildlayer_target(task.job))
295
296 cmd_target_name = "%%-command-%s" % self._buildlayer_target(task.job)
297 if not cmd_target_name in self._command_targets:
298 self._command_targets[cmd_target_name] = True
299 if not is_abld_what_or_check_command(task.job.command):
300 command = "%s $(KEEPGOING)" % task.job.command
301 else:
302 command = task.job.command
303 output += "%s:\n" % cmd_target_name
304 output += "\t@echo === Stage=%s == $(call get_unit_name,$*)\n" % self._buildlayer_target(task.job)
305 output += "\t@echo --- ElectricCloud Executed ID %s\n" % command_to_makefile(command_to_echo(command))
306 output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(task.job.command))
307 output += "\t-@%s\n" % get_localtime_command()
308 output += "\t-@%s\n" % get_hires_command()
309 output += "\t@echo Chdir $(call get_unit_path,$*)\n"
310 output += "\t-@cd $(call get_unit_path,$*) && %s\n" % command_to_makefile(command)
311 output += "\t-@%s\n" % get_localtime_command("End")
312 output += "\t-@%s\n\n" % get_localtime_command("Finished at")
313 return output
314
340
342 cmd = bl.command + "_".join(map(lambda x: x.name, bl.targetList))
343 cmd = re.sub("[\s]", "_", cmd)
344 cmd = re.sub("[|]", "_pipe_", cmd)
345 cmd = re.sub("[&]", "_and_", cmd)
346 return cmd
347
349 """ Generating target name for buildlayer:
350 <config_name>-buildLayer-<_buildlayer_target_cmd>
351 """
352 return "%s-buildLayer-%s" % (to_target(bl.config.name), self._buildlayer_target(bl))
353
355
360
366
402
403
406
412
414 for task in config.tasks:
415 self._fileOut.write(self._task_to_makefile(task))
416 self._fileOut.write("\n\n")
417
418 self._fileOut.write("%s: FILTERS=%s\n" % (config.name, " ".join(config.filters)))
419 self._fileOut.write("%s:" % (config.name))
420 if len(config.tasks)>0:
421 self._fileOut.write(" %s-task-%d" % (config.name, len(config.tasks)-1))
422 else:
423 self._fileOut.write(" ; @echo Nothing to do for configuration %s" % (config.name))
424 self._fileOut.write("\n\n")
425
426 count = 0
427 for task in config.tasks:
428 if count == 0:
429 self._fileOut.write("%s-task-%d:\n" % (config.name, count))
430 else:
431 self._fileOut.write("%s-task-%d: %s-task-%d\n" % (config.name, count, config.name, count-1))
432 self._fileOut.write(self._task_to_makefile_target(task))
433 count += 1
434
435 self._fileOut.write("\n\n")
436
438 output = ""
439 if isinstance(task.job, sysdef.api.BuildLayer):
440
441
442 glist = []
443 for unitlist in task.job.config.unitlistrefs:
444 glist.append("$(UNITLIST_%s)" % to_target(unitlist.name))
445 for layer in task.job.config.layerrefs:
446 glist.append("$(LAYER_%s)" % to_target(layer.name))
447
448 if len(task.job.targetList) > 0:
449
450 if not self._buildlayer_target_dep(task.job) in self._command_targets:
451 self._command_targets[self._buildlayer_target_dep(task.job)] = True
452 output += "%s:" % self._buildlayer_target_dep(task.job)
453 if task.job.unitParallel or self.build_layers_always_parallel:
454 for target in task.job.targetList:
455 output += " $(foreach unit,$(call filter-unitlist,%s),$(unit)-command-%s-%s)" % (" ".join(glist), self._buildlayer_target(task.job), to_target(target.name))
456 output += "\n\n"
457 else:
458 output += " ; "
459 for target in task.job.targetList:
460 output += " $(foreach unit,$(call filter-unitlist,%s),$(call serialize,$(unit)-command-%s-%s))" % (" ".join(glist), self._buildlayer_target(task.job), to_target(target.name))
461 output += "\n\n"
462
463
464 for target in task.job.targetList:
465 target_name = "%%-command-%s-%s" % (self._buildlayer_target(task.job), to_target(target.name))
466 if not target_name in self._command_targets:
467 self._command_targets[target_name] = True
468 if is_abld_what_or_check_command(task.job.command):
469 command = "%s %s" % (task.job.command, target.abldTarget)
470 else:
471 command = "%s $(KEEPGOING) %s" % (task.job.command, target.abldTarget)
472 output += "%s:\n" % target_name
473 output += "\t@echo === Stage=%s == $(call get_unit_name,$*)\n" % self._buildlayer_target(task.job)
474 output += "\t@echo --- ElectricCloud Executed ID $(call get_unit_name,$*)\n"
475 output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(command))
476 output += "\t-@%s\n" % get_localtime_command()
477 output += "\t-@%s\n" % get_hires_command()
478 output += "\t@echo Chdir $(call get_unit_path,$*)\n"
479 output += "\t-@cd $(call get_unit_path,$*) && %s\n" % command_to_makefile(command)
480 output += "\t-@%s\n" % get_localtime_command("End")
481 output += "\t-@%s\n" % get_localtime_command("Finished at")
482 output += "\n\n"
483 else:
484 if not self._buildlayer_target_dep(task.job) in self._command_targets:
485 self._command_targets[self._buildlayer_target_dep(task.job)] = True
486 if task.job.unitParallel or self.build_layers_always_parallel:
487 output += "%s: $(foreach unit,$(call filter-unitlist,%s),$(unit)-command-%s)\n\n" % (self._buildlayer_target_dep(task.job),
488 " ".join(glist),
489 self._buildlayer_target(task.job))
490 else:
491 output += "%s: ; $(foreach unit,$(call filter-unitlist,%s),$(call serialize,$(unit)-command-%s))\n\n" % (self._buildlayer_target_dep(task.job),
492 " ".join(glist),
493 self._buildlayer_target(task.job))
494
495 cmd_target_name = "%%-command-%s" % self._buildlayer_target(task.job)
496 if not cmd_target_name in self._command_targets:
497 self._command_targets[cmd_target_name] = True
498 if not is_abld_what_or_check_command(task.job.command):
499 command = "%s $(KEEPGOING)" % task.job.command
500 else:
501 command = task.job.command
502 output += "%s:\n" % cmd_target_name
503 output += "\t@echo === Stage=%s == $(call get_unit_name,$*)\n" % self._buildlayer_target(task.job)
504 output += "\t@echo --- ElectricCloud Executed ID %s\n" % command_to_makefile(command_to_echo(command))
505 output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(task.job.command))
506 output += "\t-@%s\n" % get_localtime_command()
507 output += "\t-@%s\n" % get_hires_command()
508 output += "\t@echo Chdir $(call get_unit_path,$*)\n"
509 output += "\t-@cd $(call get_unit_path,$*) && %s\n" % command_to_makefile(command)
510 output += "\t-@%s\n" % get_localtime_command("End")
511 output += "\t-@%s\n\n" % get_localtime_command("Finished at")
512 return output
513
539
541 cmd = bl.command + "_".join(map(lambda x: x.name, bl.targetList))
542 cmd = re.sub("[\s]", "_", cmd)
543 cmd = re.sub("[|]", "_pipe_", cmd)
544 cmd = re.sub("[&]", "_and_", cmd)
545 return cmd
546
548 """ Generating target name for buildlayer:
549 <config_name>-buildLayer-<_buildlayer_target_cmd>
550 """
551 return "%s-buildLayer-%s" % (to_target(bl.config.name), self._buildlayer_target(bl))
552
553
555 """ Writes a .csv file listing the content of the flash images. """
560
561 - def write(self, sys_def, config_list):
562 """ Write the .csv data to a file for the given System Definition and configuration name. """
563 self._out.write('component,binary,rom,rofs1,rofs2,rofs3\n')
564 for configuration in sys_def.configurations.values():
565
566 if configuration.name in config_list:
567 for unit in configuration.units:
568
569 for binary in unit.binaries:
570
571 if hasattr(binary, 'size'):
572 rom_types = {'rom': 0, 'rofs1': 1, 'rofs2': 2, 'rofs3': 3}
573 rom_type_values = ['', '', '', '']
574 rom_type_values[rom_types[binary.rom_type]] = str(binary.size)
575 rom_type_text = ','.join(rom_type_values)
576 self._out.write('%s,%s,%s\n' % (unit.name, binary.name, rom_type_text))
577
579 """ Closing the writer. """
580 self._out.close()
581