NBPR.Buildroot.Backend behaviour (NBPR v0.2.1)

Copy Markdown View Source

Behaviour for the different ways NBPR can produce a per-package Buildroot artefact.

A backend takes a spec/0 (patched BR tree, output dir, rendered defconfig, BR package name, build env, extra mounts) and returns the harvest dir — the directory containing per-package/<br_package>/{target,staging,legal-info}, ready for NBPR.Buildroot.Harvest.harvest!/2.

Current backends, tried in order by select/0:

Adding a new style of builder (e.g. Apple's container, a Windows runtime) is a matter of implementing this behaviour and listing it in @backends.

Overriding the choice

Set NBPR_BUILD_BACKEND to a backend's short name (shell, docker, podman) to force that backend, bypassing the auto-detect ordering. This is handy when more than one runtime is present (e.g. force podman when docker would otherwise win) or to force a native build outside the canonical env. The chosen backend's build!/1 still fails loudly if it genuinely can't run.

Summary

Callbacks

Whether this backend can run in the current environment.

Builds the artefact described by spec and returns the harvest dir (containing per-package/<br_package>/).

Functions

Returns the backend to use.

Types

spec()

@type spec() :: %{
  br_source: Path.t(),
  output_dir: Path.t(),
  defconfig_text: String.t(),
  br_package: String.t(),
  env: [{String.t(), String.t()}],
  extra_mounts: [Path.t()]
}

Callbacks

available?()

@callback available?() :: boolean()

Whether this backend can run in the current environment.

build!(spec)

@callback build!(spec()) :: Path.t()

Builds the artefact described by spec and returns the harvest dir (containing per-package/<br_package>/).

Functions

select()

@spec select() :: module()

Returns the backend to use.

Honours a NBPR_BUILD_BACKEND override if set (see the module docs); otherwise returns the first backend that can run in the current environment. Raises with guidance if the override is unknown or no backend is available.