fab.fab_base.fab_base#

This is an OO basic interface to FAB. It allows typical applications to only modify very few settings to have a working FAB build script.

Classes

FabBase(name[, link_target])

This is a convenience base class for writing Fab scripts.

class fab.fab_base.fab_base.FabBase(name, link_target='executable')#

This is a convenience base class for writing Fab scripts. It provides an extensive set of command line options that can be used to influence the build process, and can be extended by applications. It has already support for compilation modes, and allows site-specific configuration scripts to be written that can modify the initialisation and build process.

Parameters:
  • name (str) – the name to be used for the workspace. Note that the name of the compiler will be added to it.

  • link_target (str) – what target should be created. Must be one of “executable” (default), “static-library”, or “shared-library” (default: 'executable')

Sets the link target.

Parameters:

link_target (str) – what target should be created. Must be one of “executable”s, “static-library”, or “shared-library”.

Raises:

ValueError – if the link_target is invalid

Return type:

None

define_project_name(name)#

This method defines the project name, i.e. the directory name to use in the Fab workspace. It defaults to name-profile-compiler.

Parameters:

name (str) – the base name of the project as specified by the caller.

Return type:

str

Returns:

the project name

set_root_symbol(root_symbol)#

Defines the root symbol. It defaults to the name given in the constructor.

Parameters:

name – the root symbol to use when creating a binary (unused otherwise).

Return type:

None

property root_symbol: List[str]#
Returns:

the list of root symbols.

property site: str | None#
Returns:

the site, or None if no site is specified.

property logger: Logger#
Returns:

the logging instance to use.

property platform: str | None#
Returns:

the platform, or None if not specified.

property target: str#
Returns:

the target (=”site-platform”), or “default” if nothing was specified.

property config: BuildConfig#
Returns:

the FAB BuildConfig instance.

Return type:

fab.BuildConfig

property args: Namespace#
Returns:

the arg parse objects containing the user’s command line information.

property project_workspace: Path#
Returns:

the Fab workspace for this build.

property preprocess_flags_common: List[str]#
Returns:

the list of all common preprocessor flags.

property preprocess_flags_path: List[AddFlags]#
Returns:

the list of all path-specific flags.

property fortran_compiler_flags_commandline: List[str]#
Returns:

the list of flags specified through –fflags.

property c_compiler_flags_commandline: List[str]#
Returns:

the list of flags specified through –cflags.

property linker_flags_commandline: List[str]#
Returns:

the list of flags specified through –ldflags.

setup_site_specific_location()#

This method adds the required directories for site-specific configurations to the Python search path. This implementation will search the call tree to find the first call that’s not from Fab, i.e. the user script. It then adds site_specific and site_specific/default to the directory in which the user script is located. An application can overwrite this method to change this behaviour and point at site-specific directories elsewhere.

Return type:

None

define_site_platform_target()#

This method defines the attributes site, platform (and target=site-platform) based on the command line option –site and –platform (using $SITE and $PLATFORM as a default). If site or platform is missing and the corresponding environment variable is not set, ‘default’ will be used.

Return type:

None

site_specific_setup()#

Imports a site-specific config file. The location is based on the attribute target (which is set to be {site}_{platform}" based on the command line options, and the path is specified in ``setup_site_specific_location).

Return type:

None

define_command_line_options(parser=None)#

Defines command line options. Can be overwritten by a derived class which can provide its own instance (to easily allow for a different description).

Parameters:

parser (Optional[ArgumentParser]) – optional a pre-defined argument parser. If not, a new instance will be created. (default: None)

Return type:

ArgumentParser

handle_command_line_options(parser)#

Analyse the actual command line options using the specified parser. The base implementation will handle the –suite parameter, and compiler/linker parameters (including the usage of environment variables). Needs to be overwritten to handle additional options specified by a derived script.

Parameters:

parser (argparse.ArgumentParser) – the argument parser.

Return type:

None

define_preprocessor_flags_step()#

Top level function that sets preprocessor flags. The base implementation does nothing, should be overwritten.

Return type:

None

get_linker_flags()#

Base class for setting linker flags. This base implementation for now just returns an empty list.

Return type:

List[str]

Returns:

list of flags for the linker.

add_preprocessor_flags(list_of_flags)#

This function appends a preprocessor flags to the internal list of all preprocessor flags, which will be passed to Fab’s various preprocessing steps (for C, Fortran, and X90).

Each flag can be either a str, or a path-specific instance of Fab’s AddFlags object. For the convenience of the user, this function also accepts a single flag or a list of flags.

No checking will be done if a flag is already in the list of flags.

Parameters:

list_of_flags (Union[AddFlags, str, List[AddFlags], List[str]]) – the preprocessor flag(s) to add. This can be either a str or an AddFlags, and in each case either a single item or a list.

Return type:

None

grab_files_step()#

This should typically be overwritten by an application to get files e.g. from a repository.

Return type:

None

find_source_files_step(path_filters=None)#

This function calls Fab’s find_source_files, to identify and add all source files to Fab’s artefact store.

Parameters:

path_filters (Optional[Iterable[Union[Exclude, Include]]]) – optional list of path filters to be passed to Fab find_source_files, default is None. (default: None)

Return type:

None

preprocess_c_step()#

Calls Fab’s preprocessing of all C files. It passes the common and path-specific flags set using add_preprocessor_flags.

Return type:

None

preprocess_fortran_step()#

Calls Fab’s preprocessing of all fortran files. It passes the common and path-specific flags set using add_preprocessor_flags.

Return type:

None

analyse_step(find_programs=False)#

Calls Fab’s analyse. It passes the config and root symbol for Fab to analyze the source code dependencies.

Find_programs:

if set and an executable is created (see link_target), the flag will be set in Fab’s analyse step, which means it will identify all main programs automatically.

Return type:

None

compile_c_step(common_flags=None, path_flags=None)#

Calls Fab’s compile_c. It passes the config for Fab to compile all C files. Optionally, common flags, path-specific flags and alternative source can also be passed to Fab for compilation.

Return type:

None

compile_fortran_step(common_flags=None, path_flags=None)#

Calls Fab’s compile_fortran. It passes the config for Fab to compile all Fortran files. Optionally, common flags, path-specific flags and alternative source can also be passed to Fab for compilation.

Parameters:

path_flags (Optional[List[AddFlags]]) – optional list of path-specific flags to be passed to Fab compile_fortran, default is None. (default: None)

Return type:

None

Calls Fab’s archive_objects for creating static libraries, or link_shared_object for creating shared libraries, or link_exe for creating executable binaries. The outputs will be placed in the Fab workspace, either using the name or root_symbol passed to the Fab build config.

Return type:

None

build()#

This function defines the build process for Fab. Generally, a build process involves grabbing and finding Fortran and C source files for proprocessing, dependency analysis, compilation and linking.

Return type:

None