From 07d75070a6788ebc5eb353816f0a3e00fdadb42b Mon Sep 17 00:00:00 2001 From: Yo Chiang Date: Fri, 5 Jun 2020 17:43:19 +0800 Subject: [PATCH] java_sdk_library: Require xml permission file only if it is generated Eliminates invalid LOCAL_REQUIRED_MODULES lines in the generated Android.mk entries. Bug: 7456955 Test: TH artifact noop Test: Add unittest to java/androidmk_test.go Test: m nothing and verify build rule doesn't contain invalid REQUIRED Change-Id: Ic8d7e6d08181f6a24fd2aa86479bb9303cfd9be8 --- java/androidmk_test.go | 33 +++++++++++++++++++++++++++++++++ java/sdk_library.go | 6 ++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/java/androidmk_test.go b/java/androidmk_test.go index 7daa6244f..d471fb7d5 100644 --- a/java/androidmk_test.go +++ b/java/androidmk_test.go @@ -169,3 +169,36 @@ func TestDistWithTag(t *testing.T) { t.Errorf("did not expect explicit DistFile, got %v", without_tag_entries[0].DistFile) } } + +func TestJavaSdkLibrary_RequireXmlPermissionFile(t *testing.T) { + ctx, config := testJava(t, ` + java_sdk_library { + name: "foo-shared_library", + srcs: ["a.java"], + } + java_sdk_library { + name: "foo-no_shared_library", + srcs: ["a.java"], + shared_library: false, + } + `) + + // Verify the existence of internal modules + ctx.ModuleForTests("foo-shared_library.xml", "android_common") + + testCases := []struct { + moduleName string + expected []string + }{ + {"foo-shared_library", []string{"foo-shared_library.xml"}}, + {"foo-no_shared_library", nil}, + } + for _, tc := range testCases { + mod := ctx.ModuleForTests(tc.moduleName, "android_common").Module() + entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] + actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"] + if !reflect.DeepEqual(tc.expected, actual) { + t.Errorf("Unexpected required modules - expected: %q, actual: %q", tc.expected, actual) + } + } +} diff --git a/java/sdk_library.go b/java/sdk_library.go index 503ad5914..071ae111b 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1042,8 +1042,10 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { return nil } entriesList := module.Library.AndroidMkEntries() - entries := &entriesList[0] - entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) + if module.sharedLibrary() { + entries := &entriesList[0] + entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) + } return entriesList }