fab.tools.tool#
This file contains the base class for all tools, i.e. compiler, preprocessor, linker, archiver, Psyclone, rsync, versioning tools.
Each tool belongs to one category (e.g. FORTRAN_COMPILER). This category is used when adding a tool to a ToolRepository or ToolBox. It provides basic support for running a binary, and keeping track if a tool is actually available.
Classes
|
A tool that is part of a compiler suite (typically compiler and linker). |
|
This is the base class for all tools. |
- class fab.tools.tool.Tool(name, exec_name, category=Category.MISC, availability_option=None)#
This is the base class for all tools. It stores the name of the tool, the name of the executable, and provides a run method.
- Parameters:
name (
str
) – name of the tool.exec_name (
Union
[str
,Path
]) – name or full path of the executable to start.category (
Category
) – the Category to which this tool belongs. (default:<Category.MISC: 13>
)availability_option (
Union
[str
,List
[str
],None
]) – a command line option for the tool to test if the tool is available on the current system. Defaults to –version. (default:None
)
- check_available()#
Run a ‘test’ command to check if this tool is available in the system. :rtype:
bool
:returns: whether the tool is working (True) or not.
- set_full_path(full_path)#
This function adds the full path to a tool. This allows tools to be used that are not in the user’s PATH. The ToolRepository will automatically update the path for a tool if the user specified a full path.
- Parameters:
full_path (
Path
) – the full path to the executable.
- property is_available: bool#
Checks if the tool is available or not. It will call a tool-specific function check_available to determine this, but will cache the results to avoid testing a tool more than once.
- Returns:
whether the tool is available (i.e. installed and working).
- property availability_option: str | List[str]#
- Returns:
the option to use to check if the tool is available.
- get_flags(profile=None)#
- Returns:
the flags to be used with this tool.
- add_flags(new_flags, profile=None)#
Adds the specified flags to the list of flags.
- define_profile(name, inherit_from=None)#
Defines a new profile name, and allows to specify if this new profile inherit settings from an existing profile.
- run(additional_parameters=None, profile=None, env=None, cwd=None, capture_output=True)#
Run the binary as a subprocess.
- Parameters:
additional_parameters (
Union
[str
,Sequence
[Union
[Path
,str
]],None
]) – List of strings or paths to be sent tosubprocess.run()
as additional parameters for the command. Any path will be converted to a normal string. (default:None
)env (
Optional
[Dict
[str
,str
]]) – Optional env for the command. By default it will use the current session’s environment. (default:None
)capture_output – If True, capture and return stdout. If False, the command will print its output directly to the console. (default:
True
)
- Raises:
RuntimeError – if the code is not available.
RuntimeError – if the return code of the executable is not 0.
- Return type:
- class fab.tools.tool.CompilerSuiteTool(name, exec_name, suite, category, availability_option=None)#
A tool that is part of a compiler suite (typically compiler and linker).
- Parameters:
name (
str
) – name of the tool.exec_name (
Union
[str
,Path
]) – name of the executable to start.suite (
str
) – name of the compiler suite.category (
Category
) – the Category to which this tool belongs.availability_option (
Union
[str
,List
[str
],None
]) – a command line option for the tool to test if the tool is available on the current system. Defaults to –version. (default:None
)