Merge "Change init process of bp2buildAllowlist so the Soong plugin of bp2build allowlist can hookup properly."

This commit is contained in:
Wei Li
2022-05-20 20:36:40 +00:00
committed by Gerrit Code Review
3 changed files with 55 additions and 14 deletions

View File

@@ -321,25 +321,31 @@ func (a bp2BuildConversionAllowlist) SetMixedBuildsDisabledList(mixedBuildsDisab
return a return a
} }
var bp2buildAllowlist = NewBp2BuildAllowlist(). var bp2BuildAllowListKey = NewOnceKey("Bp2BuildAllowlist")
SetDefaultConfig(allowlists.Bp2buildDefaultConfig). var bp2buildAllowlist OncePer
SetKeepExistingBuildFile(allowlists.Bp2buildKeepExistingBuildFile).
SetModuleAlwaysConvertList(allowlists.Bp2buildModuleAlwaysConvertList). func getBp2BuildAllowList() bp2BuildConversionAllowlist {
SetModuleTypeAlwaysConvertList(allowlists.Bp2buildModuleTypeAlwaysConvertList). return bp2buildAllowlist.Once(bp2BuildAllowListKey, func() interface{} {
SetModuleDoNotConvertList(allowlists.Bp2buildModuleDoNotConvertList). return NewBp2BuildAllowlist().SetDefaultConfig(allowlists.Bp2buildDefaultConfig).
SetCcLibraryStaticOnlyList(allowlists.Bp2buildCcLibraryStaticOnlyList). SetKeepExistingBuildFile(allowlists.Bp2buildKeepExistingBuildFile).
SetMixedBuildsDisabledList(allowlists.MixedBuildsDisabledList) SetModuleAlwaysConvertList(allowlists.Bp2buildModuleAlwaysConvertList).
SetModuleTypeAlwaysConvertList(allowlists.Bp2buildModuleTypeAlwaysConvertList).
SetModuleDoNotConvertList(allowlists.Bp2buildModuleDoNotConvertList).
SetCcLibraryStaticOnlyList(allowlists.Bp2buildCcLibraryStaticOnlyList).
SetMixedBuildsDisabledList(allowlists.MixedBuildsDisabledList)
}).(bp2BuildConversionAllowlist)
}
// GenerateCcLibraryStaticOnly returns whether a cc_library module should only // GenerateCcLibraryStaticOnly returns whether a cc_library module should only
// generate a static version of itself based on the current global configuration. // generate a static version of itself based on the current global configuration.
func GenerateCcLibraryStaticOnly(moduleName string) bool { func GenerateCcLibraryStaticOnly(moduleName string) bool {
return bp2buildAllowlist.ccLibraryStaticOnly[moduleName] return getBp2BuildAllowList().ccLibraryStaticOnly[moduleName]
} }
// ShouldKeepExistingBuildFileForDir returns whether an existing BUILD file should be // ShouldKeepExistingBuildFileForDir returns whether an existing BUILD file should be
// added to the build symlink forest based on the current global configuration. // added to the build symlink forest based on the current global configuration.
func ShouldKeepExistingBuildFileForDir(dir string) bool { func ShouldKeepExistingBuildFileForDir(dir string) bool {
return shouldKeepExistingBuildFileForDir(bp2buildAllowlist, dir) return shouldKeepExistingBuildFileForDir(getBp2BuildAllowList(), dir)
} }
func shouldKeepExistingBuildFileForDir(allowlist bp2BuildConversionAllowlist, dir string) bool { func shouldKeepExistingBuildFileForDir(allowlist bp2BuildConversionAllowlist, dir string) bool {
@@ -392,7 +398,7 @@ func mixedBuildPossible(ctx BaseModuleContext) bool {
// variants of a cc_library. // variants of a cc_library.
return false return false
} }
return !bp2buildAllowlist.mixedBuildsDisabled[ctx.Module().Name()] return !getBp2BuildAllowList().mixedBuildsDisabled[ctx.Module().Name()]
} }
// ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel. // ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel.

View File

@@ -14,11 +14,12 @@
package android package android
import ( import (
"android/soong/android/allowlists"
"android/soong/bazel"
"fmt" "fmt"
"testing" "testing"
"android/soong/android/allowlists"
"android/soong/bazel"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
) )
@@ -386,3 +387,37 @@ func TestBp2BuildAllowlist(t *testing.T) {
}) })
} }
} }
func TestBp2buildAllowList(t *testing.T) {
allowlist := getBp2BuildAllowList()
for k, v := range allowlists.Bp2buildDefaultConfig {
if allowlist.defaultConfig[k] != v {
t.Errorf("bp2build default config of %s: expected: %v, got: %v", k, v, allowlist.defaultConfig[k])
}
}
for k, v := range allowlists.Bp2buildKeepExistingBuildFile {
if allowlist.keepExistingBuildFile[k] != v {
t.Errorf("bp2build keep existing build file of %s: expected: %v, got: %v", k, v, allowlist.keepExistingBuildFile[k])
}
}
for _, k := range allowlists.Bp2buildModuleTypeAlwaysConvertList {
if !allowlist.moduleTypeAlwaysConvert[k] {
t.Errorf("bp2build module type always convert of %s: expected: true, got: %v", k, allowlist.moduleTypeAlwaysConvert[k])
}
}
for _, k := range allowlists.Bp2buildModuleDoNotConvertList {
if !allowlist.moduleDoNotConvert[k] {
t.Errorf("bp2build module do not convert of %s: expected: true, got: %v", k, allowlist.moduleDoNotConvert[k])
}
}
for _, k := range allowlists.Bp2buildCcLibraryStaticOnlyList {
if !allowlist.ccLibraryStaticOnly[k] {
t.Errorf("bp2build cc library static only of %s: expected: true, got: %v", k, allowlist.ccLibraryStaticOnly[k])
}
}
for _, k := range allowlists.MixedBuildsDisabledList {
if !allowlist.mixedBuildsDisabled[k] {
t.Errorf("bp2build mix build disabled of %s: expected: true, got: %v", k, allowlist.mixedBuildsDisabled[k])
}
}
}

View File

@@ -558,7 +558,7 @@ func NewConfig(moduleListFile string, runGoTests bool, outDir, soongOutDir strin
} }
config.BazelContext, err = NewBazelContext(config) config.BazelContext, err = NewBazelContext(config)
config.bp2buildPackageConfig = bp2buildAllowlist config.bp2buildPackageConfig = getBp2BuildAllowList()
return Config{config}, err return Config{config}, err
} }