Suppose I have a very minimal project with an empty WORKSPACE
and a single package defined at the project root that simply uses touch
to create a file called a
, as follows:
genrule(
name = "target",
cmd = "touch $@",
outs = ["a"],
)
If I now run
bazel build //:target
the package will be "built" and the a
file will be available under bazel-genfiles
.
Suppose I now change the BUILD
to write the output to a different file, as follows:
genrule(
name = "target",
cmd = "touch $@",
outs = ["b"],
)
Building the same target will result in the file b
being available under bazel-genfiles
. a
will still be there though, even though at this point it's "unreachable" from within the context of the build definition.
Is there a way to ask Bazel to perform some sort of "garbage collection" and remove files (and possibly other content) generated by previous builds that are no longer reachable as-per the current build definition, without getting rid of the entire directory? The bazel clean
command seems to adopt the latter behavior.
There seems to be a feature in the works, but apparently it cannot be performed on demand, but rather it executes automatically as soon as a certain threshold has been reached.
Note that running bazel clean
will not actually delete the external directory. To remove all external artifacts, use bazel clean --expunge
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With