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
This commit is contained in:
@@ -17,51 +17,54 @@ 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")
|
||||
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 {
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.dexJarFile.String())
|
||||
output = library.dexJarFile
|
||||
} else {
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationAndResourcesJar.String())
|
||||
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 {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
|
||||
entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile)
|
||||
}
|
||||
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, " "))
|
||||
entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
|
||||
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
|
||||
entries.SetString("LOCAL_MODULE_STEM", library.Stem()+"-hostdex")
|
||||
},
|
||||
},
|
||||
}
|
||||
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")
|
||||
}
|
||||
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{
|
||||
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",
|
||||
@@ -104,12 +107,13 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
|
||||
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.
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user