Repository navigation
Description
Description of the problem / feature request:
Repository rules implemented in Skylark should have the ability to read and write files or directories in the repository cache. This would be useful for downloading files using something other than HTTP. It would also be useful for verifying downloads using mechanisms other than SHA-256 on the archive.
For example, here's how this might be used to checkout a git repository.
def _git_repository_impl(ctx):
key = struct(
remote = ctx.attr.remote,
commit = ctx.attr.commit,
)
cache_path = ctx.cache.get(key)
if cache_path:
ctx.execute(["cp", "-r", cache_path, "."])
return
ctx.execute(["git", "clone", "-n", ctx.attr.remote, "."])
ctx.execute(["git", "checkout", revision])
ctx.execute(["rm", "-rf", ".git"])
ctx.cache.put(key, ".")
Feature requests: what underlying problem are you trying to solve with this feature?
In rules_go, users usually checkout dependencies using go_repository with a GitHub URL. It's not common practice to attach source archives to releases, so most of the time, this rule downloads repositories with git clone (other VCSs are supported, too). There should be a way for these downloads to be cached.
go_repository may also download repository archives over HTTP. GitHub has an endpoint for this, codeload.github.com. However, GitHub generates archives on request, and their SHA-256 is not stable. For example, things like alignment or file order may change when GitHub updates their server software. This broke us a few times, and we've largely abandoned the practice of using sha256 on codeload.github.com URLs. Ideally, we could verify the SHA-256 of the archive contents instead of the archive itself, since that should never change.
Activity
meteorcloudy commentedon Apr 25, 2018
@laurentlb Can you take a look? :)
ittaiz commentedon Jul 16, 2018
@aehlig any thoughts given your recent work?
aehlig commentedon Jul 16, 2018
I don't think my recent work influences this feature request.
My general thoughts are that, on the one hand, it is a good idea to allow other cache keys. But the main concern is correctness. For the simple hash of a file, bazel can easily verify itself that the cache hit is correct, so all is fine. For the API proposed in that feature request, however, arbitrary repository rules can add arbitrary values into the cache, making (accidental) cache poising a real issue. Thus, a proper design avoiding this danger still has to be found.
For git in particular, which is basically a content-addressable store, giving optional access to a "cache repository" (where arbitrary commits can be pushed to) might be a good plan forward. That can already be implement in Skylark as we currently have it (providing the cache repository as an optional argument containing an absolute path outside bazel), if someone finds the time.
fenollp commentedon Apr 21, 2020
Another advantage of caching contents instead of the "envelopes": toolchains could be cached.
On Bazel 3.0.0 (at least) the same toolchains can be duplicated in multiple
output_bases and take a few GBs each.This is common with
bazel sync-ing a resolved file.Can't this be solved by passing the "cache miss" function along with the (key,value)?
For instance:
({"urls": [..]}, native.download_and_extract, {"sha256": ...}).i.e. color cache key with a callback macro's class (
@dep//tar:get%macro, or all the way to a hash of its AST). Calling this macro should be able to reproduce the cached value.ckolli5 commentedon Jun 10, 2022
Hey @jayconrod, Hope you are doing well!
I wanted to check with you on the above issue whether if you are still able to reproduce or resolved, Can you please share the complete details. It will be closed very soon, if no further activity occurs on this issue. Thank you.
sgowroji commentedon Jun 17, 2022
@jayconrod, I'm going to go ahead and close this Issue, because it seems to have stalled from long duration. If you're still interested in pursing this (and responding to above comments), please feel free to open a new issue adding this as reference!