From e0dc8dfd22a13744c252e56099ddd462f002647f Mon Sep 17 00:00:00 2001 From: Jaewoong Jung Date: Tue, 27 Aug 2019 17:33:16 -0700 Subject: [PATCH] AndroidMkEntries minor refactoring. This includes a few changes that make AndroidMkEntries more resemble AndroidMkData, especially in terms of how extra entries are added. Most importantly it can now have multiple custom functions. Test: Soong tests Change-Id: Ibf9102624d16d0c1c9894a2794fc7c797bb34c9a --- android/androidmk.go | 9 +++++---- android/prebuilt_etc.go | 20 +++++++++++--------- android/sh_binary.go | 32 ++++++++++++++++++-------------- apex/apex.go | 12 +++++++----- java/androidmk.go | 26 ++++++++++++++------------ java/platform_compat_config.go | 8 +++++--- 6 files changed, 60 insertions(+), 47 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index 1f1bd701b..124523f4c 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -79,12 +79,14 @@ type AndroidMkEntries struct { header bytes.Buffer footer bytes.Buffer - AddCustomEntries func(name, prefix, moduleDir string, entries *AndroidMkEntries) + ExtraEntries []AndroidMkExtraEntriesFunc EntryMap map[string][]string entryOrder []string } +type AndroidMkExtraEntriesFunc func(entries *AndroidMkEntries) + func (a *AndroidMkEntries) SetString(name, value string) { if _, ok := a.EntryMap[name]; !ok { a.entryOrder = append(a.entryOrder, name) @@ -246,9 +248,8 @@ func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod bluep prefix = "2ND_" + prefix } } - blueprintDir := filepath.Dir(bpPath) - if a.AddCustomEntries != nil { - a.AddCustomEntries(name, prefix, blueprintDir, a) + for _, extra := range a.ExtraEntries { + extra(a) } // Write to footer. diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go index 9722a2540..d29ed16f6 100644 --- a/android/prebuilt_etc.go +++ b/android/prebuilt_etc.go @@ -155,16 +155,18 @@ func (p *PrebuiltEtc) AndroidMkEntries() AndroidMkEntries { Class: "ETC", SubName: nameSuffix, OutputFile: OptionalPathForPath(p.outputFilePath), - AddCustomEntries: func(name, prefix, moduleDir string, entries *AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_TAGS", "optional") - entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString()) - entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) - entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable())) - if p.additionalDependencies != nil { - for _, path := range *p.additionalDependencies { - entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES", path.String()) + ExtraEntries: []AndroidMkExtraEntriesFunc{ + func(entries *AndroidMkEntries) { + entries.SetString("LOCAL_MODULE_TAGS", "optional") + entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString()) + entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) + entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable())) + if p.additionalDependencies != nil { + for _, path := range *p.additionalDependencies { + entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES", path.String()) + } } - } + }, }, } } diff --git a/android/sh_binary.go b/android/sh_binary.go index 2855aa040..ba0c8be7d 100644 --- a/android/sh_binary.go +++ b/android/sh_binary.go @@ -133,8 +133,10 @@ func (s *ShBinary) AndroidMkEntries() AndroidMkEntries { Class: "EXECUTABLES", OutputFile: OptionalPathForPath(s.outputFilePath), Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk", - AddCustomEntries: func(name, prefix, moduleDir string, entries *AndroidMkEntries) { - s.customAndroidMkEntries(entries) + ExtraEntries: []AndroidMkExtraEntriesFunc{ + func(entries *AndroidMkEntries) { + s.customAndroidMkEntries(entries) + }, }, } } @@ -156,20 +158,22 @@ func (s *ShTest) AndroidMkEntries() AndroidMkEntries { Class: "NATIVE_TESTS", OutputFile: OptionalPathForPath(s.outputFilePath), Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk", - AddCustomEntries: func(name, prefix, moduleDir string, entries *AndroidMkEntries) { - s.customAndroidMkEntries(entries) + ExtraEntries: []AndroidMkExtraEntriesFunc{ + func(entries *AndroidMkEntries) { + s.customAndroidMkEntries(entries) - entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...) - entries.SetString("LOCAL_TEST_CONFIG", String(s.testProperties.Test_config)) - for _, d := range s.data { - rel := d.Rel() - path := d.String() - if !strings.HasSuffix(path, rel) { - panic(fmt.Errorf("path %q does not end with %q", path, rel)) + entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...) + entries.SetString("LOCAL_TEST_CONFIG", String(s.testProperties.Test_config)) + for _, d := range s.data { + rel := d.Rel() + path := d.String() + if !strings.HasSuffix(path, rel) { + panic(fmt.Errorf("path %q does not end with %q", path, rel)) + } + path = strings.TrimSuffix(path, rel) + entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel) } - path = strings.TrimSuffix(path, rel) - entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel) - } + }, }, } } diff --git a/apex/apex.go b/apex/apex.go index 806158a9d..832188d81 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1687,11 +1687,13 @@ func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries { Class: "ETC", OutputFile: android.OptionalPathForPath(p.inputApex), Include: "$(BUILD_PREBUILT)", - AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString())) - entries.SetString("LOCAL_MODULE_STEM", p.installFilename) - entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) - entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...) + ExtraEntries: []android.AndroidMkExtraEntriesFunc{ + func(entries *android.AndroidMkEntries) { + entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString())) + entries.SetString("LOCAL_MODULE_STEM", p.installFilename) + entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) + entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...) + }, }, } } diff --git a/java/androidmk.go b/java/androidmk.go index c00e070a0..9101b2576 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -614,18 +614,20 @@ func (a *AndroidAppImport) AndroidMkEntries() android.AndroidMkEntries { Class: "APPS", OutputFile: android.OptionalPathForPath(a.outputFile), Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", - AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) { - entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged)) - if a.certificate != nil { - entries.SetString("LOCAL_CERTIFICATE", a.certificate.Pem.String()) - } else { - entries.SetString("LOCAL_CERTIFICATE", "PRESIGNED") - } - entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...) - if len(a.dexpreopter.builtInstalled) > 0 { - entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled) - } - entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel()) + ExtraEntries: []android.AndroidMkExtraEntriesFunc{ + func(entries *android.AndroidMkEntries) { + entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged)) + if a.certificate != nil { + entries.SetString("LOCAL_CERTIFICATE", a.certificate.Pem.String()) + } else { + entries.SetString("LOCAL_CERTIFICATE", "PRESIGNED") + } + entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...) + if len(a.dexpreopter.builtInstalled) > 0 { + entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled) + } + entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel()) + }, }, } } diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 792edf388..f1da20394 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -77,9 +77,11 @@ func (p *platformCompatConfig) AndroidMkEntries() android.AndroidMkEntries { Class: "ETC", OutputFile: android.OptionalPathForPath(p.configFile), Include: "$(BUILD_PREBUILT)", - AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString()) - entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) + ExtraEntries: []android.AndroidMkExtraEntriesFunc{ + func(entries *android.AndroidMkEntries) { + entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString()) + entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) + }, }, } }