aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-06-02 13:37:46 +0900
committerOphestra <cat@gensokyo.uk>2026-06-02 13:37:46 +0900
commit1490b32387e52a21dc19495e15d32ee635bef710 (patch)
treefd8be08852420192dc3388923b422300f25b46c3
parentfbd2329d50a9ef2b15c0a6b62e9aa24635c2662a (diff)
cmd/mbf: garbage collection commands
Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/mbf/main.go47
1 files changed, 45 insertions, 2 deletions
diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go
index ed7b71bf..1a8cf743 100644
--- a/cmd/mbf/main.go
+++ b/cmd/mbf/main.go
@@ -86,6 +86,7 @@ func main() {
flagCheck bool
flagLTO bool
flagPT bool
+ flagDry bool
flagSourcePath string
flagCrossOverride int
@@ -205,6 +206,10 @@ func main() {
"parse-time", command.BoolFlag(false),
"Print duration of the initial azalea parse",
).Flag(
+ &flagDry,
+ "dry", command.BoolFlag(false),
+ "Do not destroy cache entries",
+ ).Flag(
&flagSourcePath,
"source", command.StringFlag(""),
"Override hakurei source tree",
@@ -736,8 +741,9 @@ func main() {
)
}
- c.NewCommand(
- "clear",
+ cleanC := c.New("clean", "Remove unused entries from the cache")
+ cleanC.NewCommand(
+ "fault",
"Remove all fault entries from the cache",
func([]string) error {
return cm.Do(func(*pkg.Cache) error {
@@ -758,6 +764,43 @@ func main() {
})
},
)
+ cleanC.NewCommand(
+ "checksum",
+ "Remove unreachable checksum entries",
+ func([]string) error {
+ return cm.Do(func(cache *pkg.Cache) error {
+ _, checksums, err := cache.Clean(flagDry, false)
+ log.Printf("destroyed %d entries", len(checksums))
+ return err
+ })
+ },
+ )
+ {
+ var flagDeep bool
+ cleanC.NewCommand(
+ "all",
+ "Remove identifiers not reachable by loaded packages",
+ func([]string) error {
+ return cm.Do(func(cache *pkg.Cache) error {
+ t := rosa.Native().Std()
+ ids, checksums, err := cache.Clean(
+ flagDry,
+ !flagDeep,
+ t.Append(nil, t.CollectAll()...)...,
+ )
+ log.Printf(
+ "destroyed %d identifier and %d checksum entries",
+ len(ids), len(checksums),
+ )
+ return err
+ })
+ },
+ ).Flag(
+ &flagDeep,
+ "deep", command.BoolFlag(false),
+ "Include transitive inputs",
+ )
+ }
c.NewCommand(
"abort",