summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/bp2build.go10
-rw-r--r--bp2build/bp2build.go21
-rw-r--r--bp2build/conversion.go12
-rw-r--r--bp2build/conversion_test.go6
-rw-r--r--cmd/soong_build/main.go3
5 files changed, 36 insertions, 16 deletions
diff --git a/apex/bp2build.go b/apex/bp2build.go
index d28f5122e..a3dda83b1 100644
--- a/apex/bp2build.go
+++ b/apex/bp2build.go
@@ -15,16 +15,22 @@ package apex
import (
"android/soong/android"
+ "encoding/json"
"strings"
)
// This file contains the bp2build integration for the apex package.
// Export constants as Starlark using bp2build to Bazel.
-func BazelApexToolchainVars() string {
+func BazelApexToolchainVars() (string, error) {
+ marshalled, err := json.Marshal(apexAvailBaseline)
+ if err != nil {
+ return "", err
+ }
content := []string{
"# GENERATED BY SOONG. DO NOT EDIT.",
"default_manifest_version = " + android.DefaultUpdatableModuleVersion, // constants.go is different in every branch.
+ "apex_available_baseline = json.decode('''" + string(marshalled) + "''')",
}
- return strings.Join(content, "\n")
+ return strings.Join(content, "\n"), nil
}
diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go
index 86b9b27e2..062eba88a 100644
--- a/bp2build/bp2build.go
+++ b/bp2build/bp2build.go
@@ -45,8 +45,12 @@ func Codegen(ctx *CodegenContext) *CodegenMetrics {
bp2buildFiles := CreateBazelFiles(ctx.Config(), nil, res.buildFileToTargets, ctx.mode)
writeFiles(ctx, bp2buildDir, bp2buildFiles)
- soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName)
- writeFiles(ctx, soongInjectionDir, CreateSoongInjectionDirFiles(ctx, res.metrics))
+ injectionFiles, err := CreateSoongInjectionDirFiles(ctx, res.metrics)
+ if err != nil {
+ fmt.Printf("%s\n", err.Error())
+ os.Exit(1)
+ }
+ writeFiles(ctx, android.PathForOutput(ctx, bazel.SoongInjectionDirName), injectionFiles)
return &res.metrics
}
@@ -55,17 +59,20 @@ func Codegen(ctx *CodegenContext) *CodegenMetrics {
// This includes
// 1. config value(s) that are hardcoded in Soong
// 2. product_config variables
-func CreateSoongInjectionDirFiles(ctx *CodegenContext, metrics CodegenMetrics) []BazelFile {
+func CreateSoongInjectionDirFiles(ctx *CodegenContext, metrics CodegenMetrics) ([]BazelFile, error) {
var ret []BazelFile
productConfigFiles, err := CreateProductConfigFiles(ctx)
if err != nil {
- fmt.Printf("ERROR: %s", err.Error())
- os.Exit(1)
+ return nil, err
}
ret = append(ret, productConfigFiles...)
- ret = append(ret, soongInjectionFiles(ctx.Config(), metrics)...)
- return ret
+ injectionFiles, err := soongInjectionFiles(ctx.Config(), metrics)
+ if err != nil {
+ return nil, err
+ }
+ ret = append(ret, injectionFiles...)
+ return ret, nil
}
// Get the output directory and create it if it doesn't exist.
diff --git a/bp2build/conversion.go b/bp2build/conversion.go
index 5b3e19fa2..73df67555 100644
--- a/bp2build/conversion.go
+++ b/bp2build/conversion.go
@@ -22,7 +22,7 @@ type BazelFile struct {
}
// PRIVATE: Use CreateSoongInjectionDirFiles instead
-func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []BazelFile {
+func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) ([]BazelFile, error) {
var files []BazelFile
files = append(files, newFile("android", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
@@ -36,7 +36,11 @@ func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []BazelFile
files = append(files, newFile("java_toolchain", "constants.bzl", java_config.BazelJavaToolchainVars(cfg)))
files = append(files, newFile("apex_toolchain", GeneratedBuildFileName, "")) // Creates a //apex_toolchain package.
- files = append(files, newFile("apex_toolchain", "constants.bzl", apex.BazelApexToolchainVars()))
+ apexToolchainVars, err := apex.BazelApexToolchainVars()
+ if err != nil {
+ return nil, err
+ }
+ files = append(files, newFile("apex_toolchain", "constants.bzl", apexToolchainVars))
files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.Serialize().ConvertedModules, "\n")))
@@ -52,7 +56,7 @@ func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []BazelFile
apiLevelsContent, err := json.Marshal(android.GetApiLevelsMap(cfg))
if err != nil {
- panic(err)
+ return nil, err
}
files = append(files, newFile("api_levels", GeneratedBuildFileName, `exports_files(["api_levels.json"])`))
files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent)))
@@ -64,7 +68,7 @@ func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []BazelFile
files = append(files, newFile("allowlists", "mixed_build_prod_allowlist.txt", strings.Join(android.GetBazelEnabledModules(android.BazelProdMode), "\n")+"\n"))
files = append(files, newFile("allowlists", "mixed_build_staging_allowlist.txt", strings.Join(android.GetBazelEnabledModules(android.BazelStagingMode), "\n")+"\n"))
- return files
+ return files, nil
}
func CreateBazelFiles(
diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go
index 8c240934c..8c1d2ae5b 100644
--- a/bp2build/conversion_test.go
+++ b/bp2build/conversion_test.go
@@ -84,8 +84,10 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
testConfig := android.TestConfig("", make(map[string]string), "", make(map[string][]byte))
- files := soongInjectionFiles(testConfig, CreateCodegenMetrics())
-
+ files, err := soongInjectionFiles(testConfig, CreateCodegenMetrics())
+ if err != nil {
+ t.Error(err)
+ }
expectedFilePaths := []bazelFilepath{
{
dir: "android",
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index c005f7c27..5f27fa783 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -178,7 +178,8 @@ func runApiBp2build(ctx *android.Context, extraNinjaDeps []string) string {
ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...)
// Create soong_injection repository
- soongInjectionFiles := bp2build.CreateSoongInjectionDirFiles(codegenContext, bp2build.CreateCodegenMetrics())
+ soongInjectionFiles, err := bp2build.CreateSoongInjectionDirFiles(codegenContext, bp2build.CreateCodegenMetrics())
+ maybeQuit(err, "")
absoluteSoongInjectionDir := shared.JoinPath(topDir, ctx.Config().SoongOutDir(), bazel.SoongInjectionDirName)
for _, file := range soongInjectionFiles {
// The API targets in api_bp2build workspace do not have any dependency on api_bp2build.