Merge "Convert some properties to Configurable properties" into main

This commit is contained in:
Treehugger Robot 2024-05-24 20:52:27 +00:00 committed by Gerrit Code Review
commit c6b5fdbc5c
4 changed files with 31 additions and 20 deletions

View file

@ -19,6 +19,7 @@ import (
"strings"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
func init() {
@ -36,9 +37,9 @@ func RegisterFilegroupBuildComponents(ctx RegistrationContext) {
type fileGroupProperties struct {
// srcs lists files that will be included in this filegroup
Srcs []string `android:"path"`
Srcs proptools.Configurable[[]string] `android:"path"`
Exclude_srcs []string `android:"path"`
Exclude_srcs proptools.Configurable[[]string] `android:"path"`
// The base path to the files. May be used by other modules to determine which portion
// of the path to use. For example, when a filegroup is used as data in a cc_test rule,
@ -89,7 +90,7 @@ func (fg *fileGroup) JSONActions() []blueprint.JSONAction {
}
func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) {
fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs)
fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs.GetOrDefault(ctx, nil), fg.properties.Exclude_srcs.GetOrDefault(ctx, nil))
if fg.properties.Path != nil {
fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path))
}

View file

@ -74,11 +74,11 @@ var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterP
type prebuiltEtcProperties struct {
// Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
// Mutually exclusive with srcs.
Src *string `android:"path,arch_variant"`
Src proptools.Configurable[string] `android:"path,arch_variant,replace_instead_of_append"`
// Source files of this prebuilt. Can reference a genrule type module with the ":module" syntax.
// Mutually exclusive with src. When used, filename_from_src is set to true.
Srcs []string `android:"path,arch_variant"`
Srcs proptools.Configurable[[]string] `android:"path,arch_variant"`
// Optional name for the installed file. If unspecified, name of the module is used as the file
// name. Only available when using a single source (src).
@ -158,6 +158,8 @@ type PrebuiltEtc struct {
installDirPath android.InstallPath
additionalDependencies *android.Paths
usedSrcsProperty bool
makeClass string
}
@ -247,10 +249,10 @@ func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation
}
func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
if len(p.properties.Srcs) > 0 {
if len(p.properties.Srcs.GetOrDefault(ctx, nil)) > 0 {
panic(fmt.Errorf("SourceFilePath not available on multi-source prebuilt %q", p.Name()))
}
return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
return android.PathForModuleSrc(ctx, p.properties.Src.GetOrDefault(ctx, ""))
}
func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
@ -264,7 +266,7 @@ func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
}
func (p *PrebuiltEtc) OutputFile() android.OutputPath {
if len(p.properties.Srcs) > 0 {
if p.usedSrcsProperty {
panic(fmt.Errorf("OutputFile not available on multi-source prebuilt %q", p.Name()))
}
return p.outputFilePaths[0]
@ -319,7 +321,9 @@ func (p *PrebuiltEtc) installBaseDir(ctx android.ModuleContext) string {
func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var installs []installProperties
if p.properties.Src != nil && len(p.properties.Srcs) > 0 {
srcProperty := p.properties.Src.Get(ctx)
srcsProperty := p.properties.Srcs.GetOrDefault(ctx, nil)
if srcProperty.IsPresent() && len(srcsProperty) > 0 {
ctx.PropertyErrorf("src", "src is set. Cannot set srcs")
}
@ -331,8 +335,8 @@ func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
filename := proptools.String(p.properties.Filename)
filenameFromSrc := proptools.Bool(p.properties.Filename_from_src)
if p.properties.Src != nil {
p.sourceFilePaths = android.PathsForModuleSrc(ctx, []string{proptools.String(p.properties.Src)})
if srcProperty.IsPresent() {
p.sourceFilePaths = android.PathsForModuleSrc(ctx, []string{srcProperty.Get()})
// If the source was not found, set a fake source path to
// support AllowMissingDependencies executions.
if len(p.sourceFilePaths) == 0 {
@ -367,7 +371,8 @@ func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
symlinks: p.properties.Symlinks,
}
installs = append(installs, ip)
} else if len(p.properties.Srcs) > 0 {
} else if len(srcsProperty) > 0 {
p.usedSrcsProperty = true
if filename != "" {
ctx.PropertyErrorf("filename", "filename cannot be set when using srcs")
}
@ -377,7 +382,7 @@ func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if p.properties.Filename_from_src != nil {
ctx.PropertyErrorf("filename_from_src", "filename_from_src is implicitly set to true when using srcs")
}
p.sourceFilePaths = android.PathsForModuleSrc(ctx, p.properties.Srcs)
p.sourceFilePaths = android.PathsForModuleSrc(ctx, srcsProperty)
for _, src := range p.sourceFilePaths {
filename := src.Base()
output := android.PathForModuleOut(ctx, filename).OutputPath

View file

@ -197,7 +197,7 @@ type BaseCompilerProperties struct {
Features []string `android:"arch_variant"`
// list of configuration options to enable for this crate. To enable features, use the "features" property.
Cfgs []string `android:"arch_variant"`
Cfgs proptools.Configurable[[]string] `android:"arch_variant"`
// specific rust edition that should be used if the default version is not desired
Edition *string `android:"arch_variant"`
@ -338,7 +338,7 @@ func (compiler *baseCompiler) compilerProps() []interface{} {
}
func cfgsToFlags(cfgs []string) []string {
flags := []string{}
flags := make([]string, 0, len(cfgs))
for _, cfg := range cfgs {
flags = append(flags, "--cfg '"+cfg+"'")
}
@ -385,8 +385,9 @@ func CommonDefaultCfgFlags(flags Flags, vendor bool, product bool) Flags {
func (compiler *baseCompiler) cfgFlags(ctx ModuleContext, flags Flags) Flags {
flags = CommonDefaultCfgFlags(flags, ctx.RustModule().InVendor(), ctx.RustModule().InProduct())
flags.RustFlags = append(flags.RustFlags, cfgsToFlags(compiler.Properties.Cfgs)...)
flags.RustdocFlags = append(flags.RustdocFlags, cfgsToFlags(compiler.Properties.Cfgs)...)
cfgFlags := cfgsToFlags(compiler.Properties.Cfgs.GetOrDefault(ctx, nil))
flags.RustFlags = append(flags.RustFlags, cfgFlags...)
flags.RustdocFlags = append(flags.RustdocFlags, cfgFlags...)
return flags
}

View file

@ -504,15 +504,19 @@ func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags
flags = library.baseCompiler.cfgFlags(ctx, flags)
flags = CommonLibraryCfgFlags(ctx, flags)
cfgs := library.baseCompiler.Properties.Cfgs.GetOrDefault(ctx, nil)
if library.dylib() {
// We need to add a dependency on std in order to link crates as dylibs.
// The hack to add this dependency is guarded by the following cfg so
// that we don't force a dependency when it isn't needed.
library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
cfgs = append(cfgs, "android_dylib")
}
flags.RustFlags = append(flags.RustFlags, cfgsToFlags(library.baseCompiler.Properties.Cfgs)...)
flags.RustdocFlags = append(flags.RustdocFlags, cfgsToFlags(library.baseCompiler.Properties.Cfgs)...)
cfgFlags := cfgsToFlags(cfgs)
flags.RustFlags = append(flags.RustFlags, cfgFlags...)
flags.RustdocFlags = append(flags.RustdocFlags, cfgFlags...)
return flags
}