diff --git a/android/bazel_paths.go b/android/bazel_paths.go index 1d0a6d541..c030aa864 100644 --- a/android/bazel_paths.go +++ b/android/bazel_paths.go @@ -32,14 +32,14 @@ import ( // There is often a similar method for Bazel as there is for Soong path handling and should be used // in similar circumstances // -// Bazel Soong -// -// BazelLabelForModuleSrc PathForModuleSrc -// BazelLabelForModuleSrcExcludes PathForModuleSrcExcludes -// BazelLabelForModuleDeps n/a -// tbd PathForSource -// tbd ExistentPathsForSources -// PathForBazelOut PathForModuleOut +// Bazel Soong +// ============================================================== +// BazelLabelForModuleSrc PathForModuleSrc +// BazelLabelForModuleSrcExcludes PathForModuleSrcExcludes +// BazelLabelForModuleDeps n/a +// tbd PathForSource +// tbd ExistentPathsForSources +// PathForBazelOut PathForModuleOut // // Use cases: // * Module contains a property (often tagged `android:"path"`) that expects paths *relative to the @@ -68,7 +68,7 @@ import ( // cannot be resolved,the function will panic. This is often due to the dependency not being added // via an AddDependency* method. -// A minimal context interface to check if a module should be converted by bp2build, +// BazelConversionContext is a minimal context interface to check if a module should be converted by bp2build, // with functions containing information to match against allowlists and denylists. // If a module is deemed to be convertible by bp2build, then it should rely on a // BazelConversionPathContext for more functions for dep/path features. diff --git a/bazel/aquery_test.go b/bazel/aquery_test.go index 3a2bf0f38..53056c742 100644 --- a/bazel/aquery_test.go +++ b/bazel/aquery_test.go @@ -499,19 +499,11 @@ func TestSymlinkTree(t *testing.T) { func TestBazelOutRemovalFromInputDepsets(t *testing.T) { const inputString = `{ - "artifacts": [{ - "id": 1, - "pathFragmentId": 10 - }, { - "id": 2, - "pathFragmentId": 20 - }, { - "id": 3, - "pathFragmentId": 30 - }, { - "id": 4, - "pathFragmentId": 40 - }], + "artifacts": [ + { "id": 1, "pathFragmentId": 10 }, + { "id": 2, "pathFragmentId": 20 }, + { "id": 3, "pathFragmentId": 30 }, + { "id": 4, "pathFragmentId": 40 }], "depSetOfFiles": [{ "id": 1111, "directArtifactIds": [3 , 4] @@ -525,28 +517,14 @@ func TestBazelOutRemovalFromInputDepsets(t *testing.T) { "outputIds": [2], "primaryOutputId": 1 }], - "pathFragments": [{ - "id": 10, - "label": "input" - }, { - "id": 20, - "label": "output" - }, { - "id": 30, - "label": "dep1", - "parentId": 50 - }, { - "id": 40, - "label": "dep2", - "parentId": 60 - }, { - "id": 50, - "label": "bazel_tools", - "parentId": 60 - }, { - "id": 60, - "label": ".." - }] + "pathFragments": [ + { "id": 10, "label": "input" }, + { "id": 20, "label": "output" }, + { "id": 30, "label": "dep1", "parentId": 50 }, + { "id": 40, "label": "dep2", "parentId": 60 }, + { "id": 50, "label": "bazel_tools", "parentId": 60 }, + { "id": 60, "label": ".."} + ] }` actualBuildStatements, actualDepsets, _ := AqueryBuildStatements([]byte(inputString)) if len(actualDepsets) != 1 { diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go index 5bff956be..0e3d2a5f9 100644 --- a/bp2build/bp2build.go +++ b/bp2build/bp2build.go @@ -29,7 +29,9 @@ import ( func Codegen(ctx *CodegenContext) CodegenMetrics { // This directory stores BUILD files that could be eventually checked-in. bp2buildDir := android.PathForOutput(ctx, "bp2build") - android.RemoveAllOutputDir(bp2buildDir) + if err := android.RemoveAllOutputDir(bp2buildDir); err != nil { + fmt.Printf("ERROR: Encountered error while cleaning %s: %s", bp2buildDir, err.Error()) + } res, errs := GenerateBazelTargets(ctx, true) if len(errs) > 0 { @@ -52,7 +54,9 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { // Get the output directory and create it if it doesn't exist. func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext, dir string) android.OutputPath { dirPath := outputDir.Join(ctx, dir) - android.CreateOutputDirIfNonexistent(dirPath, os.ModePerm) + if err := android.CreateOutputDirIfNonexistent(dirPath, os.ModePerm); err != nil { + fmt.Printf("ERROR: path %s: %s", dirPath, err.Error()) + } return dirPath } @@ -60,13 +64,13 @@ func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext, func writeFiles(ctx android.PathContext, outputDir android.OutputPath, files []BazelFile) { for _, f := range files { p := getOrCreateOutputDir(outputDir, ctx, f.Dir).Join(ctx, f.Basename) - if err := writeFile(ctx, p, f.Contents); err != nil { + if err := writeFile(p, f.Contents); err != nil { panic(fmt.Errorf("Failed to write %q (dir %q) due to %q", f.Basename, f.Dir, err)) } } } -func writeFile(ctx android.PathContext, pathToFile android.OutputPath, content string) error { +func writeFile(pathToFile android.OutputPath, content string) error { // These files are made editable to allow users to modify and iterate on them // in the source tree. return android.WriteFileToOutputDir(pathToFile, []byte(content), 0644) diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go index a96a3fc7b..415becb84 100644 --- a/bp2build/build_conversion.go +++ b/bp2build/build_conversion.go @@ -161,22 +161,22 @@ type CodegenContext struct { unconvertedDepMode unconvertedDepsMode } -func (c *CodegenContext) Mode() CodegenMode { - return c.mode +func (ctx *CodegenContext) Mode() CodegenMode { + return ctx.mode } // CodegenMode is an enum to differentiate code-generation modes. type CodegenMode int const ( - // Bp2Build: generate BUILD files with targets buildable by Bazel directly. + // Bp2Build - generate BUILD files with targets buildable by Bazel directly. // // This mode is used for the Soong->Bazel build definition conversion. Bp2Build CodegenMode = iota - // QueryView: generate BUILD files with targets representing fully mutated + // QueryView - generate BUILD files with targets representing fully mutated // Soong modules, representing the fully configured Soong module graph with - // variants and dependency endges. + // variants and dependency edges. // // This mode is used for discovering and introspecting the existing Soong // module graph. @@ -470,13 +470,13 @@ func generateSoongModuleTarget(ctx bpToBuildContext, m blueprint.Module) BazelTa }) } - for p, _ := range ignoredPropNames { + for p := range ignoredPropNames { delete(props.Attrs, p) } attributes := propsToAttributes(props.Attrs) depLabelList := "[\n" - for depLabel, _ := range depLabels { + for depLabel := range depLabels { depLabelList += fmt.Sprintf(" %q,\n", depLabel) } depLabelList += " ]" diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go index c5075e5b2..78e7b0e75 100644 --- a/bp2build/symlink_forest.go +++ b/bp2build/symlink_forest.go @@ -22,7 +22,7 @@ type node struct { children map[string]*node } -// Ensures that the a node for the given path exists in the tree and returns it. +// Ensures that the node for the given path exists in the tree and returns it. func ensureNodeExists(root *node, path string) *node { if path == "" { return root @@ -126,11 +126,11 @@ func plantSymlinkForestRecursive(cfg android.Config, topdir string, forestDir st buildFilesMap := readdirToMap(shared.JoinPath(topdir, buildFilesDir)) allEntries := make(map[string]bool) - for n, _ := range srcDirMap { + for n := range srcDirMap { allEntries[n] = true } - for n, _ := range buildFilesMap { + for n := range buildFilesMap { allEntries[n] = true } @@ -140,7 +140,7 @@ func plantSymlinkForestRecursive(cfg android.Config, topdir string, forestDir st os.Exit(1) } - for f, _ := range allEntries { + for f := range allEntries { if f[0] == '.' { continue // Ignore dotfiles } diff --git a/ui/build/build.go b/ui/build/build.go index ec42b7004..5b80b4df8 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -183,8 +183,8 @@ func checkRAM(ctx Context, config Config) { } } -// Build the tree. The 'what' argument can be used to chose which components of -// the build to run, via checking various bitmasks. +// Build the tree. Various flags in `config` govern which components of +// the build to run. func Build(ctx Context, config Config) { ctx.Verboseln("Starting build with args:", config.Arguments()) ctx.Verboseln("Environment:", config.Environment().Environ()) diff --git a/ui/build/soong.go b/ui/build/soong.go index 8992b4f07..cfcf99028 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -544,7 +544,7 @@ func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.Soon buf, err := os.ReadFile(soongBuildMetricsFile) if errors.Is(err, fs.ErrNotExist) { // Soong may not have run during this invocation - ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err) + ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err) return nil } else if err != nil { ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err)