fab.steps.preprocess module

Fortran and C Preprocessing.

class fab.steps.preprocess.MpCommonArgs(config, output_suffix, preprocessor, flags, name)

Bases: object

Common args for calling process_artefact() using multiprocessing.

config: BuildConfig
output_suffix: str
preprocessor: str
flags: FlagsConfig
name: str
fab.steps.preprocess.pre_processor(config, preprocessor, files, output_collection, output_suffix, common_flags=None, path_flags=None, name='preprocess')

Preprocess Fortran or C files.

Uses multiprocessing, unless disabled in the config.

Parameters:
  • config (BuildConfig) – The fab.build_config.BuildConfig object where we can read settings such as the project workspace folder or the multiprocessing flag.

  • preprocessor (str) – The preprocessor executable.

  • files (Collection[Path]) – The files to preprocess.

  • output_collection – The name of the output artefact collection.

  • output_suffix – Suffix for output files.

  • common_flags (Optional[List[str]]) – (default: None) Used to construct a FlagsConfig object.

  • path_flags (Optional[List]) – (default: None) Used to construct a FlagsConfig object.

  • name – (default: 'preprocess') Human friendly name for logger output, with sensible default.

fab.steps.preprocess.process_artefact(arg)

Expects an input file in the source folder. Writes the output file to the output folder, with a lower case extension.

fab.steps.preprocess.get_fortran_preprocessor()

Identify the fortran preprocessor and any flags from the environment.

Initially looks for the FPP environment variable, then tries to call the fpp and cpp command line tools.

Returns the executable and flags.

The returned flags will always include -P to suppress line numbers. This fparser ticket requests line number handling https://github.com/stfc/fparser/issues/390 .

fab.steps.preprocess.preprocess_fortran(config, source=None, **kwargs)

Wrapper to pre_processor for Fortran files.

Ensures all preprocessed files are in the build output. This means copying already preprocessed files from source to build output.

Params as per _pre_processor().

The preprocessor is taken from the FPP environment, or falls back to fpp -P.

If source is not provided, it defaults to SuffixFilter(‘all_source’, ‘.F90’).

class fab.steps.preprocess.DefaultCPreprocessorSource

Bases: ArtefactsGetter

A source getter specifically for c preprocessing. Looks for the default output from pragma injection, falls back to default source finder. This allows the step to work with or without a preceding pragma step.

fab.steps.preprocess.preprocess_c(config, source=None, **kwargs)

Wrapper to pre_processor for C files.

Params as per _pre_processor().

The preprocessor is taken from the CPP environment, or falls back to cpp.

If source is not provided, it defaults to DefaultCPreprocessorSource.