Merge "Allow exporting bazel mixed build allowlists to simple text files" am: abc182cc94

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2356322

Change-Id: Ic2f7d46dac7deb5ddb3c05d8219faefcb4c24d51
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Cole Faust
2022-12-19 03:50:55 +00:00
committed by Automerger Merge Worker
3 changed files with 38 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort"
"strings" "strings"
"sync" "sync"
@@ -374,7 +375,7 @@ func (m noopBazelContext) AqueryDepsets() []bazel.AqueryDepset {
return []bazel.AqueryDepset{} return []bazel.AqueryDepset{}
} }
func NewBazelContext(c *config) (BazelContext, error) { func GetBazelEnabledAndDisabledModules(buildMode SoongBuildMode, forceEnabled map[string]struct{}) (map[string]bool, map[string]bool) {
disabledModules := map[string]bool{} disabledModules := map[string]bool{}
enabledModules := map[string]bool{} enabledModules := map[string]bool{}
addToStringSet := func(set map[string]bool, items []string) { addToStringSet := func(set map[string]bool, items []string) {
@@ -383,17 +384,17 @@ func NewBazelContext(c *config) (BazelContext, error) {
} }
} }
switch c.BuildMode { switch buildMode {
case BazelProdMode: case BazelProdMode:
addToStringSet(enabledModules, allowlists.ProdMixedBuildsEnabledList) addToStringSet(enabledModules, allowlists.ProdMixedBuildsEnabledList)
for enabledAdHocModule := range c.BazelModulesForceEnabledByFlag() { for enabledAdHocModule := range forceEnabled {
enabledModules[enabledAdHocModule] = true enabledModules[enabledAdHocModule] = true
} }
case BazelStagingMode: case BazelStagingMode:
// Staging mode includes all prod modules plus all staging modules. // Staging mode includes all prod modules plus all staging modules.
addToStringSet(enabledModules, allowlists.ProdMixedBuildsEnabledList) addToStringSet(enabledModules, allowlists.ProdMixedBuildsEnabledList)
addToStringSet(enabledModules, allowlists.StagingMixedBuildsEnabledList) addToStringSet(enabledModules, allowlists.StagingMixedBuildsEnabledList)
for enabledAdHocModule := range c.BazelModulesForceEnabledByFlag() { for enabledAdHocModule := range forceEnabled {
enabledModules[enabledAdHocModule] = true enabledModules[enabledAdHocModule] = true
} }
case BazelDevMode: case BazelDevMode:
@@ -405,9 +406,30 @@ func NewBazelContext(c *config) (BazelContext, error) {
} }
addToStringSet(disabledModules, allowlists.MixedBuildsDisabledList) addToStringSet(disabledModules, allowlists.MixedBuildsDisabledList)
default: default:
panic("Expected BazelProdMode, BazelStagingMode, or BazelDevMode")
}
return enabledModules, disabledModules
}
func GetBazelEnabledModules(buildMode SoongBuildMode) []string {
enabledModules, disabledModules := GetBazelEnabledAndDisabledModules(buildMode, nil)
enabledList := make([]string, 0, len(enabledModules))
for module := range enabledModules {
if !disabledModules[module] {
enabledList = append(enabledList, module)
}
}
sort.Strings(enabledList)
return enabledList
}
func NewBazelContext(c *config) (BazelContext, error) {
if c.BuildMode != BazelProdMode && c.BuildMode != BazelStagingMode && c.BuildMode != BazelDevMode {
return noopBazelContext{}, nil return noopBazelContext{}, nil
} }
enabledModules, disabledModules := GetBazelEnabledAndDisabledModules(c.BuildMode, c.BazelModulesForceEnabledByFlag())
paths := bazelPaths{ paths := bazelPaths{
soongOutDir: c.soongOutDir, soongOutDir: c.soongOutDir,
} }

View File

@@ -55,6 +55,10 @@ func CreateSoongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []Baz
files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent))) files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent)))
files = append(files, newFile("api_levels", "api_levels.bzl", android.StarlarkApiLevelConfigs(cfg))) files = append(files, newFile("api_levels", "api_levels.bzl", android.StarlarkApiLevelConfigs(cfg)))
// TODO(b/262781701): Create an alternate soong_build entrypoint for writing out these files only when requested
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
} }

View File

@@ -147,6 +147,14 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
dir: "api_levels", dir: "api_levels",
basename: "api_levels.bzl", basename: "api_levels.bzl",
}, },
{
dir: "allowlists",
basename: "mixed_build_prod_allowlist.txt",
},
{
dir: "allowlists",
basename: "mixed_build_staging_allowlist.txt",
},
} }
if len(files) != len(expectedFilePaths) { if len(files) != len(expectedFilePaths) {