Fix genrule depending on disabled module with ALLOW_MISSING_DEPENDENCIES=true

If a genrule depends on a module that is disabled, in this case because
it is a device module in a host-only build, it can cause panics when
getPathsFromModuleDep retrieves a nil Path from the disabled module.
Treat disabled modules as missing dependencies.

Test: TestGenruleAllowMissingDependencies
Change-Id: I3c689c6b5505b21eaf7ae7cb93c00f96f438ac17
This commit is contained in:
Colin Cross
2021-03-22 17:05:59 -07:00
parent dca349a782
commit fa65cee27f
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)