Merge "Choose prebuilt or source via an Soong config variable" am: e88944c51e
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1762228 Change-Id: Ib88e4a9526a74204744d8ddc9110526d30a74e76
This commit is contained in:
@@ -61,6 +61,16 @@ type PrebuiltProperties struct {
|
|||||||
// a matching name.
|
// a matching name.
|
||||||
Prefer *bool `android:"arch_variant"`
|
Prefer *bool `android:"arch_variant"`
|
||||||
|
|
||||||
|
// When specified this names a Soong config variable that controls the prefer property.
|
||||||
|
//
|
||||||
|
// If the value of the named Soong config variable is true then prefer is set to false and vice
|
||||||
|
// versa. If the Soong config variable is not set then it defaults to false, so prefer defaults
|
||||||
|
// to true.
|
||||||
|
//
|
||||||
|
// If specified then the prefer property is ignored in favor of the value of the Soong config
|
||||||
|
// variable.
|
||||||
|
Use_source_config_var *ConfigVarProperties
|
||||||
|
|
||||||
SourceExists bool `blueprint:"mutated"`
|
SourceExists bool `blueprint:"mutated"`
|
||||||
UsePrebuilt bool `blueprint:"mutated"`
|
UsePrebuilt bool `blueprint:"mutated"`
|
||||||
|
|
||||||
@@ -68,6 +78,22 @@ type PrebuiltProperties struct {
|
|||||||
PrebuiltRenamedToSource bool `blueprint:"mutated"`
|
PrebuiltRenamedToSource bool `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Properties that can be used to select a Soong config variable.
|
||||||
|
type ConfigVarProperties struct {
|
||||||
|
// Allow instances of this struct to be used as a property value in a BpPropertySet.
|
||||||
|
BpPrintableBase
|
||||||
|
|
||||||
|
// The name of the configuration namespace.
|
||||||
|
//
|
||||||
|
// As passed to add_soong_config_namespace in Make.
|
||||||
|
Config_namespace *string
|
||||||
|
|
||||||
|
// The name of the configuration variable.
|
||||||
|
//
|
||||||
|
// As passed to add_soong_config_var_value in Make.
|
||||||
|
Var_name *string
|
||||||
|
}
|
||||||
|
|
||||||
type Prebuilt struct {
|
type Prebuilt struct {
|
||||||
properties PrebuiltProperties
|
properties PrebuiltProperties
|
||||||
|
|
||||||
@@ -364,12 +390,18 @@ func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module, prebuil
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use p.Properties.Name and ctx.ModuleDir to override preference
|
// If source is not available or is disabled then always use the prebuilt.
|
||||||
if Bool(p.properties.Prefer) {
|
if source == nil || !source.Enabled() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return source == nil || !source.Enabled()
|
// If the use_source_config_var property is set then it overrides the prefer property setting.
|
||||||
|
if configVar := p.properties.Use_source_config_var; configVar != nil {
|
||||||
|
return !ctx.Config().VendorConfig(proptools.String(configVar.Config_namespace)).Bool(proptools.String(configVar.Var_name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use p.Properties.Name and ctx.ModuleDir to override preference
|
||||||
|
return Bool(p.properties.Prefer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Prebuilt) SourceExists() bool {
|
func (p *Prebuilt) SourceExists() bool {
|
||||||
|
@@ -26,6 +26,7 @@ var prebuiltsTests = []struct {
|
|||||||
replaceBp bool // modules is added to default bp boilerplate if false.
|
replaceBp bool // modules is added to default bp boilerplate if false.
|
||||||
modules string
|
modules string
|
||||||
prebuilt []OsType
|
prebuilt []OsType
|
||||||
|
preparer FixturePreparer
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no prebuilt",
|
name: "no prebuilt",
|
||||||
@@ -291,6 +292,86 @@ var prebuiltsTests = []struct {
|
|||||||
}`,
|
}`,
|
||||||
prebuilt: []OsType{Android, BuildOs},
|
prebuilt: []OsType{Android, BuildOs},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt use_source_config_var={acme, use_source} - no var specified",
|
||||||
|
modules: `
|
||||||
|
source {
|
||||||
|
name: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
}`,
|
||||||
|
// When use_source_env is specified then it will use the prebuilt by default if the environment
|
||||||
|
// variable is not set.
|
||||||
|
prebuilt: []OsType{Android, BuildOs},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=false",
|
||||||
|
modules: `
|
||||||
|
source {
|
||||||
|
name: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
}`,
|
||||||
|
preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||||
|
variables.VendorVars = map[string]map[string]string{
|
||||||
|
"acme": {
|
||||||
|
"use_source": "false",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
// Setting the environment variable named in use_source_env to false will cause the prebuilt to
|
||||||
|
// be used.
|
||||||
|
prebuilt: []OsType{Android, BuildOs},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true",
|
||||||
|
modules: `
|
||||||
|
source {
|
||||||
|
name: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
}`,
|
||||||
|
preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||||
|
variables.VendorVars = map[string]map[string]string{
|
||||||
|
"acme": {
|
||||||
|
"use_source": "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
// Setting the environment variable named in use_source_env to true will cause the source to be
|
||||||
|
// used.
|
||||||
|
prebuilt: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true, no source",
|
||||||
|
modules: `
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
}`,
|
||||||
|
preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||||
|
variables.VendorVars = map[string]map[string]string{
|
||||||
|
"acme": {
|
||||||
|
"use_source": "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
// Although the environment variable says to use source there is no source available.
|
||||||
|
prebuilt: []OsType{Android, BuildOs},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuilts(t *testing.T) {
|
func TestPrebuilts(t *testing.T) {
|
||||||
@@ -329,6 +410,7 @@ func TestPrebuilts(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
fs.AddToFixture(),
|
fs.AddToFixture(),
|
||||||
FixtureRegisterWithContext(registerTestPrebuiltModules),
|
FixtureRegisterWithContext(registerTestPrebuiltModules),
|
||||||
|
OptionalFixturePreparer(test.preparer),
|
||||||
).RunTestWithBp(t, bp)
|
).RunTestWithBp(t, bp)
|
||||||
|
|
||||||
for _, variant := range result.ModuleVariantsForTests("foo") {
|
for _, variant := range result.ModuleVariantsForTests("foo") {
|
||||||
|
Reference in New Issue
Block a user