From 00543dc61c79f472ce9c2d84b9d22c49dfba48ee Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Fri, 15 Sep 2023 21:03:08 -0400 Subject: [PATCH] Handle bad rename Cleanspec wasn't working, so let's handle it in Soong Test: create an invalid file, run m nothing, verify it is removed Change-Id: I55d3c9344541b8e504887225a660044e14204427 --- cmd/soong_ui/main.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index 0b542fec5..3b8f4f5a4 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -289,12 +289,38 @@ func logAndSymlinkSetup(buildCtx build.Context, config build.Config) { } } + removeBadTargetRename(buildCtx, config) + // Create a source finder. f := build.NewSourceFinder(buildCtx, config) defer f.Shutdown() build.FindSources(buildCtx, config, f) } +func removeBadTargetRename(ctx build.Context, config build.Config) { + log := ctx.ContextImpl.Logger + // find bad paths + m, err := filepath.Glob(filepath.Join(config.OutDir(), "bazel", "output", "execroot", "__main__", "bazel-out", "mixed_builds_product-*", "bin", "tools", "metalava", "metalava")) + if err != nil { + log.Fatalf("Glob for invalid file failed %s", err) + } + for _, f := range m { + info, err := os.Stat(f) + if err != nil { + log.Fatalf("Stat of invalid file %q failed %s", f, err) + } + // if it's a directory, leave it, but remove the files + if !info.IsDir() { + err = os.Remove(f) + if err != nil { + log.Fatalf("Remove of invalid file %q failed %s", f, err) + } else { + log.Verbosef("Removed %q", f) + } + } + } +} + func dumpVar(ctx build.Context, config build.Config, args []string) { logAndSymlinkSetup(ctx, config) flags := flag.NewFlagSet("dumpvar", flag.ExitOnError)