Ejemplo n.º 1
0
def gentask(func, args = None, inputs = (), outputs = (), name = None, **kwargs):
  """
  Create a Task that can be embedded into the build chain. Tasks can have input
  and output files that cause the task to be embedded into the build chain. By
  default, tasks need to be explicitly built or required by other targets.

  If *args* is not specified, it will be replaced by ``[inputs, outputs]``.

  :param func: A function to call to execute the task. It must accept a
    variable number of arguments, which are the arguments passed via the *args*
    parameter. This function will be called from Ninja using the ``craftr run``
    command.
  :param args: A list of arguments to pass to *func*. Note that non-string
    arguments will be pickled, compressed and and encoded in base64, prefixed
    with the string `pickle://`. These will be unpickled when the task is run.
    Note that ``$in`` and ``$out`` will be expanded in this argument list.
  :param inputs: A list of input files.
  :param inputs: A list of output files.
  :param name: Alternative target name.
  :param kwargs: Additional parameters for the :class:`Task` constructor.
  :return: A :class:`Target` object.
  """

  if args is None:
    args = [inputs, outputs]
  builder = TargetBuilder(gtn(name), inputs = inputs)
  task = _build.Task(builder.name, func, args)
  return session.graph.add_task(task, inputs = builder.inputs, outputs = outputs)
Ejemplo n.º 2
0
def genalias(*targets, name = None, **kwargs):
  """
  Create a target that serves as an alias for all targets list in *targets*.
  """

  name = gtn(name)
  return gentarget([['echo', 'alias: ' + name]], name = name,
    implicit_deps = targets, **kwargs)
Ejemplo n.º 3
0
def genalias(*targets, name = None, **kwargs):
  """
  Create a target that serves as an alias for all targets list in *targets*.
  """

  name = gtn(name)
  return gentarget([['echo', 'alias: ' + name]], name = name,
    implicit_deps = targets, **kwargs)
Ejemplo n.º 4
0
def gentool(commands, preamble=None, environ=None, name=None):
  """
  Create a :class:`~_build.Tool` object. The name of the tool will be derived
  from the variable name it is assigned to unless *name* is specified.
  """

  tool = _build.Tool(gtn(name), commands, preamble, environ)
  session.graph.add_tool(tool)
  return tool
Ejemplo n.º 5
0
def runtarget(target, *args, inputs=(), outputs=(), **kwargs):
  """
  Simplification of :func:`gentarget` to make it more obvious that a
  generate target is actually executed.
  """

  name = gtn(kwargs.pop('name', None))
  kwargs.setdefault('explicit', True)
  return gentarget([[target] + list(args)], inputs, outputs, name=name, **kwargs)
Ejemplo n.º 6
0
def gentool(commands, preamble=None, environ=None, name=None):
  """
  Create a :class:`~_build.Tool` object. The name of the tool will be derived
  from the variable name it is assigned to unless *name* is specified.
  """

  tool = _build.Tool(gtn(name), commands, preamble, environ)
  session.graph.add_tool(tool)
  return tool
Ejemplo n.º 7
0
def runtarget(target, *args, inputs=(), outputs=(), **kwargs):
  """
  Simplification of :func:`gentarget` to make it more obvious that a
  generate target is actually executed.
  """

  name = gtn(kwargs.pop('name', None))
  kwargs.setdefault('explicit', True)
  kwargs.setdefault('pool', 'console')
  return gentarget([target.runprefix + [target] + list(args)], inputs, outputs, name=name, **kwargs)
Ejemplo n.º 8
0
def gentarget(commands, inputs=(), outputs=(), *args, **kwargs):
  """
  Create a :class:`~_build.Target` object. The name of the target will be
  derived from the variable name it is assigned to unless *name* is specified.
  """

  target = _build.Target(gtn(kwargs.pop('name', None)), commands, inputs,
      outputs, *args, **kwargs)
  session.graph.add_target(target)
  return target
Ejemplo n.º 9
0
def gentarget(commands, inputs=(), outputs=(), *args, **kwargs):
  """
  Create a :class:`~_build.Target` object. The name of the target will be
  derived from the variable name it is assigned to unless *name* is specified.
  """

  target = _build.Target(gtn(kwargs.pop('name', None)), commands, inputs,
      outputs, *args, **kwargs)
  session.graph.add_target(target)
  return target