Export Rust SourceProvider types and methods
The AIDL compiler now uses SourceProvider to compiler the generated Rust code from system/tools/aidl/build/aidl_interface.go using its own SourceProvider object, which needs access to baseSourceProvider and all methods of SourceProvider. Test: mmma system/tools/aidl with 1357705 applied Change-Id: I226609a7fccca2e7e1bfbad5d69d1821d37e43a1
This commit is contained in:
@@ -26,18 +26,18 @@ import (
|
|||||||
type AndroidMkContext interface {
|
type AndroidMkContext interface {
|
||||||
Name() string
|
Name() string
|
||||||
Target() android.Target
|
Target() android.Target
|
||||||
subAndroidMk(*android.AndroidMkData, interface{})
|
SubAndroidMk(*android.AndroidMkData, interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
type subAndroidMkProvider interface {
|
type SubAndroidMkProvider interface {
|
||||||
AndroidMk(AndroidMkContext, *android.AndroidMkData)
|
AndroidMk(AndroidMkContext, *android.AndroidMkData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mod *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) {
|
func (mod *Module) SubAndroidMk(data *android.AndroidMkData, obj interface{}) {
|
||||||
if mod.subAndroidMkOnce == nil {
|
if mod.subAndroidMkOnce == nil {
|
||||||
mod.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
|
mod.subAndroidMkOnce = make(map[SubAndroidMkProvider]bool)
|
||||||
}
|
}
|
||||||
if androidmk, ok := obj.(subAndroidMkProvider); ok {
|
if androidmk, ok := obj.(SubAndroidMkProvider); ok {
|
||||||
if !mod.subAndroidMkOnce[androidmk] {
|
if !mod.subAndroidMkOnce[androidmk] {
|
||||||
mod.subAndroidMkOnce[androidmk] = true
|
mod.subAndroidMkOnce[androidmk] = true
|
||||||
androidmk.AndroidMk(mod, data)
|
androidmk.AndroidMk(mod, data)
|
||||||
@@ -77,10 +77,10 @@ func (mod *Module) AndroidMk() android.AndroidMkData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mod.compiler != nil && !mod.compiler.Disabled() {
|
if mod.compiler != nil && !mod.compiler.Disabled() {
|
||||||
mod.subAndroidMk(&ret, mod.compiler)
|
mod.SubAndroidMk(&ret, mod.compiler)
|
||||||
} else if mod.sourceProvider != nil {
|
} else if mod.sourceProvider != nil {
|
||||||
// If the compiler is disabled, this is a SourceProvider.
|
// If the compiler is disabled, this is a SourceProvider.
|
||||||
mod.subAndroidMk(&ret, mod.sourceProvider)
|
mod.SubAndroidMk(&ret, mod.sourceProvider)
|
||||||
}
|
}
|
||||||
ret.SubName += mod.Properties.SubName
|
ret.SubName += mod.Properties.SubName
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ func (mod *Module) AndroidMk() android.AndroidMkData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||||
ctx.subAndroidMk(ret, binary.baseCompiler)
|
ctx.SubAndroidMk(ret, binary.baseCompiler)
|
||||||
|
|
||||||
if binary.distFile.Valid() {
|
if binary.distFile.Valid() {
|
||||||
ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path())
|
ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path())
|
||||||
@@ -122,7 +122,7 @@ func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidM
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||||
ctx.subAndroidMk(ret, library.baseCompiler)
|
ctx.SubAndroidMk(ret, library.baseCompiler)
|
||||||
|
|
||||||
if library.rlib() {
|
if library.rlib() {
|
||||||
ret.Class = "RLIB_LIBRARIES"
|
ret.Class = "RLIB_LIBRARIES"
|
||||||
@@ -150,7 +150,7 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||||
ctx.subAndroidMk(ret, procMacro.baseCompiler)
|
ctx.SubAndroidMk(ret, procMacro.baseCompiler)
|
||||||
|
|
||||||
ret.Class = "PROC_MACRO_LIBRARIES"
|
ret.Class = "PROC_MACRO_LIBRARIES"
|
||||||
if procMacro.distFile.Valid() {
|
if procMacro.distFile.Valid() {
|
||||||
@@ -159,8 +159,8 @@ 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.AndroidMkData) {
|
||||||
outFile := sourceProvider.outputFile
|
outFile := sourceProvider.OutputFile
|
||||||
ret.Class = "ETC"
|
ret.Class = "ETC"
|
||||||
ret.OutputFile = android.OptionalPathForPath(outFile)
|
ret.OutputFile = android.OptionalPathForPath(outFile)
|
||||||
ret.SubName += sourceProvider.subName
|
ret.SubName += sourceProvider.subName
|
||||||
@@ -173,7 +173,7 @@ func (sourceProvider *baseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *a
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||||
ctx.subAndroidMk(ret, bindgen.baseSourceProvider)
|
ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider)
|
||||||
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
||||||
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
||||||
})
|
})
|
||||||
|
@@ -86,12 +86,12 @@ type BindgenProperties struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type bindgenDecorator struct {
|
type bindgenDecorator struct {
|
||||||
*baseSourceProvider
|
*BaseSourceProvider
|
||||||
|
|
||||||
Properties BindgenProperties
|
Properties BindgenProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bindgenDecorator) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
|
func (b *bindgenDecorator) GenerateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
|
||||||
ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
|
ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
|
||||||
|
|
||||||
var cflags []string
|
var cflags []string
|
||||||
@@ -134,7 +134,7 @@ func (b *bindgenDecorator) generateSource(ctx android.ModuleContext, deps PathDe
|
|||||||
ctx.PropertyErrorf("wrapper_src", "invalid path to wrapper source")
|
ctx.PropertyErrorf("wrapper_src", "invalid path to wrapper source")
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFile := android.PathForModuleOut(ctx, b.baseSourceProvider.getStem(ctx)+".rs")
|
outputFile := android.PathForModuleOut(ctx, b.BaseSourceProvider.getStem(ctx)+".rs")
|
||||||
|
|
||||||
var cmd, cmdDesc string
|
var cmd, cmdDesc string
|
||||||
if b.Properties.Custom_bindgen != "" {
|
if b.Properties.Custom_bindgen != "" {
|
||||||
@@ -158,12 +158,12 @@ func (b *bindgenDecorator) generateSource(ctx android.ModuleContext, deps PathDe
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
b.baseSourceProvider.outputFile = outputFile
|
b.BaseSourceProvider.OutputFile = outputFile
|
||||||
return outputFile
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bindgenDecorator) sourceProviderProps() []interface{} {
|
func (b *bindgenDecorator) SourceProviderProps() []interface{} {
|
||||||
return append(b.baseSourceProvider.sourceProviderProps(),
|
return append(b.BaseSourceProvider.SourceProviderProps(),
|
||||||
&b.Properties)
|
&b.Properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,27 +181,18 @@ func RustBindgenHostFactory() android.Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorator) {
|
func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorator) {
|
||||||
module := newModule(hod, android.MultilibBoth)
|
|
||||||
|
|
||||||
bindgen := &bindgenDecorator{
|
bindgen := &bindgenDecorator{
|
||||||
baseSourceProvider: NewSourceProvider(),
|
BaseSourceProvider: NewSourceProvider(),
|
||||||
Properties: BindgenProperties{},
|
Properties: BindgenProperties{},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, library := NewRustLibrary(hod)
|
module := NewSourceProviderModule(hod, bindgen, false)
|
||||||
library.BuildOnlyRust()
|
|
||||||
library.setNoLint()
|
|
||||||
library.sourceProvider = bindgen
|
|
||||||
|
|
||||||
module.sourceProvider = bindgen
|
|
||||||
module.compiler = library
|
|
||||||
module.setClippy(false)
|
|
||||||
|
|
||||||
return module, bindgen
|
return module, bindgen
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bindgenDecorator) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
func (b *bindgenDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
deps = b.baseSourceProvider.sourceProviderDeps(ctx, deps)
|
deps = b.BaseSourceProvider.SourceProviderDeps(ctx, deps)
|
||||||
if ctx.toolchain().Bionic() {
|
if ctx.toolchain().Bionic() {
|
||||||
deps = bionicDeps(deps)
|
deps = bionicDeps(deps)
|
||||||
}
|
}
|
||||||
|
10
rust/rust.go
10
rust/rust.go
@@ -83,7 +83,7 @@ type Module struct {
|
|||||||
clippy *clippy
|
clippy *clippy
|
||||||
cachedToolchain config.Toolchain
|
cachedToolchain config.Toolchain
|
||||||
sourceProvider SourceProvider
|
sourceProvider SourceProvider
|
||||||
subAndroidMkOnce map[subAndroidMkProvider]bool
|
subAndroidMkOnce map[SubAndroidMkProvider]bool
|
||||||
|
|
||||||
outputFile android.OptionalPath
|
outputFile android.OptionalPath
|
||||||
generatedFile android.OptionalPath
|
generatedFile android.OptionalPath
|
||||||
@@ -537,7 +537,7 @@ func (mod *Module) Init() android.Module {
|
|||||||
mod.AddProperties(mod.clippy.props()...)
|
mod.AddProperties(mod.clippy.props()...)
|
||||||
}
|
}
|
||||||
if mod.sourceProvider != nil {
|
if mod.sourceProvider != nil {
|
||||||
mod.AddProperties(mod.sourceProvider.sourceProviderProps()...)
|
mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
|
android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
|
||||||
@@ -671,10 +671,10 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
flags, deps = mod.clippy.flags(ctx, flags, deps)
|
flags, deps = mod.clippy.flags(ctx, flags, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceProvider needs to call generateSource() before compiler calls compile() so it can provide the source.
|
// SourceProvider needs to call GenerateSource() before compiler calls compile() so it can provide the source.
|
||||||
// TODO(b/162588681) This shouldn't have to run for every variant.
|
// TODO(b/162588681) This shouldn't have to run for every variant.
|
||||||
if mod.sourceProvider != nil {
|
if mod.sourceProvider != nil {
|
||||||
generatedFile := mod.sourceProvider.generateSource(ctx, deps)
|
generatedFile := mod.sourceProvider.GenerateSource(ctx, deps)
|
||||||
mod.generatedFile = android.OptionalPathForPath(generatedFile)
|
mod.generatedFile = android.OptionalPathForPath(generatedFile)
|
||||||
mod.sourceProvider.setSubName(ctx.ModuleSubDir())
|
mod.sourceProvider.setSubName(ctx.ModuleSubDir())
|
||||||
}
|
}
|
||||||
@@ -696,7 +696,7 @@ func (mod *Module) deps(ctx DepsContext) Deps {
|
|||||||
deps = mod.compiler.compilerDeps(ctx, deps)
|
deps = mod.compiler.compilerDeps(ctx, deps)
|
||||||
}
|
}
|
||||||
if mod.sourceProvider != nil {
|
if mod.sourceProvider != nil {
|
||||||
deps = mod.sourceProvider.sourceProviderDeps(ctx, deps)
|
deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mod.coverage != nil {
|
if mod.coverage != nil {
|
||||||
|
@@ -27,43 +27,60 @@ type SourceProviderProperties struct {
|
|||||||
Crate_name string `android:"arch_variant"`
|
Crate_name string `android:"arch_variant"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type baseSourceProvider struct {
|
type BaseSourceProvider struct {
|
||||||
Properties SourceProviderProperties
|
Properties SourceProviderProperties
|
||||||
|
|
||||||
outputFile android.Path
|
OutputFile android.Path
|
||||||
subAndroidMkOnce map[subAndroidMkProvider]bool
|
subAndroidMkOnce map[SubAndroidMkProvider]bool
|
||||||
subName string
|
subName string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SourceProvider = (*baseSourceProvider)(nil)
|
var _ SourceProvider = (*BaseSourceProvider)(nil)
|
||||||
|
|
||||||
type SourceProvider interface {
|
type SourceProvider interface {
|
||||||
generateSource(ctx android.ModuleContext, deps PathDeps) android.Path
|
GenerateSource(ctx android.ModuleContext, deps PathDeps) android.Path
|
||||||
Srcs() android.Paths
|
Srcs() android.Paths
|
||||||
sourceProviderProps() []interface{}
|
SourceProviderProps() []interface{}
|
||||||
sourceProviderDeps(ctx DepsContext, deps Deps) Deps
|
SourceProviderDeps(ctx DepsContext, deps Deps) Deps
|
||||||
setSubName(subName string)
|
setSubName(subName string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *baseSourceProvider) Srcs() android.Paths {
|
func (sp *BaseSourceProvider) Srcs() android.Paths {
|
||||||
return android.Paths{sp.outputFile}
|
return android.Paths{sp.OutputFile}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *baseSourceProvider) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
|
func (sp *BaseSourceProvider) GenerateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
|
||||||
panic("baseSourceProviderModule does not implement generateSource()")
|
panic("BaseSourceProviderModule does not implement GenerateSource()")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *baseSourceProvider) sourceProviderProps() []interface{} {
|
func (sp *BaseSourceProvider) SourceProviderProps() []interface{} {
|
||||||
return []interface{}{&sp.Properties}
|
return []interface{}{&sp.Properties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSourceProvider() *baseSourceProvider {
|
func NewSourceProvider() *BaseSourceProvider {
|
||||||
return &baseSourceProvider{
|
return &BaseSourceProvider{
|
||||||
Properties: SourceProviderProperties{},
|
Properties: SourceProviderProperties{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *baseSourceProvider) getStem(ctx android.ModuleContext) string {
|
func NewSourceProviderModule(hod android.HostOrDeviceSupported, sourceProvider SourceProvider, enableLints bool) *Module {
|
||||||
|
_, library := NewRustLibrary(hod)
|
||||||
|
library.BuildOnlyRust()
|
||||||
|
library.sourceProvider = sourceProvider
|
||||||
|
|
||||||
|
module := newModule(hod, android.MultilibBoth)
|
||||||
|
module.sourceProvider = sourceProvider
|
||||||
|
module.compiler = library
|
||||||
|
|
||||||
|
if !enableLints {
|
||||||
|
library.setNoLint()
|
||||||
|
module.setClippy(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return module
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sp *BaseSourceProvider) getStem(ctx android.ModuleContext) string {
|
||||||
if String(sp.Properties.Source_stem) == "" {
|
if String(sp.Properties.Source_stem) == "" {
|
||||||
ctx.PropertyErrorf("source_stem",
|
ctx.PropertyErrorf("source_stem",
|
||||||
"source_stem property is undefined but required for rust_bindgen modules")
|
"source_stem property is undefined but required for rust_bindgen modules")
|
||||||
@@ -71,10 +88,10 @@ func (sp *baseSourceProvider) getStem(ctx android.ModuleContext) string {
|
|||||||
return String(sp.Properties.Source_stem)
|
return String(sp.Properties.Source_stem)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *baseSourceProvider) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
func (sp *BaseSourceProvider) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *baseSourceProvider) setSubName(subName string) {
|
func (sp *BaseSourceProvider) setSubName(subName string) {
|
||||||
sp.subName = subName
|
sp.subName = subName
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user