craft_parts.plugins.bazel_plugin module

The Bazel plugin implementation.

class craft_parts.plugins.bazel_plugin.BazelPlugin(*, properties, part_info)

Bases: Plugin

A plugin useful for building Bazel-based parts.

Bazel-based projects are projects that have a Bazel build system that drives the build.

This plugin runs bazel build for the configured targets and then copies Bazel output artifacts from bazel-bin into $CRAFT_PART_INSTALL.

This plugin uses the common plugin keywords as well as those for “sources”. For more information check the ‘plugins’ topic for the former and the ‘sources’ topic for the latter.

Plugin-specific keywords:

bazel-parameters (list of strings) passes additional arguments to bazel build.

bazel-targets (list of strings; default: [“//…”]) sets which targets are built.

Parameters:
get_build_commands()

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()

Return a set of required snaps to install in the build environment.

Return type:

set[str]

properties_class

alias of BazelPluginProperties

validator_class

alias of BazelPluginEnvironmentValidator

class craft_parts.plugins.bazel_plugin.BazelPluginEnvironmentValidator(*, part_name, env, properties)

Bases: PluginEnvironmentValidator

Check the execution environment for the Bazel plugin.

Parameters:
  • part_name (str) – The part whose build environment is being validated.

  • env (str) – A string containing the build step environment setup.

  • properties (PluginProperties)

validate_environment(*, part_dependencies=None)

Ensure the environment contains dependencies needed by the plugin.

Parameters:

part_dependencies (list[str] | None) – A list of the parts this part depends on.

Raises:

PluginEnvironmentValidationError – If bazel is missing and there are no parts named “bazel-deps”.

Return type:

None

class craft_parts.plugins.bazel_plugin.BazelPluginProperties(**data)

Bases: PluginProperties

The part properties used by the Bazel plugin.

Parameters:

data (Any)

after: Optional[Annotated[list[str]]]
bazel_parameters: list[str]
bazel_targets: list[str]
model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

plugin: Literal['bazel']
source: str