diff options
Diffstat (limited to 'cmd/soong_ui/main.go')
-rw-r--r-- | cmd/soong_ui/main.go | 113 |
1 files changed, 4 insertions, 109 deletions
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index c94ff0721..fe3f8f725 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -18,7 +18,6 @@ import ( "context" "flag" "fmt" - "io/ioutil" "os" "path/filepath" "strconv" @@ -194,16 +193,13 @@ func main() { buildErrorFile := filepath.Join(logsDir, c.logsPrefix+"build_error") soongMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_metrics") rbeMetricsFile := filepath.Join(logsDir, c.logsPrefix+"rbe_metrics.pb") - bp2buildMetricsFile := filepath.Join(logsDir, c.logsPrefix+"bp2build_metrics.pb") soongBuildMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_build_metrics.pb") metricsFiles := []string{ - buildErrorFile, // build error strings - rbeMetricsFile, // high level metrics related to remote build execution. - bp2buildMetricsFile, // high level metrics related to bp2build. - soongMetricsFile, // high level metrics related to this build system. - soongBuildMetricsFile, // high level metrics related to soong build(except bp2build) - config.BazelMetricsDir(), // directory that contains a set of bazel metrics. + buildErrorFile, // build error strings + rbeMetricsFile, // high level metrics related to remote build execution. + soongMetricsFile, // high level metrics related to this build system. + soongBuildMetricsFile, // high level metrics related to soong build } os.MkdirAll(logsDir, 0777) @@ -293,38 +289,12 @@ func preProductConfigSetup(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) { flags := flag.NewFlagSet("dumpvar", flag.ExitOnError) flags.SetOutput(ctx.Writer) @@ -607,81 +577,6 @@ func getCommand(args []string) (*command, []string, error) { return nil, nil, fmt.Errorf("Command not found: %q\nDid you mean one of these: %q", args[1], listFlags()) } -// For Bazel support, this moves files and directories from e.g. out/dist/$f to DIST_DIR/$f if necessary. -func populateExternalDistDir(ctx build.Context, config build.Config) { - // Make sure that internalDistDirPath and externalDistDirPath are both absolute paths, so we can compare them - var err error - var internalDistDirPath string - var externalDistDirPath string - if internalDistDirPath, err = filepath.Abs(config.DistDir()); err != nil { - ctx.Fatalf("Unable to find absolute path of %s: %s", internalDistDirPath, err) - } - if externalDistDirPath, err = filepath.Abs(config.RealDistDir()); err != nil { - ctx.Fatalf("Unable to find absolute path of %s: %s", externalDistDirPath, err) - } - if externalDistDirPath == internalDistDirPath { - return - } - - // Make sure the internal DIST_DIR actually exists before trying to read from it - if _, err = os.Stat(internalDistDirPath); os.IsNotExist(err) { - ctx.Println("Skipping Bazel dist dir migration - nothing to do!") - return - } - - // Make sure the external DIST_DIR actually exists before trying to write to it - if err = os.MkdirAll(externalDistDirPath, 0755); err != nil { - ctx.Fatalf("Unable to make directory %s: %s", externalDistDirPath, err) - } - - ctx.Println("Populating external DIST_DIR...") - - populateExternalDistDirHelper(ctx, config, internalDistDirPath, externalDistDirPath) -} - -func populateExternalDistDirHelper(ctx build.Context, config build.Config, internalDistDirPath string, externalDistDirPath string) { - files, err := ioutil.ReadDir(internalDistDirPath) - if err != nil { - ctx.Fatalf("Can't read internal distdir %s: %s", internalDistDirPath, err) - } - for _, f := range files { - internalFilePath := filepath.Join(internalDistDirPath, f.Name()) - externalFilePath := filepath.Join(externalDistDirPath, f.Name()) - - if f.IsDir() { - // Moving a directory - check if there is an existing directory to merge with - externalLstat, err := os.Lstat(externalFilePath) - if err != nil { - if !os.IsNotExist(err) { - ctx.Fatalf("Can't lstat external %s: %s", externalDistDirPath, err) - } - // Otherwise, if the error was os.IsNotExist, that's fine and we fall through to the rename at the bottom - } else { - if externalLstat.IsDir() { - // Existing dir - try to merge the directories? - populateExternalDistDirHelper(ctx, config, internalFilePath, externalFilePath) - continue - } else { - // Existing file being replaced with a directory. Delete the existing file... - if err := os.RemoveAll(externalFilePath); err != nil { - ctx.Fatalf("Unable to remove existing %s: %s", externalFilePath, err) - } - } - } - } else { - // Moving a file (not a dir) - delete any existing file or directory - if err := os.RemoveAll(externalFilePath); err != nil { - ctx.Fatalf("Unable to remove existing %s: %s", externalFilePath, err) - } - } - - // The actual move - do a rename instead of a copy in order to save disk space. - if err := os.Rename(internalFilePath, externalFilePath); err != nil { - ctx.Fatalf("Unable to rename %s -> %s due to error %s", internalFilePath, externalFilePath, err) - } - } -} - func setMaxFiles(ctx build.Context) { var limits syscall.Rlimit |