Extract createEntriesForApexFile
While this seems like a simple refactoring it does actually fix an issue. Previously, when the ExtraEntries func was being defined inline within the for ... loop it used the loop variable "fi". Unfortunately, that meant that the func created on each iteration ended up using the value for "fi" that was set on the last iteration. Extracting the creation of the entry into a separate method means that each func created gets its own "fi" variable with the correct values. Bug: 177892522 Test: m SOONG_CONFIG_art_module_source_build=false nothing - without this change it reported duplicate rules for apache-xml.jar which is the last entry in the art-bootclasspath-fragment. With this change it works fine. Change-Id: Ia063b513f758e1bbe73407c0441b72453f412acf
This commit is contained in:
parent
5466a3699c
commit
155c17779c
1 changed files with 45 additions and 40 deletions
|
@ -217,52 +217,57 @@ func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries {
|
|||
// apex specific variants of the exported java modules available for use from within make.
|
||||
apexName := p.BaseModuleName()
|
||||
for _, fi := range p.apexFilesForAndroidMk {
|
||||
moduleName := fi.androidMkModuleName + "." + apexName
|
||||
entries := android.AndroidMkEntries{
|
||||
Class: fi.class.nameInMake(),
|
||||
OverrideName: moduleName,
|
||||
OutputFile: android.OptionalPathForPath(fi.builtFile),
|
||||
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
|
||||
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
||||
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
||||
entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
|
||||
|
||||
// soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
|
||||
// we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
|
||||
// we will have foo.jar.jar
|
||||
entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar"))
|
||||
var classesJar android.Path
|
||||
var headerJar android.Path
|
||||
if javaModule, ok := fi.module.(java.ApexDependency); ok {
|
||||
classesJar = javaModule.ImplementationAndResourcesJars()[0]
|
||||
headerJar = javaModule.HeaderJars()[0]
|
||||
} else {
|
||||
classesJar = fi.builtFile
|
||||
headerJar = fi.builtFile
|
||||
}
|
||||
entries.SetString("LOCAL_SOONG_CLASSES_JAR", classesJar.String())
|
||||
entries.SetString("LOCAL_SOONG_HEADER_JAR", headerJar.String())
|
||||
entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String())
|
||||
entries.SetString("LOCAL_DEX_PREOPT", "false")
|
||||
},
|
||||
},
|
||||
ExtraFooters: []android.AndroidMkExtraFootersFunc{
|
||||
func(w io.Writer, name, prefix, moduleDir string) {
|
||||
// m <module_name> will build <module_name>.<apex_name> as well.
|
||||
if fi.androidMkModuleName != moduleName {
|
||||
fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
|
||||
fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
entries := p.createEntriesForApexFile(fi, apexName)
|
||||
entriesList = append(entriesList, entries)
|
||||
}
|
||||
|
||||
return entriesList
|
||||
}
|
||||
|
||||
// createEntriesForApexFile creates an AndroidMkEntries for the supplied apexFile
|
||||
func (p *prebuiltCommon) createEntriesForApexFile(fi apexFile, apexName string) android.AndroidMkEntries {
|
||||
moduleName := fi.androidMkModuleName + "." + apexName
|
||||
entries := android.AndroidMkEntries{
|
||||
Class: fi.class.nameInMake(),
|
||||
OverrideName: moduleName,
|
||||
OutputFile: android.OptionalPathForPath(fi.builtFile),
|
||||
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
|
||||
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
||||
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
||||
entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
|
||||
|
||||
// soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
|
||||
// we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
|
||||
// we will have foo.jar.jar
|
||||
entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar"))
|
||||
var classesJar android.Path
|
||||
var headerJar android.Path
|
||||
if javaModule, ok := fi.module.(java.ApexDependency); ok {
|
||||
classesJar = javaModule.ImplementationAndResourcesJars()[0]
|
||||
headerJar = javaModule.HeaderJars()[0]
|
||||
} else {
|
||||
classesJar = fi.builtFile
|
||||
headerJar = fi.builtFile
|
||||
}
|
||||
entries.SetString("LOCAL_SOONG_CLASSES_JAR", classesJar.String())
|
||||
entries.SetString("LOCAL_SOONG_HEADER_JAR", headerJar.String())
|
||||
entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String())
|
||||
entries.SetString("LOCAL_DEX_PREOPT", "false")
|
||||
},
|
||||
},
|
||||
ExtraFooters: []android.AndroidMkExtraFootersFunc{
|
||||
func(w io.Writer, name, prefix, moduleDir string) {
|
||||
// m <module_name> will build <module_name>.<apex_name> as well.
|
||||
if fi.androidMkModuleName != moduleName {
|
||||
fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
|
||||
fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
// prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and
|
||||
// apex_set in order to create the modules needed to provide access to the prebuilt .apex file.
|
||||
type prebuiltApexModuleCreator interface {
|
||||
|
|
Loading…
Reference in a new issue