cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.03k stars 287 forks source link

modules: add mod clean -modcache or similar #3131

Open myitcv opened 4 months ago

myitcv commented 4 months ago

In the spirit of go clean -modcache: https://go.dev/ref/mod#go-clean-modcache

More detail to follow

mvdan commented 4 months ago

My 2c: the only reason Go ended up with flags like -cache and -modcache is that go clean used to be for cleaning build artifacts from packages. Nowadays, almost noone uses it for that purpose anymore:

Clean removes object files from package source directories.
The go command builds most objects in a temporary directory,
so go clean is mainly concerned with object files left by other
tools or by manual invocations of go build.

I don't think we will ever have a need for such a "clean package build files" command. Even if evaluating a CUE package or building its e.g. wasm artifacts were to produce some sort of build output, that would be in the cache, not in the very same package directory.

For that reason, I think we should go for something like cue clean modcache, i.e. an argument instead of a flag. Given that all of our caches live under the same directory, we could also provide cue clean allcaches to delete all of it.

It's also worth noting that "modcache" is an artifact from Go's GOMODCACHE env var, which we do not have, so we can likely come up with a better name like go clean modulecache or, as a hierarchy, go clean cache/modules.

mvdan commented 4 months ago

or, as a hierarchy, go clean cache/modules.

note that this prompted me to file https://github.com/cue-lang/cue/issues/3139.

mvdan commented 3 months ago

With #3139 implemented, I think we should support the following commands to clean ${CUE_CACHE_DIR}:

Basically, either all to clear everything under ${CUE_CACHE_DIR}, or an argument for one of the known cache directories underneath.

(nevermind the fact that in an earlier comment I wrote go clean...)

ysmaoui commented 1 month ago

With #3139 implemented, I think we should support the following commands to clean ${CUE_CACHE_DIR}:

  • cue clean all - clear everything
  • cue clean mod - clear all module caches
  • cue clean mod/download - clear all downloaded modules
  • cue clean mod/extract - clear all extracted module archives

Basically, either all to clear everything under ${CUE_CACHE_DIR}, or an argument for one of the known cache directories underneath.

(nevermind the fact that in an earlier comment I wrote go clean...)

according to https://github.com/cue-lang/cue/issues/3139, this should have been part of v9.0.0 ? right ? but the cue clean all command seems not known to cue v0.9.2 ? ( or am I missing something? )

mvdan commented 1 month ago

@ysmaoui this issue is still open - cue clean has not been added as a command yet.

ysmaoui commented 1 month ago

another remark:

cue-cache

I am trying to cleanup the cache manually ( by deleting the content of the cache folder ) , but it seems that all files of the modules stored in the cache have permissions that block the deletion

is this a known issue?

mvdan commented 1 month ago

Yes, the files are marked read-only to discourage users from directly modifying them. This is why we want to add a cue clean command - to make it easy to clear the cache entries without needing rm -rf.