From d48f3c3885d0b0ce00a3a58a1492a2bc46f23e5a Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 23 Aug 2019 11:18:57 +0900 Subject: soong: Add tests for depending on disabled module This will check if direct deps of android.Module type is "Enabled()". Previously, this is checked only if a module calls VisitDeps*() functions in GenerateAndroidBuildActions(). Most modules call VisitDeps*() in GenerateAndroidBuildActions(), but some modules don't. For example, "apex" module calls WalkDepsBlueprint() or VisitDirectDepsBlueprint() since it exceptionally depends on non-android.Module modules. Therefore, when an apex module depends on disabled(enabled:false) module, build fails with panic, which is fixed by this change. Test: m # runs soong tests Change-Id: I81c5c148bbd51a253d2904690eb76ae7b6df1a0f --- android/module_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'android/module_test.go') diff --git a/android/module_test.go b/android/module_test.go index c790a6854..6dca29f79 100644 --- a/android/module_test.go +++ b/android/module_test.go @@ -14,7 +14,9 @@ package android -import "testing" +import ( + "testing" +) func TestSrcIsModule(t *testing.T) { type args struct { @@ -139,3 +141,55 @@ func TestSrcIsModuleWithTag(t *testing.T) { }) } } + +type depsModule struct { + ModuleBase + props struct { + Deps []string + } +} + +func (m *depsModule) GenerateAndroidBuildActions(ctx ModuleContext) { +} + +func (m *depsModule) DepsMutator(ctx BottomUpMutatorContext) { + ctx.AddDependency(ctx.Module(), nil, m.props.Deps...) +} + +func depsModuleFactory() Module { + m := &depsModule{} + m.AddProperties(&m.props) + InitAndroidModule(m) + return m +} + +func TestErrorDependsOnDisabledModule(t *testing.T) { + ctx := NewTestContext() + ctx.RegisterModuleType("deps", ModuleFactoryAdaptor(depsModuleFactory)) + + bp := ` + deps { + name: "foo", + deps: ["bar"], + } + deps { + name: "bar", + enabled: false, + } + ` + + mockFS := map[string][]byte{ + "Android.bp": []byte(bp), + } + + ctx.MockFileSystem(mockFS) + + ctx.Register() + + config := TestConfig(buildDir, nil) + + _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) + FailIfErrored(t, errs) + _, errs = ctx.PrepareBuildActions(config) + FailIfNoMatchingErrors(t, `module "foo": depends on disabled module "bar"`, errs) +} -- cgit v1.2.3-59-g8ed1b