fab.build_config module

Contains the BuildConfig and helper classes.

class fab.build_config.BuildConfig(project_label, parsed_args=None, multiprocessing=True, n_procs=None, reuse_artefacts=False, fab_workspace=None)

Bases: object

Contains and runs a list of build steps.

The user is not expected to instantiate this class directly, but rather through the build_config() context manager.

Parameters:
  • project_label (str) – Name of the build project. The project workspace folder is created from this name, with spaces replaced by underscores.

  • parsed_args (Optional[Namespace]) – (default: None) If you want to add arguments to your script, please use common_arg_parser() and add arguements. This pararmeter is the result of running ArgumentParser.parse_args().

  • multiprocessing (bool) – (default: True) An option to disable multiprocessing to aid debugging.

  • n_procs (Optional[int]) – (default: None) The number of cores to use for multiprocessing operations. Defaults to the number of available cores.

  • reuse_artefacts (bool) – (default: False) A flag to avoid reprocessing certain files on subsequent runs. WARNING: Currently unsophisticated, this flag should only be used by Fab developers. The logic behind flag will soon be improved, in a work package called “incremental build”.

  • fab_workspace (Optional[Path]) – (default: None) Overrides the FAB_WORKSPACE environment variable. If not set, and FAB_WORKSPACE is not set, the fab workspace defaults to ~/fab-workspace.

property build_output
init_artefact_store()
add_current_prebuilds(artefacts)

Mark the given file paths as being current prebuilds, not to be cleaned during housekeeping.

class fab.build_config.AddFlags(match, flags)

Bases: object

Add command-line flags when our path filter matches. Generally used inside a FlagsConfig.

Parameters:
  • match (str) – The string to match against each file path.

  • flags (List[str]) – The command-line flags to add for matching files.

Both the match and flags arguments can make use of templating:

  • $source for <project workspace>/source

  • $output for <project workspace>/build_output

  • $relative for <the source file’s folder>

For example:

# For source in the um folder, add an absolute include path
AddFlags(match="$source/um/*", flags=['-I$source/include']),

# For source in the um folder, add an include path relative to each source file.
AddFlags(match="$source/um/*", flags=['-I$relative/include']),
run(fpath, input_flags, config)

Check if our filter matches a given file. If it does, add our flags.

Parameters:
  • fpath (Path) – Filepath to check.

  • input_flags (List[str]) – The list of command-line flags Fab is building for this file.

  • config – Contains the folders for templating $source and $output.

class fab.build_config.FlagsConfig(common_flags=None, path_flags=None)

Bases: object

Return command-line flags for a given path.

Simply allows appending flags but may evolve to also replace and remove flags.

Parameters:
  • common_flags (Optional[List[str]]) – (default: None) List of flags to apply to all files. E.g [‘-O2’].

  • path_flags (Optional[List[AddFlags]]) – (default: None) List of AddFlags objects which apply flags to selected paths.

flags_for_path(path, config)

Get all the flags for a given file, in a reproducible order.

Parameters:
  • path (Path) – The file path for which we want command-line flags.

  • config – THe config contains the source root and project workspace.