Merge "Fix genrule depending on disabled module with ALLOW_MISSING_DEPENDENCIES=true" am: 7b1debfcbc

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

Change-Id: I4115278a344338b19c60de705646fd73748690ca
This commit is contained in:
Treehugger Robot 2021-03-24 04:43:15 +00:00 committed by Automerger Merge Worker
commit ab200bba0c
2 changed files with 54 additions and 0 deletions

View File

@ -511,6 +511,9 @@ func getPathsFromModuleDep(ctx ModuleWithDepsPathContext, path, moduleName, tag
if module == nil {
return nil, missingDependencyError{[]string{moduleName}}
}
if aModule, ok := module.(Module); ok && !aModule.Enabled() {
return nil, missingDependencyError{[]string{moduleName}}
}
if outProducer, ok := module.(OutputFileProducer); ok {
outputFiles, err := outProducer.OutputFiles(tag)
if err != nil {

View File

@ -36,6 +36,7 @@ var prepareForGenRuleTest = android.GroupFixturePreparers(
PrepareForTestWithGenRuleBuildComponents,
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("tool", toolFactory)
ctx.RegisterModuleType("output", outputProducerFactory)
}),
android.FixtureMergeMockFs(android.MockFS{
"tool": nil,
@ -653,6 +654,35 @@ func TestGenruleDefaults(t *testing.T) {
android.AssertDeepEquals(t, "srcs", expectedSrcs, gen.properties.Srcs)
}
func TestGenruleAllowMissingDependencies(t *testing.T) {
bp := `
output {
name: "disabled",
enabled: false,
}
genrule {
name: "gen",
srcs: [
":disabled",
],
out: ["out"],
cmd: "cat $(in) > $(out)",
}
`
result := prepareForGenRuleTest.Extend(
android.FixtureModifyConfigAndContext(
func(config android.Config, ctx *android.TestContext) {
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
ctx.SetAllowMissingDependencies(true)
})).RunTestWithBp(t, bp)
gen := result.ModuleForTests("gen", "").Output("out")
if gen.Rule != android.ErrorRule {
t.Errorf("Expected missing dependency error rule for gen, got %q", gen.Rule.String())
}
}
func TestGenruleWithBazel(t *testing.T) {
bp := `
genrule {
@ -697,3 +727,24 @@ func (t *testTool) HostToolPath() android.OptionalPath {
}
var _ android.HostToolProvider = (*testTool)(nil)
type testOutputProducer struct {
android.ModuleBase
outputFile android.Path
}
func outputProducerFactory() android.Module {
module := &testOutputProducer{}
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
return module
}
func (t *testOutputProducer) GenerateAndroidBuildActions(ctx android.ModuleContext) {
t.outputFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "bin"), ctx.ModuleName(), android.PathForOutput(ctx, ctx.ModuleName()))
}
func (t *testOutputProducer) OutputFiles(tag string) (android.Paths, error) {
return android.Paths{t.outputFile}, nil
}
var _ android.OutputFileProducer = (*testOutputProducer)(nil)