From 55bd98b2d94c841f697e1ab46cc21e28ef79162f Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 11 Dec 2019 17:27:07 +0900 Subject: [PATCH] AndroidMk for the hostdex library has separate AndroidMkEntries Previously, the -hostdex library was emitted using the ExtraFooters. Now, it has its own AndroidMkEntries, which can be returned together with the AndroidMkEntries for the main library. Bug: 128708192 Test: m Change-Id: Ic9eb0d3839572ed340ccbc5fc6c4b54241e1cb24 --- java/androidmk.go | 160 +++++++++++++++++++++-------------------- java/androidmk_test.go | 48 +++++++++---- 2 files changed, 115 insertions(+), 93 deletions(-) diff --git a/java/androidmk.go b/java/androidmk.go index d94c9b8fd..f4e3c3481 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -17,99 +17,103 @@ package java import ( "fmt" "io" - "strings" "android/soong/android" ) -func (library *Library) AndroidMkHostDex(w io.Writer, name string, entries *android.AndroidMkEntries) { - if Bool(library.deviceProperties.Hostdex) && !library.Host() { - fmt.Fprintln(w, "include $(CLEAR_VARS)") - fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex") - fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") - fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES") - if library.dexJarFile != nil { - fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.dexJarFile.String()) - } else { - fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationAndResourcesJar.String()) - } - if library.dexJarFile != nil { - fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String()) - } - fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String()) - fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String()) - if len(entries.Required) > 0 { - fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(entries.Required, " ")) - } - if len(entries.Host_required) > 0 { - fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES :=", strings.Join(entries.Host_required, " ")) - } - if len(entries.Target_required) > 0 { - fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES :=", strings.Join(entries.Target_required, " ")) - } - if r := library.deviceProperties.Target.Hostdex.Required; len(r) > 0 { - fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(r, " ")) - } - fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", library.Stem()+"-hostdex") - fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") +func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries { + hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host() + if !library.IsForPlatform() { + // If the platform variant is available, don't emit hostdex modules from the APEX variants + hostDexNeeded = false } + + if hostDexNeeded { + var output android.Path + if library.dexJarFile != nil { + output = library.dexJarFile + } else { + output = library.implementationAndResourcesJar + } + return android.AndroidMkEntries{ + Class: "JAVA_LIBRARIES", + SubName: "-hostdex", + OutputFile: android.OptionalPathForPath(output), + Required: library.deviceProperties.Target.Hostdex.Required, + Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", + ExtraEntries: []android.AndroidMkExtraEntriesFunc{ + func(entries *android.AndroidMkEntries) { + entries.SetBool("LOCAL_IS_HOST_MODULE", true) + entries.SetPath("LOCAL_PREBUILT_MODULE_FILE", output) + if library.dexJarFile != nil { + entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile) + } + entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile) + entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar) + entries.SetString("LOCAL_MODULE_STEM", library.Stem()+"-hostdex") + }, + }, + } + } + return android.AndroidMkEntries{Disabled: true} } func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { - if !library.IsForPlatform() { - return []android.AndroidMkEntries{android.AndroidMkEntries{ - Disabled: true, - }} - } - return []android.AndroidMkEntries{android.AndroidMkEntries{ - Class: "JAVA_LIBRARIES", - OutputFile: android.OptionalPathForPath(library.outputFile), - Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", - ExtraEntries: []android.AndroidMkExtraEntriesFunc{ - func(entries *android.AndroidMkEntries) { - if len(library.logtagsSrcs) > 0 { - var logtags []string - for _, l := range library.logtagsSrcs { - logtags = append(logtags, l.Rel()) + var entriesList []android.AndroidMkEntries + + mainEntries := android.AndroidMkEntries{Disabled: true} + // For a java library built for an APEX, we don't need Make module + if library.IsForPlatform() { + mainEntries = android.AndroidMkEntries{ + Class: "JAVA_LIBRARIES", + OutputFile: android.OptionalPathForPath(library.outputFile), + Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", + ExtraEntries: []android.AndroidMkExtraEntriesFunc{ + func(entries *android.AndroidMkEntries) { + if len(library.logtagsSrcs) > 0 { + var logtags []string + for _, l := range library.logtagsSrcs { + logtags = append(logtags, l.Rel()) + } + entries.AddStrings("LOCAL_LOGTAGS_FILES", logtags...) } - entries.AddStrings("LOCAL_LOGTAGS_FILES", logtags...) - } - if library.installFile == nil { - entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true) - } - if library.dexJarFile != nil { - entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile) - } - if len(library.dexpreopter.builtInstalled) > 0 { - entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled) - } - entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion()) - entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar) - entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile) + if library.installFile == nil { + entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true) + } + if library.dexJarFile != nil { + entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile) + } + if len(library.dexpreopter.builtInstalled) > 0 { + entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled) + } + entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion()) + entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar) + entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile) - if library.jacocoReportClassesFile != nil { - entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile) - } + if library.jacocoReportClassesFile != nil { + entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile) + } - entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs...) + entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs...) - if len(library.additionalCheckedModules) != 0 { - entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...) - } + if len(library.additionalCheckedModules) != 0 { + entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...) + } - if library.proguardDictionary != nil { - entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", library.proguardDictionary) - } - entries.SetString("LOCAL_MODULE_STEM", library.Stem()) + if library.proguardDictionary != nil { + entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", library.proguardDictionary) + } + entries.SetString("LOCAL_MODULE_STEM", library.Stem()) + }, }, - }, - ExtraFooters: []android.AndroidMkExtraFootersFunc{ - func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) { - library.AndroidMkHostDex(w, name, entries) - }, - }, - }} + } + } + + hostDexEntries := library.AndroidMkEntriesHostDex() + + entriesList = append(entriesList, mainEntries, hostDexEntries) + return entriesList } // Called for modules that are a component of a test suite. diff --git a/java/androidmk_test.go b/java/androidmk_test.go index 967357630..acc6bf039 100644 --- a/java/androidmk_test.go +++ b/java/androidmk_test.go @@ -50,17 +50,23 @@ func TestHostdex(t *testing.T) { `) mod := ctx.ModuleForTests("foo", "android_common").Module() - entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] + entriesList := android.AndroidMkEntriesForTest(t, config, "", mod) + if len(entriesList) != 2 { + t.Errorf("two entries are expected, but got %d", len(entriesList)) + } + mainEntries := &entriesList[0] expected := []string{"foo"} - actual := entries.EntryMap["LOCAL_MODULE"] + actual := mainEntries.EntryMap["LOCAL_MODULE"] if !reflect.DeepEqual(expected, actual) { t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual) } - footerLines := entries.FooterLinesForTests() - if !android.InList("LOCAL_MODULE := foo-hostdex", footerLines) { - t.Errorf("foo-hostdex is not found in the footers: %q", footerLines) + subEntries := &entriesList[1] + expected = []string{"foo-hostdex"} + actual = subEntries.EntryMap["LOCAL_MODULE"] + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual) } } @@ -75,17 +81,23 @@ func TestHostdexRequired(t *testing.T) { `) mod := ctx.ModuleForTests("foo", "android_common").Module() - entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] + entriesList := android.AndroidMkEntriesForTest(t, config, "", mod) + if len(entriesList) != 2 { + t.Errorf("two entries are expected, but got %d", len(entriesList)) + } + mainEntries := &entriesList[0] expected := []string{"libfoo"} - actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"] + actual := mainEntries.EntryMap["LOCAL_REQUIRED_MODULES"] if !reflect.DeepEqual(expected, actual) { t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) } - footerLines := entries.FooterLinesForTests() - if !android.InList("LOCAL_REQUIRED_MODULES := libfoo", footerLines) { - t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines) + subEntries := &entriesList[1] + expected = []string{"libfoo"} + actual = subEntries.EntryMap["LOCAL_REQUIRED_MODULES"] + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) } } @@ -104,14 +116,20 @@ func TestHostdexSpecificRequired(t *testing.T) { `) mod := ctx.ModuleForTests("foo", "android_common").Module() - entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] + entriesList := android.AndroidMkEntriesForTest(t, config, "", mod) + if len(entriesList) != 2 { + t.Errorf("two entries are expected, but got %d", len(entriesList)) + } - if r, ok := entries.EntryMap["LOCAL_REQUIRED_MODULES"]; ok { + mainEntries := &entriesList[0] + if r, ok := mainEntries.EntryMap["LOCAL_REQUIRED_MODULES"]; ok { t.Errorf("Unexpected required modules: %q", r) } - footerLines := entries.FooterLinesForTests() - if !android.InList("LOCAL_REQUIRED_MODULES += libfoo", footerLines) { - t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines) + subEntries := &entriesList[1] + expected := []string{"libfoo"} + actual := subEntries.EntryMap["LOCAL_REQUIRED_MODULES"] + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) } }