Convert some properties to Configurable properties
Focusing on the properties needed to remove soong config modules from
packages/modules/Virtualization.
- prebuilt_etc's src and srcs
- filegroup's srcs and exclude_srcs
- rust's cfgs
Bug: 342006386
Test: m nothing --no-skip-soong-tests
Change-Id: I6971da744a17955f98104948e6f9614776955782
diff --git a/android/filegroup.go b/android/filegroup.go
index a8326d4..ff0f74e 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -19,6 +19,7 @@
"strings"
"github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
)
func init() {
@@ -36,9 +37,9 @@
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) 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))
}
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index e168edc..fd3b27f 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -74,11 +74,11 @@
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 @@
installDirPath android.InstallPath
additionalDependencies *android.Paths
+ usedSrcsProperty bool
+
makeClass string
}
@@ -247,10 +249,10 @@
}
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) 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) 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 @@
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 @@
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 @@
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
diff --git a/rust/compiler.go b/rust/compiler.go
index efc3dee..a2546a1 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -197,7 +197,7 @@
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 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 (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
}
diff --git a/rust/library.go b/rust/library.go
index 1eb0c5e..2a21263 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -504,15 +504,19 @@
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
}