(self, actions, extra_sources, extra_outputs,
                   extra_mac_bundle_resources, part_of_all)
Write Makefile code for any 'actions' from the gyp input.

    extra_sources: a list that will be filled in with newly generated source
                   files, if any
    extra_outputs: a list that will be filled in with any outputs of these
                   actions (used to make other pieces dependent on these
                   actions)
    part_of_all: flag indicating this target is part of 'all'
Write Makefile code for any 'actions' from the gyp input.
Write Makefile code for any actions from the gyp input .
def WriteActions(self, actions, extra_sources, extra_outputs,
                   extra_mac_bundle_resources, part_of_all):
    """Write Makefile code for any 'actions' from the gyp input.

    extra_sources: a list that will be filled in with newly generated source
                   files, if any
    extra_outputs: a list that will be filled in with any outputs of these
                   actions (used to make other pieces dependent on these
                   actions)
    part_of_all: flag indicating this target is part of 'all'
    """
    env = self.GetSortedXcodeEnv()
    for action in actions:
      name = StringToMakefileVariable('%s_%s' % (self.qualified_target,
                                                 action['action_name']))
      self.WriteLn('### Rules for action "%s":' % action['action_name'])
      inputs = action['inputs']
      outputs = action['outputs']

      # Build up a list of outputs.
      # Collect the output dirs we'll need.
      dirs = set()
      for out in outputs:
        dir = os.path.split(out)[0]
        if dir:
          dirs.add(dir)
      if int(action.get('process_outputs_as_sources', False)):
        extra_sources += outputs
      if int(action.get('process_outputs_as_mac_bundle_resources', False)):
        extra_mac_bundle_resources += outputs

      # Write the actual command.
      action_commands = action['action']
      if self.flavor == 'mac':
        action_commands = [gyp.xcode_emulation.ExpandEnvVars(command, env)
                          for command in action_commands]
      command = gyp.common.EncodePOSIXShellList(action_commands)
      if 'message' in action:
        self.WriteLn('quiet_cmd_%s = ACTION %s $@' % (name, action['message']))
      else:
        self.WriteLn('quiet_cmd_%s = ACTION %s $@' % (name, name))
      if len(dirs) > 0:
        command = 'mkdir -p %s' % ' '.join(dirs) + '; ' + command

      cd_action = 'cd %s; ' % Sourceify(self.path or '.')

      # command and cd_action get written to a toplevel variable called
      # cmd_foo. Toplevel variables can't handle things that change per
      # makefile like $(TARGET), so hardcode the target.
      command = command.replace('$(TARGET)', self.target)
      cd_action = cd_action.replace('$(TARGET)', self.target)

      # Set LD_LIBRARY_PATH in case the action runs an executable from this
      # build which links to shared libs from this build.
      # actions run on the host, so they should in theory only use host
      # libraries, but until everything is made cross-compile safe, also use
      # target libraries.
      # TODO(piman): when everything is cross-compile safe, remove lib.target
      self.WriteLn('cmd_%s = LD_LIBRARY_PATH=$(builddir)/lib.host:'
                   '$(builddir)/lib.target:$$LD_LIBRARY_PATH; '
                   'export LD_LIBRARY_PATH; '
                   '%s%s'
                   % (name, cd_action, command))
      self.WriteLn()
      outputs = map(self.Absolutify, outputs)
      # The makefile rules are all relative to the top dir, but the gyp actions
      # are defined relative to their containing dir.  This replaces the obj
      # variable for the action rule with an absolute version so that the output
      # goes in the right place.
      # Only write the 'obj' and 'builddir' rules for the "primary" output (:1);
      # it's superfluous for the "extra outputs", and this avoids accidentally
      # writing duplicate dummy rules for those outputs.
      # Same for environment.
      self.WriteLn("%s: obj := $(abs_obj)" % QuoteSpaces(outputs[0]))
      self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(outputs[0]))
      self.WriteSortedXcodeEnv(outputs[0], self.GetSortedXcodeEnv())

      for input in inputs:
        assert ' ' not in input, (
            "Spaces in action input filenames not supported (%s)"  % input)
      for output in outputs:
        assert ' ' not in output, (
            "Spaces in action output filenames not supported (%s)"  % output)

      # See the comment in WriteCopies about expanding env vars.
      outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs]
      inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs]

      self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
                      part_of_all=part_of_all, command=name)

      # Stuff the outputs in a variable so we can refer to them later.
      outputs_variable = 'action_%s_outputs' % name
      self.WriteLn('%s := %s' % (outputs_variable, ' '.join(outputs)))
      extra_outputs.append('$(%s)' % outputs_variable)
      self.WriteLn()

    self.WriteLn()
