Package sysdef :: Module io |
[hide private]
[frames] | no frames]

# Source Code for Module sysdef.io

      1  #============================================================================
      2  #Name        : io.py
      3  #Part of     : Helium
      4
      5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
      6  #All rights reserved.
      7  #This component and the accompanying materials are made available
      8  #under the terms of the License "Eclipse Public License v1.0"
      9  #which accompanies this distribution, and is available
     10  #at the URL "http://www.eclipse.org/legal/epl-v10.html".
     11  #
     12  #Initial Contributors:
     13  #Nokia Corporation - initial contribution.
     14  #
     15  #Contributors:
     16  #
     17  #Description:
     18  #===============================================================================
     19  # pylint: disable-msg=W0212,W0141
     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
     29 -def path_to_makefile_echo(path):
     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
     37 -def path_to_makefile_command(path):
     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
     45 -def command_to_makefile(cmd):
     46      return re.sub(r'(.*(?:\\\\)*)\\\s*$', r'\1\\\\', cmd)
     47
     48 -def command_to_echo(cmd):
     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
     58 -def get_localtime_command(title='Started at'):
     59      return "perl -e \"print '++ %s '.localtime().\\\"\\n\\\"\"" % title
     60
     61 -def get_hires_command(title='Start'):
     62      return "perl -e \"use Time::HiRes; print '+++ HiRes %s '.Time::HiRes::time().\\\"\\n\\\";\"" % title
     63
     64 -def is_abld_what_or_check_command(command):
     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
     68 -def to_target(name):
     69      return re.sub("\s", "_", name)
     70
     71
     72 -class MakeWriter(buildtools.AbstractOutputWriter):
     73 -    def __init__(self, output):
     74          buildtools.AbstractOutputWriter.__init__(self, output)
     75
     76 -    def write(self, sdf):
     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
     83 -    def _configuration_to_makefile(self, config):
     84          sys.stderr.write(" * Generating configuration %s\n" % config.name)
     85
     86          self._fileOut.write("%s-UNITLIST := " % config.target)
     87
     88          for unit in config.units():
     89              self._fileOut.write(" \\\n   %s" % unit.path)
     90
     91          self._fileOut.write("\n\n")
     92          self._fileOut.write("%s:\n" % config.target)
     93          mainoutput = ""
     94          for task in config.tasks:
     95              self._fileOut.write(self._task_to_makefile_target(task))
     96              mainoutput +=  task._task_to_makefile()
     97
     98          self._fileOut.write("\n\n" + mainoutput)
     99
    100 -    def _task_to_makefile(self, task):
    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
    142 -    def _task_to_makefile_target(self, task):
    143          output = ""
    144          if isinstance(task.job, sysdef.api.SpecialInstruction):
    145              output = ("\t@echo ===-------------------------------------------------\n")
    146              output += ("\t@echo === Stage=%s\n" % task.job.name)
    147              output += ("\t@echo ===-------------------------------------------------\n")
    148              output += ("\t-@perl -e \"print '=== Stage=%s started '.localtime().\\\"\\n\\\"\"\n" % task.job.name)
    149              output += "\t@echo === Stage=%s == %s\n" % (task.job.name, task.job.name)
    150              output += "\t@echo --- ElectricCloud Executed ID %s\n" % command_to_makefile(command_to_echo(task.job.command))
    151              output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(task.job.command))
    152              output += "\t-@%s\n" % get_localtime_command()
    153              output += "\t-@%s\n" % get_hires_command()
    154              output += "\t@echo Chdir %s\n" % path_to_makefile_echo(task.job.path)
    155              output += "\t-@cd %s && %s\n" % (os.path.join(os.path.sep, path_to_makefile_command(task.job.path)), command_to_makefile(task.job.command))
    156              output += "\t-@%s\n" % get_localtime_command("End")
    157              output += "\t-@%s\n\n" % get_localtime_command("Finished at")
    158              output += ("\t-@perl -e \"print '=== Stage=%s finished '.localtime().\\\"\\n\\\"\"\n\n" % task.job.name)
    159          else:
    160              output = ("\t@echo ===-------------------------------------------------\n")
    161              output += ("\t@echo === Stage=%s\n" % task.job.target)
    162              output += ("\t@echo ===-------------------------------------------------\n")
    163              output += ("\t-@perl -e \"print '=== Stage=%s started '.localtime().\\\"\\n\\\"\"\n" % task.job.target)
    164              output += "\t-@$(MAKE) -k %s-buildLayer-%s\n" % (task.job.config.target, task.job.target)
    165              output += ("\t-@perl -e \"print '=== Stage=%s finished '.localtime().\\\"\\n\\\"\"\n\n" % task.job.target)
    166          return output
    167
    168
    169 -class MakeWriter2(buildtools.AbstractOutputWriter):
    170 -    def __init__(self, output):
    171          buildtools.AbstractOutputWriter.__init__(self, output)
    172          self._command_targets = {}
    173
    174 -    def __read_file(self, filename):
    175          f = open(filename)
    176          content = f.read()
    177          f.close()
    178          return content
    179
    180 -    def write(self, sdf):
    181          self._fileOut.write("# Generated makefile\n")
    182          self._fileOut.write(self.__read_file(os.path.join(os.environ['HELIUM_HOME'], 'tools/compile/ec/ec_functions.mk')))
    183          self._fileOut.write("\n\n")
    184
    185          # options
    186          self._fileOut.write("\n# Options\n")
    187          for option in sdf._options:
    188              self._fileOut.write("%s := %s\n\n" % (option, sdf._options[option].filteredOption))
    189          self._fileOut.write("\n# Units\n")
    190          for unitid in sdf.units.keys():
    191              self._unit_to_makefile(sdf.units[unitid])
    192          self._fileOut.write("\n# Layers\n")
    193          for layerid in sdf.layers.keys():
    194              self._group_to_makefile(sdf.layers[layerid], "LAYER")
    195          self._fileOut.write("\n# Unitlists\n")
    196          for unitlistid in sdf.unitlists.keys():
    197              self._group_to_makefile(sdf.unitlists[unitlistid], "UNITLIST")
    198
    199          self._fileOut.write("\n# Configurations\n")
    200          for cf in sdf.configurations.keys():
    201              self._configuration_to_makefile(sdf._configurations[cf])
    202
    203          self._fileOut.write("\n# Helps\n")
    204          self._fileOut.write("\nhelp:\n")
    205          self._fileOut.write("\t@echo (e)make configurations           display all available configurations.\n")
    206          self._fileOut.write("\t@echo (e)make units                    display all available units.\n")
    207
    208          self._fileOut.write("\nconfigurations:\n")
    209          for cf in sdf.configurations.keys():
    210              self._fileOut.write("\t@echo %s\n" % sdf._configurations[cf].name)
    211
    212          self._fileOut.write("\nunits:\n")
    213          for unit in sdf.units.keys():
    214              self._fileOut.write("\t@echo %s\n" % sdf.units[unit].id)
    215
    216
    217 -    def _unit_to_makefile(self, unit):
    218          self._fileOut.write("UNIT_%s:=%s|%s|%s\n" % (unit.id, unit.name, unit.path, " ".join(unit.filters)))
    219
    220 -    def _group_to_makefile(self, group, gtype):
    221          self._fileOut.write("%s_%s:=" % (gtype, to_target(group.name)))
    222          for unit in group.units:
    223              self._fileOut.write(" \\\n%s" % unit.id)
    224          self._fileOut.write(" \n\n")
    225
    226 -    def _configuration_to_makefile(self, config):
    227          for task in config.tasks:
    228              self._fileOut.write(self._task_to_makefile(task))
    229          self._fileOut.write("\n\n")
    230
    231          self._fileOut.write("%s: FILTERS=%s\n" % (config.name, " ".join(config.filters)))
    232          self._fileOut.write("%s:\n" % (config.name))
    233          for task in config.tasks:
    234              self._fileOut.write(self._task_to_makefile_target(task))
    235
    236          self._fileOut.write("\n\n")
    237
    238 -    def _task_to_makefile(self, task):
    239          output = ""
    240          if isinstance(task.job, sysdef.api.BuildLayer):
    241
    242              # generating the list of required unit groups
    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
    315 -    def _task_to_makefile_target(self, task):
    316          output = ""
    317          if isinstance(task.job, sysdef.api.SpecialInstruction):
    318              output = ("\t@echo ===-------------------------------------------------\n")
    319              output += ("\t@echo === Stage=%s\n" % task.job.name)
    320              output += ("\t@echo ===-------------------------------------------------\n")
    321              output += ("\t-@perl -e \"print '=== Stage=%s started '.localtime().\\\"\\n\\\"\"\n" % task.job.name)
    322              output += "\t@echo === Stage=%s == %s\n" % (task.job.name, task.job.name)
    323              output += "\t@echo --- ElectricCloud Executed ID %s\n" % command_to_makefile(command_to_echo(task.job.command))
    324              output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(task.job.command))
    325              output += "\t-@%s\n" % get_localtime_command()
    326              output += "\t-@%s\n" % get_hires_command()
    327              output += "\t@echo Chdir %s\n" % path_to_makefile_echo(task.job.path)
    328              output += "\t-@cd %s && %s\n" % (os.path.join(os.path.sep, path_to_makefile_command(task.job.path)), command_to_makefile(task.job.command))
    329              output += "\t-@%s\n" % get_localtime_command("End")
    330              output += "\t-@%s\n" % get_localtime_command("Finished at")
    331              output += ("\t-@perl -e \"print '=== Stage=%s finished '.localtime().\\\"\\n\\\"\"\n\n" % task.job.name)
    332          else:
    333              output = ("\t@echo ===-------------------------------------------------\n")
    334              output += ("\t@echo === Stage=%s\n" % self._buildlayer_target(task.job))
    335              output += ("\t@echo ===-------------------------------------------------\n")
    336              output += ("\t-@perl -e \"print '=== Stage=%s started '.localtime().\\\"\\n\\\"\"\n" % self._buildlayer_target(task.job))
    337              output += "\t-@$(MAKE) $(MAKEFILE_CMD_LINE) -k %s \"FILTERS=$(FILTERS)\"\n" % self._buildlayer_target_dep(task.job)
    338              output += ("\t-@perl -e \"print '=== Stage=%s finished '.localtime().\\\"\\n\\\"\"\n\n" % self._buildlayer_target(task.job))
    339          return output
    340
    341 -    def _buildlayer_target(self, bl):
    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
    348 -    def _buildlayer_target_dep(self, bl):
    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
    354 -class MakeWriter3(buildtools.AbstractOutputWriter):
    355
    356 -    def __init__(self, output):
    357          buildtools.AbstractOutputWriter.__init__(self, output)
    358          self._command_targets = {}
    359          self.build_layers_always_parallel = True
    360
    361 -    def __read_file(self, filename):
    362          f = open(filename)
    363          content = f.read()
    364          f.close()
    365          return content
    366
    367 -    def write(self, sdf):
    368          self._fileOut.write("# Generated makefile\n")
    369          self._fileOut.write(self.__read_file(os.path.join(os.environ['HELIUM_HOME'], 'tools/compile/ec/ec_functions.mk')))
    370          self._fileOut.write("\n\n")
    371
    372          # options
    373          self._fileOut.write("\n# Options\n")
    374          for option in sdf._options:
    375              self._fileOut.write("%s := %s\n\n" % (option, sdf._options[option].filteredOption))
    376          self._fileOut.write("\n# Units\n")
    377          for unitid in sdf.units.keys():
    378              self._unit_to_makefile(sdf.units[unitid])
    379          self._fileOut.write("\n# Layers\n")
    380          for layerid in sdf.layers.keys():
    381              self._group_to_makefile(sdf.layers[layerid], "LAYER")
    382          self._fileOut.write("\n# Unitlists\n")
    383          for unitlistid in sdf.unitlists.keys():
    384              self._group_to_makefile(sdf.unitlists[unitlistid], "UNITLIST")
    385
    386          self._fileOut.write("\n# Configurations\n")
    387          for cf in sdf.configurations.keys():
    388              self._configuration_to_makefile(sdf._configurations[cf])
    389
    390          self._fileOut.write("\n# Helps\n")
    391          self._fileOut.write("\nhelp:\n")
    392          self._fileOut.write("\t@echo (e)make configurations           display all available configurations.\n")
    393          self._fileOut.write("\t@echo (e)make units                    display all available units.\n")
    394
    395          self._fileOut.write("\nconfigurations:\n")
    396          for cf in sdf.configurations.keys():
    397              self._fileOut.write("\t@echo %s\n" % sdf._configurations[cf].name)
    398
    399          self._fileOut.write("\nunits:\n")
    400          for unit in sdf.units.keys():
    401              self._fileOut.write("\t@echo %s\n" % sdf.units[unit].id)
    402
    403
    404 -    def _unit_to_makefile(self, unit):
    405          self._fileOut.write("UNIT_%s:=%s|%s|%s\n" % (unit.id, unit.name, unit.path, " ".join(unit.filters)))
    406
    407 -    def _group_to_makefile(self, group, gtype):
    408          self._fileOut.write("%s_%s:=" % (gtype, to_target(group.name)))
    409          for unit in group.units:
    410              self._fileOut.write(" \\\n%s" % unit.id)
    411          self._fileOut.write(" \n\n")
    412
    413 -    def _configuration_to_makefile(self, config):
    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
    437 -    def _task_to_makefile(self, task):
    438          output = ""
    439          if isinstance(task.job, sysdef.api.BuildLayer):
    440
    441              # generating the list of required unit groups
    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
    514 -    def _task_to_makefile_target(self, task):
    515          output = ""
    516          if isinstance(task.job, sysdef.api.SpecialInstruction):
    517              output = ("\t@echo ===-------------------------------------------------\n")
    518              output += ("\t@echo === Stage=%s\n" % task.job.name)
    519              output += ("\t@echo ===-------------------------------------------------\n")
    520              output += ("\t-@perl -e \"print '=== Stage=%s started '.localtime().\\\"\\n\\\"\"\n" % task.job.name)
    521              output += "\t@echo === Stage=%s == %s\n" % (task.job.name, task.job.name)
    522              output += "\t@echo --- ElectricCloud Executed ID %s\n" % command_to_makefile(command_to_echo(task.job.command))
    523              output += "\t@echo -- %s\n" % command_to_makefile(command_to_echo(task.job.command))
    524              output += "\t-@%s\n" % get_localtime_command()
    525              output += "\t-@%s\n" % get_hires_command()
    526              output += "\t@echo Chdir %s\n" % path_to_makefile_echo(task.job.path)
    527              output += "\t-@cd %s && %s\n" % (os.path.join(os.path.sep, path_to_makefile_command(task.job.path)), command_to_makefile(task.job.command))
    528              output += "\t-@%s\n" % get_localtime_command("End")
    529              output += "\t-@%s\n" % get_localtime_command("Finished at")
    530              output += ("\t-@perl -e \"print '=== Stage=%s finished '.localtime().\\\"\\n\\\"\"\n\n" % task.job.name)
    531          else:
    532              output = ("\t@echo ===-------------------------------------------------\n")
    533              output += ("\t@echo === Stage=%s\n" % self._buildlayer_target(task.job))
    534              output += ("\t@echo ===-------------------------------------------------\n")
    535              output += ("\t-@perl -e \"print '=== Stage=%s started '.localtime().\\\"\\n\\\"\"\n" % self._buildlayer_target(task.job))
    536              output += "\t-@$(MAKE) $(MAKEFILE_CMD_LINE) -k %s \"FILTERS=$(FILTERS)\"\n" % self._buildlayer_target_dep(task.job)
    537              output += ("\t-@perl -e \"print '=== Stage=%s finished '.localtime().\\\"\\n\\\"\"\n\n" % self._buildlayer_target(task.job))
    538          return output
    539
    540 -    def _buildlayer_target(self, bl):
    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
    547 -    def _buildlayer_target_dep(self, bl):
    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
    554 -class FlashImageSizeWriter(object):
    555      """ Writes a .csv file listing the content of the flash images. """
    556 -    def __init__(self, output):
    557          """ Initialisation. """
    558          self.output = output
    559          self._out = file(output, 'w')
    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              #print configuration.name
    566              if configuration.name in config_list:
    567                  for unit in configuration.units:
    568                      #print str(unit.name) + '  ' + str(unit.binaries)
    569                      for binary in unit.binaries:
    570                          # Only print out the binaries for which there is size information
    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
    578 -    def close(self):
    579          """ Closing the writer. """
    580          self._out.close()
    581