scripts: west_commands: blobs: support ZEPHYR_BLOBS_CACHE #99681
+35
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



This PR adds support for cache directories for blobs via the
ZEPHYR_BLOBS_CACHEenvironment 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.