NBPR.Buildroot.Source (NBPR v0.2.1)

Copy Markdown View Source

Manages the cached Buildroot source tree.

Buildroot is large (~50 MB compressed, ~500 MB extracted) and shared across all nbpr operations targeting the same BR version. Layout under $NERVES_DATA_DIR/nbpr/:

  • buildroot-dl/ — BR source-tarball cache (shared across BR versions; accumulates over time, never invalidated)
  • buildroot/<version>/ — one extracted, patched, ready-to-use BR tree per version, treated as read-only thereafter

Per-build outputs live elsewhere via BR's O=<dir> flag and don't contend with this cache.

Patching is done via the patch binary. The patches come from the user's deps/nerves_system_br/patches/buildroot/ and must be applied in lexicographic order — Buildroot's own patch script does the same.

Summary

Functions

Returns the absolute path where BR version is (or will be) extracted.

Returns true when BR version is already extracted, patched, and marked ready at cache_dir/1.

Returns the shared download cache directory for BR source tarballs.

Ensures BR version is downloaded, extracted, patched against patches_dir, and ready at cache_dir(version). Returns the cache path.

Returns true when the BR tarball for version is sitting in the download cache. Useful for deciding whether ensure!/2 would do network — if both cached?/1 and tarball_cached?/1 are false, the next ensure!/2 will fetch over HTTP.

Returns the path the BR tarball for version is (or will be) cached at.

Functions

cache_dir(version)

@spec cache_dir(String.t()) :: Path.t()

Returns the absolute path where BR version is (or will be) extracted.

cached?(version)

@spec cached?(String.t()) :: boolean()

Returns true when BR version is already extracted, patched, and marked ready at cache_dir/1.

download_dir()

@spec download_dir() :: Path.t()

Returns the shared download cache directory for BR source tarballs.

ensure!(version, patches_dir)

@spec ensure!(String.t(), Path.t() | nil) :: Path.t()

Ensures BR version is downloaded, extracted, patched against patches_dir, and ready at cache_dir(version). Returns the cache path.

No-op when the version is already cached.

tarball_cached?(version)

@spec tarball_cached?(String.t()) :: boolean()

Returns true when the BR tarball for version is sitting in the download cache. Useful for deciding whether ensure!/2 would do network — if both cached?/1 and tarball_cached?/1 are false, the next ensure!/2 will fetch over HTTP.

tarball_path(version)

@spec tarball_path(String.t()) :: Path.t()

Returns the path the BR tarball for version is (or will be) cached at.