diff options
| author | 2020-12-05 00:07:57 +0000 | |
|---|---|---|
| committer | 2020-12-05 00:07:57 +0000 | |
| commit | 6544c774af0deacc1df8bd19a4559ee5fc834fb6 (patch) | |
| tree | fdbb3cd72e8a3758aa9910508aa9e761317a17a2 | |
| parent | 53a3d92368d49bef8b1ab66b785563f97354f358 (diff) | |
| parent | 3e0ee48d175aac5abea5fb3d4a21a0a42f76839d (diff) | |
Merge "Refactor rust to use AndroidMkEntries" into mainline-prod
| -rw-r--r-- | rust/androidmk.go | 78 |
1 files changed, 30 insertions, 48 deletions
diff --git a/rust/androidmk.go b/rust/androidmk.go index 99880a821..428e74925 100644 --- a/rust/androidmk.go +++ b/rust/androidmk.go @@ -15,10 +15,7 @@ package rust import ( - "fmt" - "io" "path/filepath" - "strings" "android/soong/android" ) @@ -26,14 +23,14 @@ import ( type AndroidMkContext interface { Name() string Target() android.Target - subAndroidMk(*android.AndroidMkData, interface{}) + subAndroidMk(*android.AndroidMkEntries, interface{}) } type subAndroidMkProvider interface { - AndroidMk(AndroidMkContext, *android.AndroidMkData) + AndroidMk(AndroidMkContext, *android.AndroidMkEntries) } -func (mod *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) { +func (mod *Module) subAndroidMk(data *android.AndroidMkEntries, obj interface{}) { if mod.subAndroidMkOnce == nil { mod.subAndroidMkOnce = make(map[subAndroidMkProvider]bool) } @@ -45,27 +42,17 @@ func (mod *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) { } } -func (mod *Module) AndroidMk() android.AndroidMkData { - ret := android.AndroidMkData{ +func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries { + ret := android.AndroidMkEntries{ OutputFile: mod.outputFile, Include: "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk", - Extra: []android.AndroidMkExtraFunc{ - func(w io.Writer, outputFile android.Path) { - if len(mod.Properties.AndroidMkRlibs) > 0 { - fmt.Fprintln(w, "LOCAL_RLIB_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkRlibs, " ")) - } - if len(mod.Properties.AndroidMkDylibs) > 0 { - fmt.Fprintln(w, "LOCAL_DYLIB_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkDylibs, " ")) - } - if len(mod.Properties.AndroidMkProcMacroLibs) > 0 { - fmt.Fprintln(w, "LOCAL_PROC_MACRO_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkProcMacroLibs, " ")) - } - if len(mod.Properties.AndroidMkSharedLibs) > 0 { - fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkSharedLibs, " ")) - } - if len(mod.Properties.AndroidMkStaticLibs) > 0 { - fmt.Fprintln(w, "LOCAL_STATIC_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkStaticLibs, " ")) - } + ExtraEntries: []android.AndroidMkExtraEntriesFunc{ + func(entries *android.AndroidMkEntries) { + entries.AddStrings("LOCAL_RLIB_LIBRARIES", mod.Properties.AndroidMkRlibs...) + entries.AddStrings("LOCAL_DYLIB_LIBRARIES", mod.Properties.AndroidMkDylibs...) + entries.AddStrings("LOCAL_PROC_MACRO_LIBRARIES", mod.Properties.AndroidMkProcMacroLibs...) + entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.Properties.AndroidMkSharedLibs...) + entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...) }, }, } @@ -74,10 +61,10 @@ func (mod *Module) AndroidMk() android.AndroidMkData { ret.SubName += mod.Properties.SubName - return ret + return []android.AndroidMkEntries{ret} } -func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { +func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { ctx.subAndroidMk(ret, binary.baseCompiler) if binary.distFile.Valid() { @@ -85,31 +72,26 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr } ret.Class = "EXECUTABLES" - ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { - fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String()) + ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) { + entries.SetPath("LOCAL_SOONG_UNSTRIPPED_BINARY", binary.unstrippedOutputFile) }) } -func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { +func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { test.binaryDecorator.AndroidMk(ctx, ret) ret.Class = "NATIVE_TESTS" ret.SubName = test.getMutatedModuleSubName(ctx.Name()) - ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { - if len(test.Properties.Test_suites) > 0 { - fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", - strings.Join(test.Properties.Test_suites, " ")) - } + ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) { + entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", test.Properties.Test_suites...) if test.testConfig != nil { - fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", test.testConfig.String()) - } - if !BoolDefault(test.Properties.Auto_gen_config, true) { - fmt.Fprintln(w, "LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG := true") + entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String()) } + entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true)) }) // TODO(chh): add test data with androidMkWriteTestData(test.data, ctx, ret) } -func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { +func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { ctx.subAndroidMk(ret, library.baseCompiler) if library.rlib() { @@ -126,14 +108,14 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An ret.DistFiles = android.MakeDefaultDistFiles(library.distFile.Path()) } - ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { + ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) { if !library.rlib() { - fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String()) + entries.SetPath("LOCAL_SOONG_UNSTRIPPED_BINARY", library.unstrippedOutputFile) } }) } -func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { +func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { ctx.subAndroidMk(ret, procMacro.baseCompiler) ret.Class = "PROC_MACRO_LIBRARIES" @@ -143,17 +125,17 @@ func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *androi } -func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { +func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { // Soong installation is only supported for host modules. Have Make // installation trigger Soong installation. if ctx.Target().Os.Class == android.Host { ret.OutputFile = android.OptionalPathForPath(compiler.path) } - ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { + ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) { path, file := filepath.Split(compiler.path.ToMakePath().String()) stem, suffix, _ := android.SplitFileExt(file) - fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) - fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) + entries.SetString("LOCAL_MODULE_SUFFIX", suffix) + entries.SetString("LOCAL_MODULE_PATH", path) + entries.SetString("LOCAL_MODULE_STEM", stem) }) } |