bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Automatic deletion of old build output for no longer existing workspaces.

Open ulrfa opened this issue 3 years ago • 3 comments

Description of the feature request:

This feature request is primarily about automatic deletion of old workspace directories in the output root, which are associated with workspace locations that no longer exist in the file system.

If building such automatic deletion into bazel is too controversial, then an alternative could be to expose a formal interface where an external cleanup script could retrieve association from build output directories to workspace locations. That association is already provided in generated README files, but they states:

The first line of this file is intentionally easy to parse for various interactive scripting and debugging purposes. But please DO NOT write programs that exploit it, as they will be broken by design: it is not possible to reverse engineer the set of source trees or the --package_path from the output tree, and if you attempt it, you will fail, creating subtle and hard-to-diagnose bugs, that will no doubt get blamed on changes made by the Bazel team.

Feature requests: what underlying problem are you trying to solve with this feature?

Our users often create new git clones at various file system locations. After deleting the git clones, the associated build output remains "forever" and consume lots of space in their output root.

“Bazel clean” only deletes the current workspace.

Many users have limited knowledge about the output root, how the build output is stored for each workspace or what internal directories are safe to delete. I think bazel should solve this problem for them automatically.

Have you found anything relevant by searching the web?

Related to #12902, but that one is not automatic and delete everything (also workspaces still working with).

#5139 touches on similar subject but is primarily about --disk_cache not build output in output root.

ulrfa avatar Mar 14 '22 09:03 ulrfa

Hi @ulrfa , thanks for filing this FR. I think it's overall a good idea.

One implementation could be for the Bazel installer aka Bazelisk to set up a cron job. Not sure if there are considerations about doing this by default (e.g. not sure if all users would like that sort of side effect). team-Core doesn't currently have the resources or expertise to do this Bazel user research, nor do we own Bazelisk.

If we drop the "automatic" part of the FR, then one idea would be a new feature of bazel clean that tries to clean up workspaces besides the current one.

haxorz avatar Apr 28 '22 18:04 haxorz

Thanks @haxorz

Deleting these outputs via bazelisk (or similar) would require bazel to expose the mapping between build outputs and workspaces. Right? But bazel’s README files warns about trying to get those mappings (quoted in description of this ticket).

Making this a new feature of bazel clean is an alternative. But I would like users to trust the build system and not fall back to old habits of too much ’make clean’. Therefore I would prefer an automatic solution.

ulrfa avatar May 18 '22 15:05 ulrfa

#2109 Was only solving install base "when running from project", not in stale workspaces? I got hit by "cloning things around as building as well :(