From 9dc8c54fc4ca25cb48766068229f4e08be3a22bb Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 17 Jun 2021 13:33:09 +0100 Subject: [PATCH] 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. Merged-In: Ia063b513f758e1bbe73407c0441b72453f412acf Change-Id: Ia063b513f758e1bbe73407c0441b72453f412acf (cherry picked from commit 155c17779c5e5937fa987b81df6697fc3c23607e) --- apex/prebuilt.go | 85 +++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/apex/prebuilt.go b/apex/prebuilt.go index c17f162a5..d4867767a 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -216,52 +216,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 will build . 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 will build . 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 {