def WriteActions ( self , actions , extra_sources , extra_outputs , extra_mac_bundle_resources , part_of_all ) : env = self . GetSortedXcodeEnv ( ) for action in actions : name = StringToMakefileVariable ( '%s_%s' % ( self . qualified_target , action [ 'action_name' ] ) ) self . WriteLn ( '### Rules for action "%s":' % action [ 'action_name' ] ) inputs = action [ 'inputs' ] outputs = action [ 'outputs' ] # Build up a list of outputs. # Collect the output dirs we'll need. dirs = set ( ) for out in outputs : dir = os . path . split ( out ) [ 0 ] if dir : dirs . add ( dir ) if int ( action . get ( 'process_outputs_as_sources' , False ) ) : extra_sources += outputs if int ( action . get ( 'process_outputs_as_mac_bundle_resources' , False ) ) : extra_mac_bundle_resources += outputs # Write the actual command. action_commands = action [ 'action' ] if self . flavor == 'mac' : action_commands = [ gyp . xcode_emulation . ExpandEnvVars ( command , env ) for command in action_commands ] command = gyp . common . EncodePOSIXShellList ( action_commands ) if 'message' in action : self . WriteLn ( 'quiet_cmd_%s = ACTION %s $@' % ( name , action [ 'message' ] ) ) else : self . WriteLn ( 'quiet_cmd_%s = ACTION %s $@' % ( name , name ) ) if len ( dirs ) > 0 : command = 'mkdir -p %s' % ' ' . join ( dirs ) + '; ' + command cd_action = 'cd %s; ' % Sourceify ( self . path or '.' ) # command and cd_action get written to a toplevel variable called # cmd_foo. Toplevel variables can't handle things that change per # makefile like $(TARGET), so hardcode the target. command = command . replace ( '$(TARGET)' , self . target ) cd_action = cd_action . replace ( '$(TARGET)' , self . target ) # Set LD_LIBRARY_PATH in case the action runs an executable from this # build which links to shared libs from this build. # actions run on the host, so they should in theory only use host # libraries, but until everything is made cross-compile safe, also use # target libraries. # TODO(piman): when everything is cross-compile safe, remove lib.target self . WriteLn ( 'cmd_%s = LD_LIBRARY_PATH=$(builddir)/lib.host:' '$(builddir)/lib.target:$$LD_LIBRARY_PATH; ' 'export LD_LIBRARY_PATH; ' '%s%s' % ( name , cd_action , command ) ) self . WriteLn ( ) outputs = map ( self . Absolutify , outputs ) # The makefile rules are all relative to the top dir, but the gyp actions # are defined relative to their containing dir.  This replaces the obj # variable for the action rule with an absolute version so that the output # goes in the right place. # Only write the 'obj' and 'builddir' rules for the "primary" output (:1); # it's superfluous for the "extra outputs", and this avoids accidentally # writing duplicate dummy rules for those outputs. # Same for environment. self . WriteLn ( "%s: obj := $(abs_obj)" % QuoteSpaces ( outputs [ 0 ] ) ) self . WriteLn ( "%s: builddir := $(abs_builddir)" % QuoteSpaces ( outputs [ 0 ] ) ) self . WriteSortedXcodeEnv ( outputs [ 0 ] , self . GetSortedXcodeEnv ( ) ) for input in inputs : assert ' ' not in input , ( "Spaces in action input filenames not supported (%s)" % input ) for output in outputs : assert ' ' not in output , ( "Spaces in action output filenames not supported (%s)" % output ) # See the comment in WriteCopies about expanding env vars. outputs = [ gyp . xcode_emulation . ExpandEnvVars ( o , env ) for o in outputs ] inputs = [ gyp . xcode_emulation . ExpandEnvVars ( i , env ) for i in inputs ] self . WriteDoCmd ( outputs , map ( Sourceify , map ( self . Absolutify , inputs ) ) , part_of_all = part_of_all , command = name ) # Stuff the outputs in a variable so we can refer to them later. outputs_variable = 'action_%s_outputs' % name self . WriteLn ( '%s := %s' % ( outputs_variable , ' ' . join ( outputs ) ) ) extra_outputs . append ( '$(%s)' % outputs_variable ) self . WriteLn ( ) self . WriteLn ( )