summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-03-13 12:32:15 -0700
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2025-03-13 12:32:15 -0700
commitf6138662ae92cbeebaae8588279ed281c4737cd5 (patch)
tree7a1fd237e1a32fb8adacb2bbbcde34ba61a0677a
parent9ac53f04e6d198e33ed3f3834fe423011c086161 (diff)
parentf729d2e617bef827503888c76383ab9e6bf7c8d7 (diff)
Merge "Disallow prebuilt_root module type from setting Dsts property" into main
-rw-r--r--etc/prebuilt_etc.go26
-rw-r--r--fsgen/filesystem_creator_test.go36
-rw-r--r--fsgen/prebuilt_etc_modules_gen.go10
3 files changed, 53 insertions, 19 deletions
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index bf32d417e..6b581bcd3 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -116,12 +116,6 @@ type PrebuiltEtcProperties struct {
// set. May use globs in filenames.
Srcs proptools.Configurable[[]string] `android:"path,arch_variant"`
- // Destination files of this prebuilt. Requires srcs to be used and causes srcs not to implicitly
- // set filename_from_src. This can be used to install each source file to a different directory
- // and/or change filenames when files are installed. Must be exactly one entry per source file,
- // which means care must be taken if srcs has globs.
- Dsts 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).
Filename *string `android:"arch_variant"`
@@ -160,6 +154,20 @@ type PrebuiltEtcProperties struct {
Oem_specific *bool `android:"arch_variant"`
}
+// Dsts is useful in that it allows prebuilt_* modules to easily map the source files to the
+// install path within the partition. Dsts values are allowed to contain filepath separator
+// so that the source files can be installed in subdirectories within the partition.
+// However, this functionality should not be supported for prebuilt_root module type, as it
+// allows the module to install to any arbitrary location. Thus, this property is defined in
+// a separate struct so that it's not available to be set in prebuilt_root module type.
+type PrebuiltDstsProperties struct {
+ // Destination files of this prebuilt. Requires srcs to be used and causes srcs not to implicitly
+ // set filename_from_src. This can be used to install each source file to a different directory
+ // and/or change filenames when files are installed. Must be exactly one entry per source file,
+ // which means care must be taken if srcs has globs.
+ Dsts proptools.Configurable[[]string] `android:"path,arch_variant"`
+}
+
type prebuiltSubdirProperties struct {
// Optional subdirectory under which this file is installed into, cannot be specified with
// relative_install_path, prefer relative_install_path.
@@ -195,6 +203,8 @@ type PrebuiltEtc struct {
properties PrebuiltEtcProperties
+ dstsProperties PrebuiltDstsProperties
+
// rootProperties is used to return the value of the InstallInRoot() method. Currently, only
// prebuilt_avb and prebuilt_root modules use this.
rootProperties prebuiltRootProperties
@@ -385,7 +395,7 @@ func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if srcProperty.IsPresent() && len(srcsProperty) > 0 {
ctx.PropertyErrorf("src", "src is set. Cannot set srcs")
}
- dstsProperty := p.properties.Dsts.GetOrDefault(ctx, nil)
+ dstsProperty := p.dstsProperties.Dsts.GetOrDefault(ctx, nil)
if len(dstsProperty) > 0 && len(srcsProperty) == 0 {
ctx.PropertyErrorf("dsts", "dsts is set. Must use srcs")
}
@@ -613,6 +623,7 @@ func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
p.AddProperties(&p.properties)
p.AddProperties(&p.subdirProperties)
p.AddProperties(&p.rootProperties)
+ p.AddProperties(&p.dstsProperties)
}
func InitPrebuiltRootModule(p *PrebuiltEtc) {
@@ -624,6 +635,7 @@ func InitPrebuiltRootModule(p *PrebuiltEtc) {
func InitPrebuiltAvbModule(p *PrebuiltEtc) {
p.installDirBase = "avb"
p.AddProperties(&p.properties)
+ p.AddProperties(&p.dstsProperties)
p.rootProperties.Install_in_root = proptools.BoolPtr(true)
}
diff --git a/fsgen/filesystem_creator_test.go b/fsgen/filesystem_creator_test.go
index ba40f3f5e..81236a0a1 100644
--- a/fsgen/filesystem_creator_test.go
+++ b/fsgen/filesystem_creator_test.go
@@ -366,15 +366,25 @@ func TestPrebuiltEtcModuleGen(t *testing.T) {
eval := generatedModule0.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext))
android.AssertBoolEquals(
t,
- "module expected to set correct srcs and dsts properties",
+ "module expected to set correct srcs property",
true,
checkModuleProp(generatedModule0, func(actual interface{}) bool {
if p, ok := actual.(*etc.PrebuiltEtcProperties); ok {
srcs := p.Srcs.GetOrDefault(eval, nil)
- dsts := p.Dsts.GetOrDefault(eval, nil)
return len(srcs) == 1 &&
- srcs[0] == "apns-full-conf.xml" &&
- len(dsts) == 1 &&
+ srcs[0] == "apns-full-conf.xml"
+ }
+ return false
+ }),
+ )
+ android.AssertBoolEquals(
+ t,
+ "module expected to set correct dsts property",
+ true,
+ checkModuleProp(generatedModule0, func(actual interface{}) bool {
+ if p, ok := actual.(*etc.PrebuiltDstsProperties); ok {
+ dsts := p.Dsts.GetOrDefault(eval, nil)
+ return len(dsts) == 1 &&
dsts[0] == "apns-conf.xml"
}
return false
@@ -385,15 +395,25 @@ func TestPrebuiltEtcModuleGen(t *testing.T) {
eval = generatedModule1.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext))
android.AssertBoolEquals(
t,
- "module expected to set correct srcs and dsts properties",
+ "module expected to set correct srcs property",
true,
checkModuleProp(generatedModule1, func(actual interface{}) bool {
if p, ok := actual.(*etc.PrebuiltEtcProperties); ok {
srcs := p.Srcs.GetOrDefault(eval, nil)
- dsts := p.Dsts.GetOrDefault(eval, nil)
return len(srcs) == 1 &&
- srcs[0] == "apns-full-conf.xml" &&
- len(dsts) == 1 &&
+ srcs[0] == "apns-full-conf.xml"
+ }
+ return false
+ }),
+ )
+ android.AssertBoolEquals(
+ t,
+ "module expected to set correct dsts property",
+ true,
+ checkModuleProp(generatedModule1, func(actual interface{}) bool {
+ if p, ok := actual.(*etc.PrebuiltDstsProperties); ok {
+ dsts := p.Dsts.GetOrDefault(eval, nil)
+ return len(dsts) == 1 &&
dsts[0] == "apns-conf-2.xml"
}
return false
diff --git a/fsgen/prebuilt_etc_modules_gen.go b/fsgen/prebuilt_etc_modules_gen.go
index 3f088a3fd..a0b019597 100644
--- a/fsgen/prebuilt_etc_modules_gen.go
+++ b/fsgen/prebuilt_etc_modules_gen.go
@@ -164,7 +164,6 @@ type prebuiltModuleProperties struct {
Ramdisk *bool
Srcs []string
- Dsts []string
No_full_install *bool
@@ -357,11 +356,14 @@ func createPrebuiltEtcModulesInDirectory(ctx android.LoadHookContext, partition,
moduleFactory = etc.PrebuiltAnyFactory
}
modulePropsPtr.Srcs = srcBaseFiles
- dsts := []string{}
+ dsts := proptools.NewConfigurable[[]string](nil, nil)
for _, installBaseFile := range installBaseFiles {
- dsts = append(dsts, filepath.Join(relDestDirFromInstallDirBase, installBaseFile))
+ dsts.AppendSimpleValue([]string{filepath.Join(relDestDirFromInstallDirBase, installBaseFile)})
}
- modulePropsPtr.Dsts = dsts
+
+ propsList = append(propsList, &etc.PrebuiltDstsProperties{
+ Dsts: dsts,
+ })
}
ctx.CreateModuleInDirectory(moduleFactory, srcDir, propsList...)