Cosmetic Changes plus log errors
Test: N/A Bug: N/A Change-Id: I39e622a93270c922bdbea27ca79632a606431a2c
This commit is contained in:
@@ -32,14 +32,14 @@ import (
|
|||||||
// There is often a similar method for Bazel as there is for Soong path handling and should be used
|
// There is often a similar method for Bazel as there is for Soong path handling and should be used
|
||||||
// in similar circumstances
|
// in similar circumstances
|
||||||
//
|
//
|
||||||
// Bazel Soong
|
// Bazel Soong
|
||||||
//
|
// ==============================================================
|
||||||
// BazelLabelForModuleSrc PathForModuleSrc
|
// BazelLabelForModuleSrc PathForModuleSrc
|
||||||
// BazelLabelForModuleSrcExcludes PathForModuleSrcExcludes
|
// BazelLabelForModuleSrcExcludes PathForModuleSrcExcludes
|
||||||
// BazelLabelForModuleDeps n/a
|
// BazelLabelForModuleDeps n/a
|
||||||
// tbd PathForSource
|
// tbd PathForSource
|
||||||
// tbd ExistentPathsForSources
|
// tbd ExistentPathsForSources
|
||||||
// PathForBazelOut PathForModuleOut
|
// PathForBazelOut PathForModuleOut
|
||||||
//
|
//
|
||||||
// Use cases:
|
// Use cases:
|
||||||
// * Module contains a property (often tagged `android:"path"`) that expects paths *relative to the
|
// * 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
|
// cannot be resolved,the function will panic. This is often due to the dependency not being added
|
||||||
// via an AddDependency* method.
|
// 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.
|
// 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
|
// If a module is deemed to be convertible by bp2build, then it should rely on a
|
||||||
// BazelConversionPathContext for more functions for dep/path features.
|
// BazelConversionPathContext for more functions for dep/path features.
|
||||||
|
@@ -499,19 +499,11 @@ func TestSymlinkTree(t *testing.T) {
|
|||||||
|
|
||||||
func TestBazelOutRemovalFromInputDepsets(t *testing.T) {
|
func TestBazelOutRemovalFromInputDepsets(t *testing.T) {
|
||||||
const inputString = `{
|
const inputString = `{
|
||||||
"artifacts": [{
|
"artifacts": [
|
||||||
"id": 1,
|
{ "id": 1, "pathFragmentId": 10 },
|
||||||
"pathFragmentId": 10
|
{ "id": 2, "pathFragmentId": 20 },
|
||||||
}, {
|
{ "id": 3, "pathFragmentId": 30 },
|
||||||
"id": 2,
|
{ "id": 4, "pathFragmentId": 40 }],
|
||||||
"pathFragmentId": 20
|
|
||||||
}, {
|
|
||||||
"id": 3,
|
|
||||||
"pathFragmentId": 30
|
|
||||||
}, {
|
|
||||||
"id": 4,
|
|
||||||
"pathFragmentId": 40
|
|
||||||
}],
|
|
||||||
"depSetOfFiles": [{
|
"depSetOfFiles": [{
|
||||||
"id": 1111,
|
"id": 1111,
|
||||||
"directArtifactIds": [3 , 4]
|
"directArtifactIds": [3 , 4]
|
||||||
@@ -525,28 +517,14 @@ func TestBazelOutRemovalFromInputDepsets(t *testing.T) {
|
|||||||
"outputIds": [2],
|
"outputIds": [2],
|
||||||
"primaryOutputId": 1
|
"primaryOutputId": 1
|
||||||
}],
|
}],
|
||||||
"pathFragments": [{
|
"pathFragments": [
|
||||||
"id": 10,
|
{ "id": 10, "label": "input" },
|
||||||
"label": "input"
|
{ "id": 20, "label": "output" },
|
||||||
}, {
|
{ "id": 30, "label": "dep1", "parentId": 50 },
|
||||||
"id": 20,
|
{ "id": 40, "label": "dep2", "parentId": 60 },
|
||||||
"label": "output"
|
{ "id": 50, "label": "bazel_tools", "parentId": 60 },
|
||||||
}, {
|
{ "id": 60, "label": ".."}
|
||||||
"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))
|
actualBuildStatements, actualDepsets, _ := AqueryBuildStatements([]byte(inputString))
|
||||||
if len(actualDepsets) != 1 {
|
if len(actualDepsets) != 1 {
|
||||||
|
@@ -29,7 +29,9 @@ import (
|
|||||||
func Codegen(ctx *CodegenContext) CodegenMetrics {
|
func Codegen(ctx *CodegenContext) CodegenMetrics {
|
||||||
// This directory stores BUILD files that could be eventually checked-in.
|
// This directory stores BUILD files that could be eventually checked-in.
|
||||||
bp2buildDir := android.PathForOutput(ctx, "bp2build")
|
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)
|
res, errs := GenerateBazelTargets(ctx, true)
|
||||||
if len(errs) > 0 {
|
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.
|
// Get the output directory and create it if it doesn't exist.
|
||||||
func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext, dir string) android.OutputPath {
|
func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext, dir string) android.OutputPath {
|
||||||
dirPath := outputDir.Join(ctx, dir)
|
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
|
return dirPath
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,13 +64,13 @@ func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext,
|
|||||||
func writeFiles(ctx android.PathContext, outputDir android.OutputPath, files []BazelFile) {
|
func writeFiles(ctx android.PathContext, outputDir android.OutputPath, files []BazelFile) {
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
p := getOrCreateOutputDir(outputDir, ctx, f.Dir).Join(ctx, f.Basename)
|
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))
|
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
|
// These files are made editable to allow users to modify and iterate on them
|
||||||
// in the source tree.
|
// in the source tree.
|
||||||
return android.WriteFileToOutputDir(pathToFile, []byte(content), 0644)
|
return android.WriteFileToOutputDir(pathToFile, []byte(content), 0644)
|
||||||
|
@@ -161,22 +161,22 @@ type CodegenContext struct {
|
|||||||
unconvertedDepMode unconvertedDepsMode
|
unconvertedDepMode unconvertedDepsMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CodegenContext) Mode() CodegenMode {
|
func (ctx *CodegenContext) Mode() CodegenMode {
|
||||||
return c.mode
|
return ctx.mode
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodegenMode is an enum to differentiate code-generation modes.
|
// CodegenMode is an enum to differentiate code-generation modes.
|
||||||
type CodegenMode int
|
type CodegenMode int
|
||||||
|
|
||||||
const (
|
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.
|
// This mode is used for the Soong->Bazel build definition conversion.
|
||||||
Bp2Build CodegenMode = iota
|
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
|
// 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
|
// This mode is used for discovering and introspecting the existing Soong
|
||||||
// module graph.
|
// 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)
|
delete(props.Attrs, p)
|
||||||
}
|
}
|
||||||
attributes := propsToAttributes(props.Attrs)
|
attributes := propsToAttributes(props.Attrs)
|
||||||
|
|
||||||
depLabelList := "[\n"
|
depLabelList := "[\n"
|
||||||
for depLabel, _ := range depLabels {
|
for depLabel := range depLabels {
|
||||||
depLabelList += fmt.Sprintf(" %q,\n", depLabel)
|
depLabelList += fmt.Sprintf(" %q,\n", depLabel)
|
||||||
}
|
}
|
||||||
depLabelList += " ]"
|
depLabelList += " ]"
|
||||||
|
@@ -22,7 +22,7 @@ type node struct {
|
|||||||
children map[string]*node
|
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 {
|
func ensureNodeExists(root *node, path string) *node {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return root
|
return root
|
||||||
@@ -126,11 +126,11 @@ func plantSymlinkForestRecursive(cfg android.Config, topdir string, forestDir st
|
|||||||
buildFilesMap := readdirToMap(shared.JoinPath(topdir, buildFilesDir))
|
buildFilesMap := readdirToMap(shared.JoinPath(topdir, buildFilesDir))
|
||||||
|
|
||||||
allEntries := make(map[string]bool)
|
allEntries := make(map[string]bool)
|
||||||
for n, _ := range srcDirMap {
|
for n := range srcDirMap {
|
||||||
allEntries[n] = true
|
allEntries[n] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, _ := range buildFilesMap {
|
for n := range buildFilesMap {
|
||||||
allEntries[n] = true
|
allEntries[n] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ func plantSymlinkForestRecursive(cfg android.Config, topdir string, forestDir st
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
for f, _ := range allEntries {
|
for f := range allEntries {
|
||||||
if f[0] == '.' {
|
if f[0] == '.' {
|
||||||
continue // Ignore dotfiles
|
continue // Ignore dotfiles
|
||||||
}
|
}
|
||||||
|
@@ -183,8 +183,8 @@ func checkRAM(ctx Context, config Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the tree. The 'what' argument can be used to chose which components of
|
// Build the tree. Various flags in `config` govern which components of
|
||||||
// the build to run, via checking various bitmasks.
|
// the build to run.
|
||||||
func Build(ctx Context, config Config) {
|
func Build(ctx Context, config Config) {
|
||||||
ctx.Verboseln("Starting build with args:", config.Arguments())
|
ctx.Verboseln("Starting build with args:", config.Arguments())
|
||||||
ctx.Verboseln("Environment:", config.Environment().Environ())
|
ctx.Verboseln("Environment:", config.Environment().Environ())
|
||||||
|
@@ -544,7 +544,7 @@ func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.Soon
|
|||||||
buf, err := os.ReadFile(soongBuildMetricsFile)
|
buf, err := os.ReadFile(soongBuildMetricsFile)
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
// Soong may not have run during this invocation
|
// 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
|
return nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err)
|
ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err)
|
||||||
|
Reference in New Issue
Block a user