craftr.ext.compiler.base

Provides a convenient base class for Craftr compilers.

class craftr.ext.compiler.base.BaseCompiler(**kwargs)[source]

This is a convenient base class for implementing compilers.

Params kwargs:Arbitrary keyword arguments from which a Framework will be created and assigned to the settings member
from craftr.ext.compiler.base import BaseCompiler
from craftr.ext.compiler import gen_output

class SimpleGCC(BaseCompiler):
  def compile(self, sources, frameworks, **kwargs):
    builder = self.builder(sources, frameworks, kwargs)
    include = builder.merge('include')
    defines = builder.merge('defines')

    outputs = gen_output(builder.input, suffix='.obj')
    command = ['gcc', '-c', '$in', '-c', '-o', '$out']
    command += ['-I' + x for x in include]
    command += ['-D' + x for x in defines]
    return builder.create_target(command, outputs, foreach=True)

In the above example, the TargetBuilder returned by builder() has the following framework option resolution order (first is first):

  1. The **kwargs passed to compile()
  2. The Framework objects in frameworks
  3. The settings framework of SimpleGCC
  4. If the sources list contained an Target s, the Framework s of these targets will be considered
settings

A Framework that will be included in the TargetBuilder returned by the builder() method.

builder(inputs, frameworks, kwargs, **_add_kwargs)[source]

Create a TargetBuilder that includes the settings Framework of this BaseCompiler.

fork(**kwargs)[source]

Create a fork of the compiler that overrides/add parameters in the settings with the specified **kwargs.

register_hook(call, handler)[source]

Registers a handler for the method call that will be invoked when a TargetBuilder was created. It will allow the “handler” to set up default and additional settings.