BuildElement - Abstract class for build elements
The BuildElement class is a convenience element one can derive from for implementing the most common case of element.
Built-in functionality
Abstract method implementations
Element.configure_sandbox()
In Element.configure_sandbox(),
the BuildElement will ensure that the sandbox locations described by the %{build-root}
and %{install-root} variables are marked and will be mounted read-write for the
assemble phase.
The working directory for the sandbox will be configured to be the %{build-root},
unless the %{command-subdir} variable is specified for the element in question,
in which case the working directory will be configured as %{build-root}/%{command-subdir}.
Element.stage()
In Element.stage(), the BuildElement
will do the following operations:
Stage all of the build dependencies into the sandbox root.
Run the integration commands for all staged dependencies using
Element.integrate()Stage any Source on the given element to the
%{build-root}location inside the sandbox, usingElement.stage_sources()
Element.assemble()
In Element.assemble(), the
BuildElement will proceed to run sandboxed commands which are expected to be
found in the element configuration.
Commands are run in the following order:
configure-commands: Commands to configure the build scriptsbuild-commands: Commands to build the elementinstall-commands: Commands to install the results into%{install-root}strip-commands: Commands to strip debugging symbols installed binaries
The result of the build is expected to end up in %{install-root}, and
as such; Element.assemble() method will return the %{install-root} for
artifact collection purposes.
Note
In the case that the element is currently workspaced, the configure-commands
will only be run in subsequent builds until they succeed at least once, unless
bst workspace reset –soft is called on the
workspace to explicitly avoid an incremental build.
- class BuildElement(context: Context, project: Project, load_element: LoadElement, plugin_conf: str | None, *, artifact_key: str | None = None)
Bases:
Element- configure(node)
Configure the Plugin from loaded configuration data
- Parameters:
node – The loaded configuration dictionary
- Raises:
Plugin implementors should implement this method to read configuration data and store it.
The
MappingNode.validate_keys()method should be used to ensure that the user has not specified keys in node which are unsupported by the plugin.
- configure_dependencies(dependencies)
Configure the Element with regards to it’s build dependencies
Elements can use this method to parse custom configuration which define their relationship to their build dependencies.
If this method is implemented, then it will be called with all direct build dependencies specified in their element declaration in a list.
If the dependency was declared with custom configuration, it will be provided along with the dependency element, otherwise None will be passed with dependencies which do not have any additional configuration.
If the user has specified the same build dependency multiple times with differing configurations, then those build dependencies will be provided multiple times in the
dependencieslist.- Parameters:
dependencies (list) – A list of
DependencyConfigurationobjects- Raises:
.ElementError – When the element raises an error
The format of the
MappingNodeprovided asDependencyConfiguration.configmethod should be called by the implementing plugin in order to validate it.Note
It is unnecessary to implement this method if the plugin does not support any custom dependency configuration.
- preflight()
Preflight Check
- Raises:
This method is run after
Plugin.configure()and after the pipeline is fully constructed.Implementors should simply raise
SourceErrororElementErrorwith an informative message in the case that the host environment is unsuitable for operation.Plugins which require host tools (only sources usually) should obtain them with
utils.get_host_tool()which will raise an error automatically informing the user that a host tool is needed.
- get_unique_key()
Return something which uniquely identifies the plugin input
- Returns:
A string, list or dictionary which uniquely identifies the input
This is used to construct unique cache keys for elements and sources, sources should return something which uniquely identifies the payload, such as an sha256 sum of a tarball content.
Elements and Sources should implement this by collecting any configurations which could possibly affect the output and return a dictionary of these settings.
For Sources, this is guaranteed to only be called if
Source.is_resolved()has returnedTruewhich is to say that theSourceis expected to have an exact source ref indicating exactly what source is going to be staged.Note
If your plugin is concerned with API stability, then future extensions of your plugin YAML configuration which affect the unique key returned here should be added to this key with care.
A good rule of thumb is to only compute the new value in the returned key if the value of the newly added YAML key is not equal to it’s default value.
- configure_sandbox(sandbox)
Configures the the sandbox for execution
- Parameters:
sandbox – The build sandbox
:raises (
ElementError): When the element raises an errorElements must implement this method to configure the sandbox object for execution.
- stage(sandbox)
Stage inputs into the sandbox directories
- Parameters:
sandbox – The build sandbox
:raises (
ElementError): When the element raises an errorElements must implement this method to populate the sandbox directory with data. This is done either by staging
Sourceobjects, by staging the artifacts of the elements this element depends on, or both.
- assemble(sandbox)
Assemble the output artifact
- Parameters:
sandbox – The build sandbox
- Returns:
An absolute path within the sandbox to collect the artifact from
:raises (
ElementError): When the element raises an errorElements must implement this method to create an output artifact from its sources and dependencies.
- generate_script()
Generate a build (sh) script to build this element
- Returns:
A string containing the shell commands required to build the element
BuildStream guarantees the following environment when the generated script is run:
All element variables have been exported.
The cwd is self.get_variable(‘build-root’)/self.normal_name.
$PREFIX is set to self.get_variable(‘install-root’).
The directory indicated by $PREFIX is an empty directory.
Files are expected to be installed to $PREFIX.
If the script fails, it is expected to return with an exit code != 0.