Refactor rust to use AndroidMkEntries
This is to facilitate consolidation of compatibility suite logic. Test: go soong tests Test: m nothing & compare soong Android mk files -- only diffs are elimination of duplicate LOCAL_UNINSTALLABLE_MODULE := true lines Change-Id: I76211505b2b6afde5d0431586b77d799cf70c6b9
This commit is contained in:
parent
0dabd31057
commit
4018a8d4d7
|
@ -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,33 +42,22 @@ func (mod *Module) SubAndroidMk(data *android.AndroidMkData, obj interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func (mod *Module) AndroidMk() android.AndroidMkData {
|
||||
func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
|
||||
if mod.Properties.HideFromMake {
|
||||
return android.AndroidMkData{
|
||||
Disabled: true,
|
||||
}
|
||||
|
||||
return []android.AndroidMkEntries{android.AndroidMkEntries{Disabled: true}}
|
||||
}
|
||||
|
||||
ret := android.AndroidMkData{
|
||||
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...)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -84,10 +70,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() {
|
||||
|
@ -95,35 +81,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) {
|
||||
if binary.coverageOutputZipFile.Valid() {
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+binary.coverageOutputZipFile.String())
|
||||
}
|
||||
ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
||||
entries.SetOptionalPath("LOCAL_PREBUILT_COVERAGE_ARCHIVE", binary.coverageOutputZipFile)
|
||||
})
|
||||
}
|
||||
|
||||
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.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")
|
||||
}
|
||||
if Bool(test.Properties.Test_options.Unit_test) {
|
||||
fmt.Fprintln(w, "LOCAL_IS_UNIT_TEST := 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))
|
||||
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(test.Properties.Test_options.Unit_test))
|
||||
})
|
||||
// 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() {
|
||||
|
@ -140,15 +117,12 @@ 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) {
|
||||
if library.coverageOutputZipFile.Valid() {
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+library.coverageOutputZipFile.String())
|
||||
}
|
||||
|
||||
ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
||||
entries.SetOptionalPath("LOCAL_PREBUILT_COVERAGE_ARCHIVE", library.coverageOutputZipFile)
|
||||
})
|
||||
}
|
||||
|
||||
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"
|
||||
|
@ -158,29 +132,29 @@ func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *androi
|
|||
|
||||
}
|
||||
|
||||
func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||
func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
||||
outFile := sourceProvider.OutputFiles[0]
|
||||
ret.Class = "ETC"
|
||||
ret.OutputFile = android.OptionalPathForPath(outFile)
|
||||
ret.SubName += sourceProvider.subName
|
||||
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
||||
ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
||||
_, file := filepath.Split(outFile.String())
|
||||
stem, suffix, _ := android.SplitFileExt(file)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
|
||||
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
||||
entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
|
||||
entries.SetString("LOCAL_MODULE_STEM", stem)
|
||||
entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
|
||||
})
|
||||
}
|
||||
|
||||
func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||
func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
||||
ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider)
|
||||
}
|
||||
|
||||
func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||
func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
||||
ctx.SubAndroidMk(ret, proto.BaseSourceProvider)
|
||||
}
|
||||
|
||||
func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||
func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
||||
if compiler.path == (android.InstallPath{}) {
|
||||
return
|
||||
}
|
||||
|
@ -194,14 +168,12 @@ func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.Andro
|
|||
unstrippedOutputFile = ret.OutputFile
|
||||
ret.OutputFile = compiler.strippedOutputFile
|
||||
}
|
||||
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
||||
if compiler.strippedOutputFile.Valid() {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", unstrippedOutputFile)
|
||||
}
|
||||
ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
||||
entries.SetOptionalPath("LOCAL_SOONG_UNSTRIPPED_BINARY", unstrippedOutputFile)
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue