Skip to content

Conversation

@thorsten-klein
Copy link
Contributor

This PR adds support for cache directories for blobs via the ZEPHYR_BLOBS_CACHE environment variable.
The variable may contain a single directory or multiple directories separated by ;.

When running west blobs fetch:

  • If one or more cache directories are provided, the command searches them in order for the requested blob.
    If the blob is found, it is copied to the according path. It searches for a file named as the blob, or the name prefixed with the sha256 hashsum.

  • If exactly one cache directory is provided, the cache is automatically filled:
    when a blob is not found in the cache, it is fetched, stored in that cache directory (with its SHA-256 hash as a prefix), and then copied to the according path.

  • If multiple cache directories are provided, the command behaves like a lookup-only cache:
    if the blob is not found in any of the specified directories, it is fetched directly into the blobs directory as usual (i.e., without populating the caches).

Why?

This feature can help to speed up builds and save network bandwidth in a CI environment (that start with an empty workspace), as blobs are cached and not re-downloaded.
It also helps to become independent from 3rd party servers, as all blobs can be pre-fetched and packaged and uploaded to own server.

Considered Alternative

There could be a remapping of the url from blobs done in a config file. But this is much more complex than this solution.

@zephyrbot zephyrbot added the area: West West utility label Nov 19, 2025
@thorsten-klein thorsten-klein marked this pull request as draft November 19, 2025 16:17
In environment variable `ZEPHYR_BLOBS_CACHE` one or more directories
(separated by `;`) can be specified. `west blobs fetch` will search in
these folders for according file and copy it if it exists. If only one
directory was given, it will automatically fill the cache by fetching
the blob to this cache dir (with prefixed sha256 hashsum) and
subsequently copy the file to the blobs path. Otherwise it fetches the
blob as usual directly to the blobs path.

Signed-off-by: Thorsten Klein <[email protected]>
@sonarqubecloud
Copy link

cached_filenames = [f'{sha256}-{path.name}', path.name]

# check if the blob is already cached
cache_dirs = os.getenv('ZEPHYR_BLOBS_CACHE', '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid using environment variables where CLI arguments or west config options are perfectly viable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I will update it tomorrow to a west config option.

Any wishes for the option name?
zephyr.blobs-cache-dir?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe blobs.cache-dir is sufficient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: West West utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants