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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (library *Library) AndroidMkHostDex(w io.Writer, name string, entries *android.AndroidMkEntries) {
|
func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {
|
||||||
if Bool(library.deviceProperties.Hostdex) && !library.Host() {
|
hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host()
|
||||||
fmt.Fprintln(w, "include $(CLEAR_VARS)")
|
if !library.IsForPlatform() {
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
|
// If the platform variant is available, don't emit hostdex modules from the APEX variants
|
||||||
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
|
hostDexNeeded = false
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
|
}
|
||||||
|
|
||||||
|
if hostDexNeeded {
|
||||||
|
var output android.Path
|
||||||
if library.dexJarFile != nil {
|
if library.dexJarFile != nil {
|
||||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.dexJarFile.String())
|
output = library.dexJarFile
|
||||||
} else {
|
} 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 {
|
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())
|
entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
|
||||||
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
|
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
|
||||||
if len(entries.Required) > 0 {
|
entries.SetString("LOCAL_MODULE_STEM", library.Stem()+"-hostdex")
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
return android.AndroidMkEntries{Disabled: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
|
func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
|
||||||
if !library.IsForPlatform() {
|
var entriesList []android.AndroidMkEntries
|
||||||
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
|
||||||
Disabled: true,
|
mainEntries := android.AndroidMkEntries{Disabled: true}
|
||||||
}}
|
// For a java library built for an APEX, we don't need Make module
|
||||||
}
|
if library.IsForPlatform() {
|
||||||
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
mainEntries = android.AndroidMkEntries{
|
||||||
Class: "JAVA_LIBRARIES",
|
Class: "JAVA_LIBRARIES",
|
||||||
OutputFile: android.OptionalPathForPath(library.outputFile),
|
OutputFile: android.OptionalPathForPath(library.outputFile),
|
||||||
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
|
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
|
||||||
@@ -104,12 +107,13 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
entries.SetString("LOCAL_MODULE_STEM", library.Stem())
|
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.
|
// 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()
|
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"}
|
expected := []string{"foo"}
|
||||||
actual := entries.EntryMap["LOCAL_MODULE"]
|
actual := mainEntries.EntryMap["LOCAL_MODULE"]
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual)
|
t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
footerLines := entries.FooterLinesForTests()
|
subEntries := &entriesList[1]
|
||||||
if !android.InList("LOCAL_MODULE := foo-hostdex", footerLines) {
|
expected = []string{"foo-hostdex"}
|
||||||
t.Errorf("foo-hostdex is not found in the footers: %q", footerLines)
|
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()
|
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"}
|
expected := []string{"libfoo"}
|
||||||
actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"]
|
actual := mainEntries.EntryMap["LOCAL_REQUIRED_MODULES"]
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual)
|
t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
footerLines := entries.FooterLinesForTests()
|
subEntries := &entriesList[1]
|
||||||
if !android.InList("LOCAL_REQUIRED_MODULES := libfoo", footerLines) {
|
expected = []string{"libfoo"}
|
||||||
t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines)
|
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()
|
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)
|
t.Errorf("Unexpected required modules: %q", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
footerLines := entries.FooterLinesForTests()
|
subEntries := &entriesList[1]
|
||||||
if !android.InList("LOCAL_REQUIRED_MODULES += libfoo", footerLines) {
|
expected := []string{"libfoo"}
|
||||||
t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines)
|
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