Output informational messages only when BP2BUILD_VERBOSE is set.
Test: manual Change-Id: Ieeb00a002e07b04449d70614ce205c47c1dd7bce
This commit is contained in:
@@ -40,7 +40,7 @@ func Codegen(ctx *CodegenContext) CodegenMetrics {
|
||||
fmt.Printf("ERROR: Encountered %d error(s): \nERROR: %s", len(errs), strings.Join(errMsgs, "\n"))
|
||||
os.Exit(1)
|
||||
}
|
||||
bp2buildFiles := CreateBazelFiles(nil, res.buildFileToTargets, ctx.mode)
|
||||
bp2buildFiles := CreateBazelFiles(ctx.Config(), nil, res.buildFileToTargets, ctx.mode)
|
||||
writeFiles(ctx, bp2buildDir, bp2buildFiles)
|
||||
|
||||
soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName)
|
||||
|
@@ -189,7 +189,7 @@ func TestGenerateSoongModuleBzl(t *testing.T) {
|
||||
content: "irrelevant",
|
||||
},
|
||||
}
|
||||
files := CreateBazelFiles(ruleShims, make(map[string]BazelTargets), QueryView)
|
||||
files := CreateBazelFiles(android.NullConfig("out", "out/soong"), ruleShims, make(map[string]BazelTargets), QueryView)
|
||||
|
||||
var actualSoongModuleBzl BazelFile
|
||||
for _, f := range files {
|
||||
|
@@ -50,6 +50,7 @@ func convertedModules(convertedModules []string) string {
|
||||
}
|
||||
|
||||
func CreateBazelFiles(
|
||||
cfg android.Config,
|
||||
ruleShims map[string]RuleShim,
|
||||
buildToTargets map[string]BazelTargets,
|
||||
mode CodegenMode) []BazelFile {
|
||||
@@ -74,16 +75,19 @@ func CreateBazelFiles(
|
||||
files = append(files, newFile(bazelRulesSubDir, "soong_module.bzl", generateSoongModuleBzl(ruleShims)))
|
||||
}
|
||||
|
||||
files = append(files, createBuildFiles(buildToTargets, mode)...)
|
||||
files = append(files, createBuildFiles(cfg, buildToTargets, mode)...)
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
func createBuildFiles(buildToTargets map[string]BazelTargets, mode CodegenMode) []BazelFile {
|
||||
func createBuildFiles(cfg android.Config, buildToTargets map[string]BazelTargets, mode CodegenMode) []BazelFile {
|
||||
files := make([]BazelFile, 0, len(buildToTargets))
|
||||
warnNotWriting := cfg.IsEnvTrue("BP2BUILD_VERBOSE")
|
||||
for _, dir := range android.SortedStringKeys(buildToTargets) {
|
||||
if mode == Bp2Build && android.ShouldKeepExistingBuildFileForDir(dir) {
|
||||
fmt.Printf("[bp2build] Not writing generated BUILD file for dir: '%s'\n", dir)
|
||||
if warnNotWriting {
|
||||
fmt.Printf("[bp2build] Not writing generated BUILD file for dir: '%s'\n", dir)
|
||||
}
|
||||
continue
|
||||
}
|
||||
targets := buildToTargets[dir]
|
||||
|
@@ -27,7 +27,8 @@ type bazelFilepath struct {
|
||||
}
|
||||
|
||||
func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
|
||||
files := CreateBazelFiles(map[string]RuleShim{}, map[string]BazelTargets{}, QueryView)
|
||||
files := CreateBazelFiles(android.NullConfig("out", "out/soong"),
|
||||
map[string]RuleShim{}, map[string]BazelTargets{}, QueryView)
|
||||
expectedFilePaths := []bazelFilepath{
|
||||
{
|
||||
dir: "",
|
||||
|
@@ -116,8 +116,6 @@ func (metrics *CodegenMetrics) Write(dir string) {
|
||||
}
|
||||
if _, err := os.Stat(metricsFile); err != nil {
|
||||
fail(err, "MISSING BP2BUILD METRICS OUTPUT: Failed to `stat` %s", metricsFile)
|
||||
} else {
|
||||
fmt.Printf("\nWrote bp2build metrics to: %s\n", metricsFile)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -114,7 +115,7 @@ func isDir(path string, fi os.FileInfo) bool {
|
||||
// contain every file in buildFilesDir and srcDir excluding the files in
|
||||
// exclude. Collects every directory encountered during the traversal of srcDir
|
||||
// into acc.
|
||||
func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir string, srcDir string, exclude *node, acc *[]string, okay *bool) {
|
||||
func plantSymlinkForestRecursive(cfg android.Config, topdir string, forestDir string, buildFilesDir string, srcDir string, exclude *node, acc *[]string, okay *bool) {
|
||||
if exclude != nil && exclude.excluded {
|
||||
// This directory is not needed, bail out
|
||||
return
|
||||
@@ -179,7 +180,7 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir
|
||||
if bDir && excludeChild != nil {
|
||||
// Not in the source tree, but we have to exclude something from under
|
||||
// this subtree, so descend
|
||||
plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
|
||||
plantSymlinkForestRecursive(cfg, topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
|
||||
} else {
|
||||
// Not in the source tree, symlink BUILD file
|
||||
symlinkIntoForest(topdir, forestChild, buildFilesChild)
|
||||
@@ -188,19 +189,21 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir
|
||||
if sDir && excludeChild != nil {
|
||||
// Not in the build file tree, but we have to exclude something from
|
||||
// under this subtree, so descend
|
||||
plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
|
||||
plantSymlinkForestRecursive(cfg, topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
|
||||
} else {
|
||||
// Not in the build file tree, symlink source tree, carry on
|
||||
symlinkIntoForest(topdir, forestChild, srcChild)
|
||||
}
|
||||
} else if sDir && bDir {
|
||||
// Both are directories. Descend.
|
||||
plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
|
||||
plantSymlinkForestRecursive(cfg, topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
|
||||
} else if !sDir && !bDir {
|
||||
// Neither is a directory. Prioritize BUILD files generated by bp2build
|
||||
// over any BUILD file imported into external/.
|
||||
fmt.Fprintf(os.Stderr, "Both '%s' and '%s' exist, symlinking the former to '%s'\n",
|
||||
buildFilesChild, srcChild, forestChild)
|
||||
if cfg.IsEnvTrue("BP2BUILD_VERBOSE") {
|
||||
fmt.Fprintf(os.Stderr, "Both '%s' and '%s' exist, symlinking the former to '%s'\n",
|
||||
buildFilesChild, srcChild, forestChild)
|
||||
}
|
||||
symlinkIntoForest(topdir, forestChild, buildFilesChild)
|
||||
} else {
|
||||
// Both exist and one is a file. This is an error.
|
||||
@@ -216,12 +219,12 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir
|
||||
// "srcDir" while excluding paths listed in "exclude". Returns the set of paths
|
||||
// under srcDir on which readdir() had to be called to produce the symlink
|
||||
// forest.
|
||||
func PlantSymlinkForest(topdir string, forest string, buildFiles string, srcDir string, exclude []string) []string {
|
||||
func PlantSymlinkForest(cfg android.Config, topdir string, forest string, buildFiles string, srcDir string, exclude []string) []string {
|
||||
deps := make([]string, 0)
|
||||
os.RemoveAll(shared.JoinPath(topdir, forest))
|
||||
excludeTree := treeFromExcludePathList(exclude)
|
||||
okay := true
|
||||
plantSymlinkForestRecursive(topdir, forest, buildFiles, srcDir, excludeTree, &deps, &okay)
|
||||
plantSymlinkForestRecursive(cfg, topdir, forest, buildFiles, srcDir, excludeTree, &deps, &okay)
|
||||
if !okay {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@@ -552,7 +552,7 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
|
||||
excludes = append(excludes, getTemporaryExcludes()...)
|
||||
|
||||
symlinkForestDeps := bp2build.PlantSymlinkForest(
|
||||
topDir, workspaceRoot, generatedRoot, ".", excludes)
|
||||
configuration, topDir, workspaceRoot, generatedRoot, ".", excludes)
|
||||
|
||||
ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...)
|
||||
ninjaDeps = append(ninjaDeps, symlinkForestDeps...)
|
||||
@@ -566,7 +566,9 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
|
||||
// Only report metrics when in bp2build mode. The metrics aren't relevant
|
||||
// for queryview, since that's a total repo-wide conversion and there's a
|
||||
// 1:1 mapping for each module.
|
||||
metrics.Print()
|
||||
if configuration.IsEnvTrue("BP2BUILD_VERBOSE") {
|
||||
metrics.Print()
|
||||
}
|
||||
writeBp2BuildMetrics(&metrics, configuration, eventHandler)
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,8 @@ func createBazelQueryView(ctx *bp2build.CodegenContext, bazelQueryViewDir string
|
||||
panic(err)
|
||||
}
|
||||
|
||||
filesToWrite := bp2build.CreateBazelFiles(ruleShims, res.BuildDirToTargets(), bp2build.QueryView)
|
||||
filesToWrite := bp2build.CreateBazelFiles(ctx.Config(), ruleShims, res.BuildDirToTargets(),
|
||||
bp2build.QueryView)
|
||||
for _, f := range filesToWrite {
|
||||
if err := writeReadOnlyFile(bazelQueryViewDir, f); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user