Merge "Make platform_bootclasspath a regular module" into main
diff --git a/android/dirgroup.go b/android/dirgroup.go
index 20c4d13..62fbaa5 100644
--- a/android/dirgroup.go
+++ b/android/dirgroup.go
@@ -39,8 +39,7 @@
}
type DirInfo struct {
- // TODO(b/358302178): Use DirectoryPaths instead of Paths
- Dirs Paths
+ Dirs DirectoryPaths
}
var DirProvider = blueprint.NewProvider[DirInfo]()
diff --git a/android/module_context.go b/android/module_context.go
index 9fa3fa3..1f5e706 100644
--- a/android/module_context.go
+++ b/android/module_context.go
@@ -19,6 +19,7 @@
"github.com/google/blueprint/depset"
"path"
"path/filepath"
+ "slices"
"strings"
"github.com/google/blueprint"
@@ -562,9 +563,22 @@
m.aconfigFilePaths = paths
}
+func (m *moduleContext) getOwnerAndOverrides() (string, []string) {
+ owner := m.ModuleName()
+ overrides := slices.Clone(m.Module().base().commonProperties.Overrides)
+ if b, ok := m.Module().(OverridableModule); ok {
+ if b.GetOverriddenBy() != "" {
+ // overriding variant of base module
+ overrides = append(overrides, m.ModuleName()) // com.android.foo
+ owner = m.Module().Name() // com.company.android.foo
+ }
+ }
+ return owner, overrides
+}
+
func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
licenseFiles := m.Module().EffectiveLicenseFiles()
- overrides := CopyOf(m.Module().base().commonProperties.Overrides)
+ owner, overrides := m.getOwnerAndOverrides()
spec := PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: srcPath,
@@ -576,7 +590,7 @@
aconfigPaths: m.getAconfigPaths(),
archType: m.target.Arch.ArchType,
overrides: &overrides,
- owner: m.ModuleName(),
+ owner: owner,
}
m.packagingSpecs = append(m.packagingSpecs, spec)
return spec
@@ -695,7 +709,7 @@
m.installFiles = append(m.installFiles, fullInstallPath)
}
- overrides := CopyOf(m.Module().base().commonProperties.Overrides)
+ owner, overrides := m.getOwnerAndOverrides()
m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: nil,
@@ -706,7 +720,7 @@
aconfigPaths: m.getAconfigPaths(),
archType: m.target.Arch.ArchType,
overrides: &overrides,
- owner: m.ModuleName(),
+ owner: owner,
})
return fullInstallPath
@@ -742,7 +756,7 @@
m.installFiles = append(m.installFiles, fullInstallPath)
}
- overrides := CopyOf(m.Module().base().commonProperties.Overrides)
+ owner, overrides := m.getOwnerAndOverrides()
m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: nil,
@@ -753,7 +767,7 @@
aconfigPaths: m.getAconfigPaths(),
archType: m.target.Arch.ArchType,
overrides: &overrides,
- owner: m.ModuleName(),
+ owner: owner,
})
return fullInstallPath
diff --git a/android/paths.go b/android/paths.go
index bf2c3a0..a7ee7ac 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -551,15 +551,35 @@
return ret
}
+type directoryPath struct {
+ basePath
+}
+
+func (d *directoryPath) String() string {
+ return d.basePath.String()
+}
+
+func (d *directoryPath) base() basePath {
+ return d.basePath
+}
+
+// DirectoryPath represents a source path for directories. Incompatible with Path by design.
+type DirectoryPath interface {
+ String() string
+ base() basePath
+}
+
+var _ DirectoryPath = (*directoryPath)(nil)
+
+type DirectoryPaths []DirectoryPath
+
// DirectoryPathsForModuleSrcExcludes returns a Paths{} containing the resolved references in
// directory paths. Elements of paths are resolved as:
// - filepath, relative to local module directory, resolves as a filepath relative to the local
// source directory
// - other modules using the ":name" syntax. These modules must implement DirProvider.
-//
-// TODO(b/358302178): Implement DirectoryPath and change the return type.
-func DirectoryPathsForModuleSrc(ctx ModuleMissingDepsPathContext, paths []string) Paths {
- var ret Paths
+func DirectoryPathsForModuleSrc(ctx ModuleMissingDepsPathContext, paths []string) DirectoryPaths {
+ var ret DirectoryPaths
for _, path := range paths {
if m, t := SrcIsModuleWithTag(path); m != "" {
@@ -588,12 +608,12 @@
} else if !isDir {
ReportPathErrorf(ctx, "module directory path %q is not a directory", p)
} else {
- ret = append(ret, p)
+ ret = append(ret, &directoryPath{basePath{path: p.path, rel: p.rel}})
}
}
}
- seen := make(map[Path]bool, len(ret))
+ seen := make(map[DirectoryPath]bool, len(ret))
for _, path := range ret {
if seen[path] {
ReportPathErrorf(ctx, "duplicated path %q", path)
diff --git a/android/paths_test.go b/android/paths_test.go
index 941f0ca..5e618f9 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -1592,6 +1592,12 @@
})
}
+func TestDirectoryPathIsIncompatibleWithPath(t *testing.T) {
+ d := (DirectoryPath)(&directoryPath{})
+ _, ok := d.(Path)
+ AssertBoolEquals(t, "directoryPath shouldn't implement Path", ok, false)
+}
+
func ExampleOutputPath_ReplaceExtension() {
ctx := &configErrorWrapper{
config: TestConfig("out", nil, "", nil),
diff --git a/android/rule_builder.go b/android/rule_builder.go
index 56de9cd..403c184 100644
--- a/android/rule_builder.go
+++ b/android/rule_builder.go
@@ -575,25 +575,28 @@
nsjailCmd.WriteString(r.outDir.String())
nsjailCmd.WriteString(":nsjail_build_sandbox/out")
- for _, input := range inputs {
+ addBindMount := func(src, dst string) {
nsjailCmd.WriteString(" -R $PWD/")
- nsjailCmd.WriteString(input.String())
+ nsjailCmd.WriteString(src)
nsjailCmd.WriteString(":nsjail_build_sandbox/")
- nsjailCmd.WriteString(r.nsjailPathForInputRel(input))
+ nsjailCmd.WriteString(dst)
+ }
+
+ for _, input := range inputs {
+ addBindMount(input.String(), r.nsjailPathForInputRel(input))
}
for _, tool := range tools {
- nsjailCmd.WriteString(" -R $PWD/")
- nsjailCmd.WriteString(tool.String())
- nsjailCmd.WriteString(":nsjail_build_sandbox/")
- nsjailCmd.WriteString(nsjailPathForToolRel(r.ctx, tool))
+ addBindMount(tool.String(), nsjailPathForToolRel(r.ctx, tool))
}
inputs = append(inputs, tools...)
for _, c := range r.commands {
+ for _, directory := range c.implicitDirectories {
+ addBindMount(directory.String(), directory.String())
+ // TODO(b/375551969): Add implicitDirectories to BuildParams, rather than relying on implicits
+ inputs = append(inputs, SourcePath{basePath: directory.base()})
+ }
for _, tool := range c.packagedTools {
- nsjailCmd.WriteString(" -R $PWD/")
- nsjailCmd.WriteString(tool.srcPath.String())
- nsjailCmd.WriteString(":nsjail_build_sandbox/")
- nsjailCmd.WriteString(nsjailPathForPackagedToolRel(tool))
+ addBindMount(tool.srcPath.String(), nsjailPathForPackagedToolRel(tool))
inputs = append(inputs, tool.srcPath)
}
}
@@ -917,16 +920,17 @@
type RuleBuilderCommand struct {
rule *RuleBuilder
- buf strings.Builder
- inputs Paths
- implicits Paths
- orderOnlys Paths
- validations Paths
- outputs WritablePaths
- depFiles WritablePaths
- tools Paths
- packagedTools []PackagingSpec
- rspFiles []rspFileAndPaths
+ buf strings.Builder
+ inputs Paths
+ implicits Paths
+ orderOnlys Paths
+ validations Paths
+ outputs WritablePaths
+ depFiles WritablePaths
+ tools Paths
+ packagedTools []PackagingSpec
+ rspFiles []rspFileAndPaths
+ implicitDirectories DirectoryPaths
}
type rspFileAndPaths struct {
@@ -951,6 +955,10 @@
c.implicits = append(c.implicits, path)
}
+func (c *RuleBuilderCommand) addImplicitDirectory(path DirectoryPath) {
+ c.implicitDirectories = append(c.implicitDirectories, path)
+}
+
func (c *RuleBuilderCommand) addOrderOnly(path Path) {
checkPathNotNil(path)
c.orderOnlys = append(c.orderOnlys, path)
@@ -1313,6 +1321,16 @@
return c
}
+// ImplicitDirectory adds the specified input directory to the dependencies without modifying the
+// command line. Added directories will be bind-mounted for the nsjail.
+func (c *RuleBuilderCommand) ImplicitDirectory(path DirectoryPath) *RuleBuilderCommand {
+ if !c.rule.nsjail {
+ panic("ImplicitDirectory() must be called after Nsjail()")
+ }
+ c.addImplicitDirectory(path)
+ return c
+}
+
// GetImplicits returns the command's implicit inputs.
func (c *RuleBuilderCommand) GetImplicits() Paths {
return c.implicits
diff --git a/android/util.go b/android/util.go
index 2d269b7..3fc4608 100644
--- a/android/util.go
+++ b/android/util.go
@@ -660,3 +660,13 @@
v, loaded := m.Map.LoadOrStore(key, value)
return v.(V), loaded
}
+
+// AppendIfNotZero append the given value to the slice if it is not the zero value
+// for its type.
+func AppendIfNotZero[T comparable](slice []T, value T) []T {
+ var zeroValue T // Get the zero value of the type T
+ if value != zeroValue {
+ return append(slice, value)
+ }
+ return slice
+}
diff --git a/cc/cc.go b/cc/cc.go
index 551f2cd..5dee32e 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -35,6 +35,14 @@
"android/soong/genrule"
)
+type CcMakeVarsInfo struct {
+ WarningsAllowed string
+ UsingWnoError string
+ MissingProfile string
+}
+
+var CcMakeVarsInfoProvider = blueprint.NewProvider[*CcMakeVarsInfo]()
+
func init() {
RegisterCCBuildComponents(android.InitRegistrationContext)
@@ -531,6 +539,7 @@
getSharedFlags() *SharedFlags
notInPlatform() bool
optimizeForSize() bool
+ getOrCreateMakeVarsInfo() *CcMakeVarsInfo
}
type SharedFlags struct {
@@ -845,9 +854,10 @@
sourceProperties android.SourceProperties
// initialize before calling Init
- hod android.HostOrDeviceSupported
- multilib android.Multilib
- testModule bool
+ hod android.HostOrDeviceSupported
+ multilib android.Multilib
+ testModule bool
+ incremental bool
// Allowable SdkMemberTypes of this module type.
sdkMemberTypes []android.SdkMemberType
@@ -913,8 +923,16 @@
hasSysprop bool
hasWinMsg bool
hasYacc bool
+
+ makeVarsInfo *CcMakeVarsInfo
}
+func (c *Module) IncrementalSupported() bool {
+ return c.incremental
+}
+
+var _ blueprint.Incremental = (*Module)(nil)
+
func (c *Module) AddJSONData(d *map[string]interface{}) {
c.AndroidModuleBase().AddJSONData(d)
(*d)["Cc"] = map[string]interface{}{
@@ -1700,6 +1718,13 @@
return ctx.mod.NotInPlatform()
}
+func (ctx *moduleContextImpl) getOrCreateMakeVarsInfo() *CcMakeVarsInfo {
+ if ctx.mod.makeVarsInfo == nil {
+ ctx.mod.makeVarsInfo = &CcMakeVarsInfo{}
+ }
+ return ctx.mod.makeVarsInfo
+}
+
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
return &Module{
hod: hod,
@@ -2091,6 +2116,10 @@
}
c.setOutputFiles(ctx)
+
+ if c.makeVarsInfo != nil {
+ android.SetProvider(ctx, CcMakeVarsInfoProvider, c.makeVarsInfo)
+ }
}
func (c *Module) setOutputFiles(ctx ModuleContext) {
diff --git a/cc/compiler.go b/cc/compiler.go
index f06287c..0fa058a 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -685,10 +685,10 @@
if len(srcs) > 0 {
module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
if inList("-Wno-error", flags.Local.CFlags) || inList("-Wno-error", flags.Local.CppFlags) {
- addToModuleList(ctx, modulesUsingWnoErrorKey, module)
+ ctx.getOrCreateMakeVarsInfo().UsingWnoError = module
} else if !inList("-Werror", flags.Local.CFlags) && !inList("-Werror", flags.Local.CppFlags) {
if warningsAreAllowed(ctx.ModuleDir()) {
- addToModuleList(ctx, modulesWarningsAllowedKey, module)
+ ctx.getOrCreateMakeVarsInfo().WarningsAllowed = module
} else {
flags.Local.CFlags = append([]string{"-Werror"}, flags.Local.CFlags...)
}
diff --git a/cc/makevars.go b/cc/makevars.go
index f82e0e9..4cb98e7 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -25,10 +25,7 @@
)
var (
- modulesWarningsAllowedKey = android.NewOnceKey("ModulesWarningsAllowed")
- modulesUsingWnoErrorKey = android.NewOnceKey("ModulesUsingWnoError")
- modulesMissingProfileFileKey = android.NewOnceKey("ModulesMissingProfileFile")
- sanitizerVariables = map[string]string{
+ sanitizerVariables = map[string]string{
"ADDRESS_SANITIZER_RUNTIME_LIBRARY": config.AddressSanitizerRuntimeLibrary(),
"HWADDRESS_SANITIZER_RUNTIME_LIBRARY": config.HWAddressSanitizerRuntimeLibrary(),
"HWADDRESS_SANITIZER_STATIC_LIBRARY": config.HWAddressSanitizerStaticLibrary(),
@@ -50,15 +47,9 @@
}).(*sync.Map)
}
-func makeStringOfKeys(ctx android.MakeVarsContext, key android.OnceKey) string {
- set := getNamedMapForConfig(ctx.Config(), key)
- keys := []string{}
- set.Range(func(key interface{}, value interface{}) bool {
- keys = append(keys, key.(string))
- return true
- })
- sort.Strings(keys)
- return strings.Join(keys, " ")
+func makeVarsString(items []string) string {
+ items = android.SortedUniqueStrings(items)
+ return strings.Join(items, " ")
}
func makeStringOfWarningAllowedProjects() string {
@@ -108,28 +99,33 @@
ctx.Strict("GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideExternalGlobalCflags}")
// Filter vendor_public_library that are exported to make
- exportedVendorPublicLibraries := []string{}
+ var exportedVendorPublicLibraries []string
+ var warningsAllowed []string
+ var usingWnoErrors []string
+ var missingProfiles []string
ctx.VisitAllModules(func(module android.Module) {
+ if v, ok := android.OtherModuleProvider(ctx, module, CcMakeVarsInfoProvider); ok {
+ warningsAllowed = android.AppendIfNotZero(warningsAllowed, v.WarningsAllowed)
+ usingWnoErrors = android.AppendIfNotZero(usingWnoErrors, v.UsingWnoError)
+ missingProfiles = android.AppendIfNotZero(missingProfiles, v.MissingProfile)
+ }
if ccModule, ok := module.(*Module); ok {
baseName := ccModule.BaseModuleName()
if ccModule.IsVendorPublicLibrary() && module.ExportedToMake() {
- if !inList(baseName, exportedVendorPublicLibraries) {
- exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName)
- }
+ exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName)
}
}
})
- sort.Strings(exportedVendorPublicLibraries)
- ctx.Strict("VENDOR_PUBLIC_LIBRARIES", strings.Join(exportedVendorPublicLibraries, " "))
+ ctx.Strict("VENDOR_PUBLIC_LIBRARIES", makeVarsString(exportedVendorPublicLibraries))
lsdumpPaths := *lsdumpPaths(ctx.Config())
sort.Strings(lsdumpPaths)
ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " "))
ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
- ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", makeStringOfKeys(ctx, modulesWarningsAllowedKey))
- ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoErrorKey))
- ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFileKey))
+ ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", makeVarsString(warningsAllowed))
+ ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeVarsString(usingWnoErrors))
+ ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeVarsString(missingProfiles))
ctx.Strict("CLANG_COVERAGE_CONFIG_CFLAGS", strings.Join(clangCoverageCFlags, " "))
ctx.Strict("CLANG_COVERAGE_CONFIG_COMMFLAGS", strings.Join(clangCoverageCommonFlags, " "))
diff --git a/cc/orderfile.go b/cc/orderfile.go
index 38b8905..6e08da7 100644
--- a/cc/orderfile.go
+++ b/cc/orderfile.go
@@ -54,10 +54,6 @@
})
}
-func recordMissingOrderfile(ctx BaseModuleContext, missing string) {
- getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true)
-}
-
type OrderfileProperties struct {
Orderfile struct {
Instrumentation *bool
@@ -117,7 +113,7 @@
// Record that this module's order file is absent
missing := *props.Orderfile.Order_file_path + ":" + ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
- recordMissingOrderfile(ctx, missing)
+ ctx.getOrCreateMakeVarsInfo().MissingProfile = missing
return android.OptionalPath{}
}
diff --git a/docs/selects.md b/docs/selects.md
new file mode 100644
index 0000000..4f436ac
--- /dev/null
+++ b/docs/selects.md
@@ -0,0 +1,170 @@
+# Select statements
+
+## Introduction
+
+Soong currently has the arch, target, product_variables, and soong config variable properties that all support changing the values of soong properties based on some condition. These are confusing for users, and particularly the soong config variable properties require a lot of boilerplate that is annoying to write.
+
+In addition, these properties are all implemented using reflection on property structs, and can combine in ways that the original authors did not expect. For example, soong config variables can be combined with arch/target by saying that they operate on "arch.arm.enabled" instead of just "enabled". But product variables do not have the same abilities.
+
+The goal here is to combine all these different configuration mechanisms into one, to reduce complexity and boilerplate both in Android.bp files and in soong code.
+
+## Usage
+
+The soong select statements take their name and inspiration from [bazel select statements](https://bazel.build/docs/configurable-attributes).
+
+### Syntax
+
+#### Basic
+
+The basic syntax for select statements looks like:
+
+```
+my_module_type {
+ name: "my_module",
+ some_string_property: select(arch(), {
+ "arm": "foo",
+ "x86": "bar",
+ default: "baz",
+ }),
+}
+```
+
+That is, `select(` followed by a variable function, then a map of values of the variable to values to set the property to.
+
+Arguments can be passed to the "functions" that look up axes:
+
+```
+select(soong_config_variable("my_namespace", "my_variable"), {
+ "value1": "foo",
+ default: "bar",
+})
+```
+
+
+The list of functions that can currently be selected on:
+ - `arch()`
+ - `os()`
+ - `soong_config_variable(namespace, variable)`
+ - `release_flag(flag)`
+
+The functions are [defined here](https://cs.android.com/android/platform/superproject/main/+/main:build/soong/android/module.go;l=2144;drc=3f01580c04bfe37c920e247015cce93cff2451c0), and it should be easy to add more.
+
+#### Multivariable
+
+To handle multivariable selects, multiple axes can be specified within parenthesis, to look like tuple destructuring. All of the variables being selected must match the corresponding value from the branch in order for the branch to be chosen.
+
+```
+select((arch(), os()), {
+ ("arm", "linux"): "foo",
+ (default, "windows"): "bar",
+ (default, default): "baz",
+})
+```
+
+#### Unset
+
+You can have unset branches of selects using the "unset" keyword, which will act as if the property was not assigned to. This is only really useful if you’re using defaults modules.
+
+```
+cc_binary {
+ name: "my_binary",
+ enabled: select(os(), {
+ "darwin": false,
+ default: unset,
+ }),
+}
+```
+
+#### Appending
+
+You can append select statements to both scalar values and other select statements:
+
+```
+my_module_type {
+ name: "my_module",
+ // string_property will be set to something like penguin-four, apple-two, etc.
+ string_property: select(os(), {
+ "linux_glibc": "penguin",
+ "darwin": "apple",
+ default: "unknown",
+ }) + "-" + select(soong_config_variable("ANDROID", "favorite_vehicle"), {
+ "car": "four",
+ "tricycle": "three",
+ "bike": "two",
+ default: "unknown",
+ })
+}
+```
+
+
+You can also append a select with a value with another select that may not have a value, because some of its branches are "unset". If an unset branch was selected it will not append anything to the other select.
+
+#### Binding the selected value to a Blueprint variable and the "any" keyword
+
+In case you want to allow a selected value to have an unbounded number of possible values, you can bind its value to a blueprint variable and use it within the expression for that select branch.
+
+```
+my_module_type {
+ name: "my_module",
+ my_string_property: select(soong_config_variable("my_namespace", "my_variable"), {
+ "some_value": "baz",
+ any @ my_var: "foo" + my_var,
+ default: "bar",
+ }),
+}
+```
+
+The syntax is `any @ my_variable_name: <expression using my_variable_name>`. `any` is currently the only pattern that can be bound to a variable, but we may add more in the future. `any` is equivalent to `default` except it will not match undefined select conditions.
+
+#### Errors
+
+If a select statement does not have a "default" branch, and none of the other branches match the variable being selected on, it’s a compile-time error. This may be useful for enforcing a variable is 1 of only a few values.
+
+```
+# in product config:
+$(call soong_config_set,ANDROID,my_variable,foo)
+
+// in an Android.bp:
+my_module_type {
+ name: "my_module",
+ // Will error out with: soong_config_variable("ANDROID", "my_variable") had value "foo", which was not handled by the select
+ enabled: select(soong_config_variable("ANDROID", "my_variable"), {
+ "bar": true,
+ "baz": false,
+ }),
+}
+```
+
+### Changes to property structs to support selects
+
+Currently, the way configurable properties work is that there is secretly another property struct that has the `target`, `arch`, etc. properties, and then when the arch mutator (or other relevant mutator) runs, it copies the values of these properties onto the regular property structs. There’s nothing stopping you from accessing your properties from a mutator that runs before the one that updates the properties based on configurable values. This is a potential source of bugs, and we want to make sure that select statements don’t have the same pitfall. For that reason, you have to read property’s values through a getter which can do this check. This requires changing the code on a property-by-property basis to support selects.
+
+To make a property support selects, it must be of type [proptools.Configurable[T]](https://cs.android.com/android/platform/superproject/main/+/main:build/blueprint/proptools/configurable.go;l=341;drc=a52b058cccd2caa778d0f97077adcd4ef7ffb68a). T is the old type of the property. Currently we support bool, string, and []string. Configurable has a `Get(evaluator)` method to get the value of the property. The evaluator can be a ModuleContext, or if you’re in a situation where you only have a very limited context and a module, (such as in a singleton) you can use [ModuleBase.ConfigurableEvaluator](https://cs.android.com/android/platform/superproject/main/+/main:build/soong/android/module.go;l=2133;drc=e19f741052cce097da940d9083d3f29e668de5cb).
+
+`proptools.Configurable[T]` will handle unset properties for you, so you don’t need to make it a pointer type. However, there is a not-widely-known feature of property structs, where normally, properties are appended when squashing defaults. But if the property was a pointer property, later defaults replace earlier values instead of appending. With selects, to maintain this behavior, add the `android:"replace_instead_of_append"` struct tag. The "append" behavior for boolean values is to boolean OR them together, which is rarely what you want, so most boolean properties are pointers today.
+
+Old:
+```
+type commonProperties struct {
+ Enabled *bool `android:"arch_variant"`
+}
+
+func (m *ModuleBase) Enabled() *bool {
+ return m.commonProperties.Enabled
+}
+```
+
+New:
+```
+type commonProperties struct {
+ Enabled proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
+}
+
+func (m *ModuleBase) Enabled(ctx ConfigAndErrorContext) *bool {
+ return m.commonProperties.Enabled.Get(m.ConfigurableEvaluator(ctx))
+}
+```
+
+The `android:"arch_variant"` tag is kept to support the old `target:` and `arch:` properties with this property, but if all their usages in bp files were replaced by selects, then that tag could be removed.
+
+The enabled property underwent this migration in https://r.android.com/3066188
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go
index f767eae..29f9373 100644
--- a/filesystem/filesystem_test.go
+++ b/filesystem/filesystem_test.go
@@ -691,3 +691,27 @@
android.AssertStringDoesContain(t, "Could not find linker.config.json file in cmd", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json")
android.AssertStringDoesContain(t, "Could not find stub in `provideLibs`", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so")
}
+
+// override_android_* modules implicitly override their base module.
+// If both of these are listed in `deps`, the base module should not be installed.
+func TestOverrideModulesInDeps(t *testing.T) {
+ result := fixture.RunTestWithBp(t, `
+ android_filesystem {
+ name: "myfilesystem",
+ deps: ["myapp", "myoverrideapp"],
+ }
+
+ android_app {
+ name: "myapp",
+ platform_apis: true,
+ }
+ override_android_app {
+ name: "myoverrideapp",
+ base: "myapp",
+ }
+ `)
+
+ partition := result.ModuleForTests("myfilesystem", "android_common")
+ fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
+ android.AssertStringEquals(t, "filesystem with override app", "app/myoverrideapp/myoverrideapp.apk\n", fileList)
+}
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go
index 001cac8..06e154a 100644
--- a/fsgen/filesystem_creator.go
+++ b/fsgen/filesystem_creator.go
@@ -68,7 +68,7 @@
}
// Map of module name to depCandidateProps
-type multilibDeps *map[string]*depCandidateProps
+type multilibDeps map[string]*depCandidateProps
// Information necessary to generate the filesystem modules, including details about their
// dependencies
@@ -76,7 +76,7 @@
// List of modules in `PRODUCT_PACKAGES` and `PRODUCT_PACKAGES_DEBUG`
depCandidates []string
// Map of names of partition to the information of modules to be added as deps
- fsDeps map[string]multilibDeps
+ fsDeps map[string]*multilibDeps
// List of name of partitions to be generated by the filesystem_creator module
soongGeneratedPartitions []string
// Mutex to protect the fsDeps
@@ -90,10 +90,6 @@
Overrides []string
}
-func newMultilibDeps() multilibDeps {
- return &map[string]*depCandidateProps{}
-}
-
func defaultDepCandidateProps(config android.Config) *depCandidateProps {
return &depCandidateProps{
Namespace: ".",
@@ -122,9 +118,9 @@
return &FsGenState{
depCandidates: candidates,
- fsDeps: map[string]multilibDeps{
+ fsDeps: map[string]*multilibDeps{
// These additional deps are added according to the cuttlefish system image bp.
- "system": &map[string]*depCandidateProps{
+ "system": {
"com.android.apex.cts.shim.v1_prebuilt": defaultDepCandidateProps(ctx.Config()),
"dex_bootjars": defaultDepCandidateProps(ctx.Config()),
"framework_compatibility_matrix.device.xml": defaultDepCandidateProps(ctx.Config()),
@@ -142,19 +138,19 @@
"public.libraries.android.txt": defaultDepCandidateProps(ctx.Config()),
"update_engine_sideload": defaultDepCandidateProps(ctx.Config()),
},
- "vendor": &map[string]*depCandidateProps{
+ "vendor": {
"fs_config_files_vendor": defaultDepCandidateProps(ctx.Config()),
"fs_config_dirs_vendor": defaultDepCandidateProps(ctx.Config()),
generatedModuleName(ctx.Config(), "vendor-build.prop"): defaultDepCandidateProps(ctx.Config()),
},
- "odm": &map[string]*depCandidateProps{
+ "odm": {
// fs_config_* files are automatically installed for all products with odm partitions.
// https://cs.android.com/android/_/android/platform/build/+/e4849e87ab660b59a6501b3928693db065ee873b:tools/fs_config/Android.mk;l=34;drc=8d6481b92c4b4e9b9f31a61545b6862090fcc14b;bpv=1;bpt=0
"fs_config_files_odm": defaultDepCandidateProps(ctx.Config()),
"fs_config_dirs_odm": defaultDepCandidateProps(ctx.Config()),
},
- "product": newMultilibDeps(),
- "system_ext": &map[string]*depCandidateProps{
+ "product": {},
+ "system_ext": {
// VNDK apexes are automatically included.
// This hardcoded list will need to be updated if `PRODUCT_EXTRA_VNDK_VERSIONS` is updated.
// https://cs.android.com/android/_/android/platform/build/+/adba533072b00c53ac0f198c550a3cbd7a00e4cd:core/main.mk;l=984;bpv=1;bpt=0;drc=174db7b179592cf07cbfd2adb0119486fda911e7
@@ -172,14 +168,14 @@
}).(*FsGenState)
}
-func checkDepModuleInMultipleNamespaces(mctx android.BottomUpMutatorContext, foundDeps map[string]*depCandidateProps, module string, partitionName string) {
+func checkDepModuleInMultipleNamespaces(mctx android.BottomUpMutatorContext, foundDeps multilibDeps, module string, partitionName string) {
otherNamespace := mctx.Namespace().Path
if val, found := foundDeps[module]; found && otherNamespace != "." && !android.InList(val.Namespace, []string{".", otherNamespace}) {
mctx.ModuleErrorf("found in multiple namespaces(%s and %s) when including in %s partition", val.Namespace, otherNamespace, partitionName)
}
}
-func appendDepIfAppropriate(mctx android.BottomUpMutatorContext, deps *map[string]*depCandidateProps, installPartition string) {
+func appendDepIfAppropriate(mctx android.BottomUpMutatorContext, deps *multilibDeps, installPartition string) {
checkDepModuleInMultipleNamespaces(mctx, *deps, mctx.Module().Name(), installPartition)
if _, ok := (*deps)[mctx.Module().Name()]; ok {
// Prefer the namespace-specific module over the platform module
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 1ab1378..1282bfb 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -231,7 +231,7 @@
// For nsjail tasks
useNsjail bool
- dirSrcs android.Paths
+ dirSrcs android.DirectoryPaths
}
func (g *Module) GeneratedSourceFiles() android.Paths {
@@ -604,7 +604,8 @@
if task.useNsjail {
for _, input := range task.dirSrcs {
- cmd.Implicit(input)
+ cmd.ImplicitDirectory(input)
+ // TODO(b/375551969): remove glob
if paths, err := ctx.GlobWithDeps(filepath.Join(input.String(), "**/*"), nil); err == nil {
rule.NsjailImplicits(android.PathsForSource(ctx, paths))
} else {
diff --git a/rust/config/global.go b/rust/config/global.go
index 68a74c2..7b79fca 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -15,6 +15,7 @@
package config
import (
+ "fmt"
"strings"
"android/soong/android"
@@ -93,6 +94,16 @@
}
)
+func RustPath(ctx android.PathContext) string {
+ // I can't see any way to flatten the static variable inside Soong, so this
+ // reproduces the init logic.
+ var RustBase string = RustDefaultBase
+ if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
+ RustBase = override
+ }
+ return fmt.Sprintf("%s/%s/%s", RustBase, HostPrebuiltTag(ctx.Config()), GetRustVersion(ctx))
+}
+
func init() {
pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase)
pctx.VariableConfigMethod("HostPrebuiltTag", HostPrebuiltTag)
diff --git a/rust/project_json.go b/rust/project_json.go
index 6c1e320..6e8cebe 100644
--- a/rust/project_json.go
+++ b/rust/project_json.go
@@ -19,6 +19,7 @@
"fmt"
"android/soong/android"
+ "android/soong/rust/config"
)
// This singleton collects Rust crate definitions and generates a JSON file
@@ -44,17 +45,19 @@
}
type rustProjectCrate struct {
- DisplayName string `json:"display_name"`
- RootModule string `json:"root_module"`
- Edition string `json:"edition,omitempty"`
- Deps []rustProjectDep `json:"deps"`
- Cfg []string `json:"cfg"`
- Env map[string]string `json:"env"`
- ProcMacro bool `json:"is_proc_macro"`
+ DisplayName string `json:"display_name"`
+ RootModule string `json:"root_module"`
+ Edition string `json:"edition,omitempty"`
+ Deps []rustProjectDep `json:"deps"`
+ Cfg []string `json:"cfg"`
+ Env map[string]string `json:"env"`
+ ProcMacro bool `json:"is_proc_macro"`
+ ProcMacroDylib *string `json:"proc_macro_dylib_path"`
}
type rustProjectJson struct {
- Crates []rustProjectCrate `json:"crates"`
+ Sysroot string `json:"sysroot"`
+ Crates []rustProjectCrate `json:"crates"`
}
// crateInfo is used during the processing to keep track of the known crates.
@@ -135,16 +138,21 @@
return 0, false
}
- _, procMacro := rModule.compiler.(*procMacroDecorator)
+ var procMacroDylib *string = nil
+ if procDec, procMacro := rModule.compiler.(*procMacroDecorator); procMacro {
+ procMacroDylib = new(string)
+ *procMacroDylib = procDec.baseCompiler.unstrippedOutputFilePath().String()
+ }
crate := rustProjectCrate{
- DisplayName: rModule.Name(),
- RootModule: rootModule.String(),
- Edition: rModule.compiler.edition(),
- Deps: make([]rustProjectDep, 0),
- Cfg: make([]string, 0),
- Env: make(map[string]string),
- ProcMacro: procMacro,
+ DisplayName: rModule.Name(),
+ RootModule: rootModule.String(),
+ Edition: rModule.compiler.edition(),
+ Deps: make([]rustProjectDep, 0),
+ Cfg: make([]string, 0),
+ Env: make(map[string]string),
+ ProcMacro: procMacroDylib != nil,
+ ProcMacroDylib: procMacroDylib,
}
if rModule.compiler.cargoOutDir().Valid() {
@@ -197,6 +205,8 @@
return
}
+ singleton.project.Sysroot = config.RustPath(ctx)
+
singleton.knownCrates = make(map[string]crateInfo)
ctx.VisitAllModules(func(module android.Module) {
singleton.appendCrateAndDependencies(ctx, module)