Merge "Fix issue where bazel-force-enabled-modules aren't actually analyzed." am: 4e37219e4c
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2494955 Change-Id: I1a65358259a2961d0479d58957a4f5b39ae7c971 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -84,8 +84,12 @@ func RegisterMixedBuildsMutator(ctx RegistrationContext) {
|
|||||||
func mixedBuildsPrepareMutator(ctx BottomUpMutatorContext) {
|
func mixedBuildsPrepareMutator(ctx BottomUpMutatorContext) {
|
||||||
if m := ctx.Module(); m.Enabled() {
|
if m := ctx.Module(); m.Enabled() {
|
||||||
if mixedBuildMod, ok := m.(MixedBuildBuildable); ok {
|
if mixedBuildMod, ok := m.(MixedBuildBuildable); ok {
|
||||||
if mixedBuildMod.IsMixedBuildSupported(ctx) && MixedBuildsEnabled(ctx) {
|
queueMixedBuild := mixedBuildMod.IsMixedBuildSupported(ctx) && MixedBuildsEnabled(ctx)
|
||||||
|
if queueMixedBuild {
|
||||||
mixedBuildMod.QueueBazelCall(ctx)
|
mixedBuildMod.QueueBazelCall(ctx)
|
||||||
|
} else if _, ok := ctx.Config().bazelForceEnabledModules[m.Name()]; ok {
|
||||||
|
// TODO(b/273910287) - remove this once --ensure_allowlist_integrity is added
|
||||||
|
ctx.ModuleErrorf("Attempted to force enable an unready module: %s. Did you forget to Bp2BuildDefaultTrue its directory?\n", m.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -592,12 +592,11 @@ func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error)
|
|||||||
setBazelMode(cmdArgs.BazelMode, "--bazel-mode", BazelProdMode)
|
setBazelMode(cmdArgs.BazelMode, "--bazel-mode", BazelProdMode)
|
||||||
setBazelMode(cmdArgs.BazelModeStaging, "--bazel-mode-staging", BazelStagingMode)
|
setBazelMode(cmdArgs.BazelModeStaging, "--bazel-mode-staging", BazelStagingMode)
|
||||||
|
|
||||||
config.BazelContext, err = NewBazelContext(config)
|
|
||||||
config.Bp2buildPackageConfig = GetBp2BuildAllowList()
|
|
||||||
|
|
||||||
for _, module := range strings.Split(cmdArgs.BazelForceEnabledModules, ",") {
|
for _, module := range strings.Split(cmdArgs.BazelForceEnabledModules, ",") {
|
||||||
config.bazelForceEnabledModules[module] = struct{}{}
|
config.bazelForceEnabledModules[module] = struct{}{}
|
||||||
}
|
}
|
||||||
|
config.BazelContext, err = NewBazelContext(config)
|
||||||
|
config.Bp2buildPackageConfig = GetBp2BuildAllowList()
|
||||||
|
|
||||||
return Config{config}, err
|
return Config{config}, err
|
||||||
}
|
}
|
||||||
@@ -1934,3 +1933,8 @@ func (c *config) BuildFromTextStub() bool {
|
|||||||
func (c *config) SetBuildFromTextStub(b bool) {
|
func (c *config) SetBuildFromTextStub(b bool) {
|
||||||
c.buildFromTextStub = b
|
c.buildFromTextStub = b
|
||||||
}
|
}
|
||||||
|
func (c *config) AddForceEnabledModules(forceEnabled []string) {
|
||||||
|
for _, forceEnabledModule := range forceEnabled {
|
||||||
|
c.bazelForceEnabledModules[forceEnabledModule] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -65,6 +65,7 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
|
|||||||
BuildMode: BazelProdMode,
|
BuildMode: BazelProdMode,
|
||||||
mixedBuildDisabledModules: make(map[string]struct{}),
|
mixedBuildDisabledModules: make(map[string]struct{}),
|
||||||
mixedBuildEnabledModules: make(map[string]struct{}),
|
mixedBuildEnabledModules: make(map[string]struct{}),
|
||||||
|
bazelForceEnabledModules: make(map[string]struct{}),
|
||||||
}
|
}
|
||||||
config.deviceConfig = &deviceConfig{
|
config.deviceConfig = &deviceConfig{
|
||||||
config: config,
|
config: config,
|
||||||
|
@@ -321,6 +321,9 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers
|
|||||||
// target, each of a different rule class.
|
// target, each of a different rule class.
|
||||||
metrics.IncrementRuleClassCount(t.ruleClass)
|
metrics.IncrementRuleClassCount(t.ruleClass)
|
||||||
}
|
}
|
||||||
|
} else if _, ok := ctx.Config().BazelModulesForceEnabledByFlag()[m.Name()]; ok && m.Name() != "" {
|
||||||
|
err := fmt.Errorf("Force Enabled Module %s not converted", m.Name())
|
||||||
|
errs = append(errs, err)
|
||||||
} else {
|
} else {
|
||||||
metrics.AddUnconvertedModule(moduleType)
|
metrics.AddUnconvertedModule(moduleType)
|
||||||
return
|
return
|
||||||
|
@@ -1175,6 +1175,8 @@ func TestAllowlistingBp2buildTargetsWithConfig(t *testing.T) {
|
|||||||
bp2buildConfig allowlists.Bp2BuildConfig
|
bp2buildConfig allowlists.Bp2BuildConfig
|
||||||
checkDir string
|
checkDir string
|
||||||
fs map[string]string
|
fs map[string]string
|
||||||
|
forceEnabledModules []string
|
||||||
|
expectedErrorMessages []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "test bp2build config package and subpackages config",
|
description: "test bp2build config package and subpackages config",
|
||||||
@@ -1237,6 +1239,24 @@ filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } }
|
|||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "test force-enabled errors out",
|
||||||
|
moduleTypeUnderTest: "filegroup",
|
||||||
|
moduleTypeUnderTestFactory: android.FileGroupFactory,
|
||||||
|
expectedCount: map[string]int{
|
||||||
|
"migrated": 0,
|
||||||
|
"not_migrated": 0,
|
||||||
|
},
|
||||||
|
bp2buildConfig: allowlists.Bp2BuildConfig{
|
||||||
|
"migrated/but_not_really": allowlists.Bp2BuildDefaultFalse,
|
||||||
|
"not_migrated": allowlists.Bp2BuildDefaultFalse,
|
||||||
|
},
|
||||||
|
fs: map[string]string{
|
||||||
|
"migrated/Android.bp": `filegroup { name: "a" }`,
|
||||||
|
},
|
||||||
|
forceEnabledModules: []string{"a"},
|
||||||
|
expectedErrorMessages: []string{"Force Enabled Module a not converted"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := "."
|
dir := "."
|
||||||
@@ -1252,6 +1272,7 @@ filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } }
|
|||||||
fs[f] = []byte(content)
|
fs[f] = []byte(content)
|
||||||
}
|
}
|
||||||
config := android.TestConfig(buildDir, nil, "", fs)
|
config := android.TestConfig(buildDir, nil, "", fs)
|
||||||
|
config.AddForceEnabledModules(testCase.forceEnabledModules)
|
||||||
ctx := android.NewTestContext(config)
|
ctx := android.NewTestContext(config)
|
||||||
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
|
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
|
||||||
allowlist := android.NewBp2BuildAllowlist().SetDefaultConfig(testCase.bp2buildConfig)
|
allowlist := android.NewBp2BuildAllowlist().SetDefaultConfig(testCase.bp2buildConfig)
|
||||||
@@ -1268,7 +1289,7 @@ filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } }
|
|||||||
// For each directory, test that the expected number of generated targets is correct.
|
// For each directory, test that the expected number of generated targets is correct.
|
||||||
for dir, expectedCount := range testCase.expectedCount {
|
for dir, expectedCount := range testCase.expectedCount {
|
||||||
bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
|
bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
|
||||||
android.FailIfErrored(t, err)
|
android.CheckErrorsAgainstExpectations(t, err, testCase.expectedErrorMessages)
|
||||||
if actualCount := len(bazelTargets); actualCount != expectedCount {
|
if actualCount := len(bazelTargets); actualCount != expectedCount {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"%s: Expected %d bazel target for %s package, got %d",
|
"%s: Expected %d bazel target for %s package, got %d",
|
||||||
|
@@ -63,4 +63,37 @@ EOF
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_force_enabled_modules {
|
||||||
|
setup
|
||||||
|
# b/273910287 - test force enable modules
|
||||||
|
mkdir -p soong_tests/a/b
|
||||||
|
cat > soong_tests/a/b/Android.bp <<'EOF'
|
||||||
|
genrule {
|
||||||
|
name: "touch-file",
|
||||||
|
out: ["fake-out.txt"],
|
||||||
|
cmd: "touch $(out)",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}
|
||||||
|
|
||||||
|
genrule {
|
||||||
|
name: "unenabled-touch-file",
|
||||||
|
out: ["fake-out2.txt"],
|
||||||
|
cmd: "touch $(out)",
|
||||||
|
bazel_module: { bp2build_available: false },
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
run_soong --bazel-mode-staging --bazel-force-enabled-modules=touch-file nothing
|
||||||
|
local bazel_contained=`grep out/soong/.intermediates/soong_tests/a/b/touch-file/gen/fake-out.txt out/soong/build.ninja`
|
||||||
|
if [[ $bazel_contained == '' ]]; then
|
||||||
|
fail "Bazel actions not found for force-enabled module"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local exit_code=`run_soong --bazel-force-enabled-modules=unenabled-touch-file nothing`
|
||||||
|
|
||||||
|
if [[ $exit_code -ne 1 ]]; then
|
||||||
|
fail "Expected failure due to force-enabling an unenabled module "
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
scan_and_run_tests
|
scan_and_run_tests
|
Reference in New Issue
Block a user