Merge "Export apex_available_baseline to soong_injection" am: aafdf54f70
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2427237 Change-Id: I852cffbc856d44b8ae9be9419498b50134718ee8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
21f74f582d
5 changed files with 36 additions and 16 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue