Add defaults_visibility support
Bug: 130796911 Test: m nothing Change-Id: I7b9462d3360be2bbeaf6ff38c5328f45ff5b5ebb
This commit is contained in:
@@ -236,6 +236,11 @@ a `default_visibility` property is specified.
|
|||||||
If no `default_visibility` property can be found then the module uses the
|
If no `default_visibility` property can be found then the module uses the
|
||||||
global default of `//visibility:legacy_public`.
|
global default of `//visibility:legacy_public`.
|
||||||
|
|
||||||
|
The `visibility` property has no effect on a defaults module although it does
|
||||||
|
apply to any non-defaults module that uses it. To set the visibility of a
|
||||||
|
defaults module, use the `defaults_visibility` property on the defaults module;
|
||||||
|
not to be confused with the `default_visibility` property on the package module.
|
||||||
|
|
||||||
Once the build has been completely switched over to soong it is possible that a
|
Once the build has been completely switched over to soong it is possible that a
|
||||||
global refactoring will be done to change this to `//visibility:private` at
|
global refactoring will be done to change this to `//visibility:private` at
|
||||||
which point all packages that do not currently specify a `default_visibility`
|
which point all packages that do not currently specify a `default_visibility`
|
||||||
|
@@ -68,11 +68,20 @@ func InitDefaultableModule(module DefaultableModule) {
|
|||||||
module.AddProperties(module.defaults())
|
module.AddProperties(module.defaults())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The Defaults_visibility property.
|
||||||
|
type DefaultsVisibilityProperties struct {
|
||||||
|
|
||||||
|
// Controls the visibility of the defaults module itself.
|
||||||
|
Defaults_visibility []string
|
||||||
|
}
|
||||||
|
|
||||||
type DefaultsModuleBase struct {
|
type DefaultsModuleBase struct {
|
||||||
DefaultableModuleBase
|
DefaultableModuleBase
|
||||||
|
|
||||||
// Container for defaults of the common properties
|
// Container for defaults of the common properties
|
||||||
commonProperties commonProperties
|
commonProperties commonProperties
|
||||||
|
|
||||||
|
defaultsVisibilityProperties DefaultsVisibilityProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
// The common pattern for defaults modules is to register separate instances of
|
// The common pattern for defaults modules is to register separate instances of
|
||||||
@@ -107,6 +116,9 @@ type Defaults interface {
|
|||||||
|
|
||||||
// Return the defaults common properties.
|
// Return the defaults common properties.
|
||||||
common() *commonProperties
|
common() *commonProperties
|
||||||
|
|
||||||
|
// Return the defaults visibility properties.
|
||||||
|
defaultsVisibility() *DefaultsVisibilityProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DefaultsModuleBase) isDefaults() bool {
|
func (d *DefaultsModuleBase) isDefaults() bool {
|
||||||
@@ -126,6 +138,10 @@ func (d *DefaultsModuleBase) common() *commonProperties {
|
|||||||
return &d.commonProperties
|
return &d.commonProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DefaultsModuleBase) defaultsVisibility() *DefaultsVisibilityProperties {
|
||||||
|
return &d.defaultsVisibilityProperties
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DefaultsModuleBase) GenerateAndroidBuildActions(ctx ModuleContext) {
|
func (d *DefaultsModuleBase) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,17 +158,19 @@ func InitDefaultsModule(module DefaultsModule) {
|
|||||||
|
|
||||||
// Add properties that will not have defaults applied to them.
|
// Add properties that will not have defaults applied to them.
|
||||||
base := module.base()
|
base := module.base()
|
||||||
module.AddProperties(&base.nameProperties)
|
defaultsVisibility := module.defaultsVisibility()
|
||||||
|
module.AddProperties(&base.nameProperties, defaultsVisibility)
|
||||||
|
|
||||||
// There is currently no way to control the visibility of a defaults module, i.e. there is no
|
// The defaults_visibility property controls the visibility of a defaults module.
|
||||||
// primary visibility property.
|
base.primaryVisibilityProperty =
|
||||||
base.primaryVisibilityProperty = nil
|
newVisibilityProperty("defaults_visibility", &defaultsVisibility.Defaults_visibility)
|
||||||
|
|
||||||
// Unlike non-defaults modules the visibility property is not stored in m.base().commonProperties.
|
// Unlike non-defaults modules the visibility property is not stored in m.base().commonProperties.
|
||||||
// Instead it is stored in a separate instance of commonProperties created above so use that.
|
// Instead it is stored in a separate instance of commonProperties created above so use that.
|
||||||
// The visibility property needs to be checked (but not parsed) by the visibility module during
|
// The visibility property needs to be checked (but not parsed) by the visibility module during
|
||||||
// its checking phase and parsing phase.
|
// its checking phase and parsing phase.
|
||||||
base.visibilityPropertyInfo = []visibilityProperty{
|
base.visibilityPropertyInfo = []visibilityProperty{
|
||||||
|
base.primaryVisibilityProperty,
|
||||||
newVisibilityProperty("visibility", &commonProperties.Visibility),
|
newVisibilityProperty("visibility", &commonProperties.Visibility),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -305,6 +305,11 @@ type commonProperties struct {
|
|||||||
// If no `default_visibility` property can be found then the module uses the
|
// If no `default_visibility` property can be found then the module uses the
|
||||||
// global default of `//visibility:legacy_public`.
|
// global default of `//visibility:legacy_public`.
|
||||||
//
|
//
|
||||||
|
// The `visibility` property has no effect on a defaults module although it does
|
||||||
|
// apply to any non-defaults module that uses it. To set the visibility of a
|
||||||
|
// defaults module, use the `defaults_visibility` property on the defaults module;
|
||||||
|
// not to be confused with the `default_visibility` property on the package module.
|
||||||
|
//
|
||||||
// See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
|
// See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
|
||||||
// more details.
|
// more details.
|
||||||
Visibility []string
|
Visibility []string
|
||||||
|
@@ -658,6 +658,40 @@ var visibilityTests = []struct {
|
|||||||
` visible to this module`,
|
` visible to this module`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Defaults module's defaults_visibility tests
|
||||||
|
{
|
||||||
|
name: "defaults_visibility invalid",
|
||||||
|
fs: map[string][]byte{
|
||||||
|
"top/Blueprints": []byte(`
|
||||||
|
mock_defaults {
|
||||||
|
name: "top_defaults",
|
||||||
|
defaults_visibility: ["//visibility:invalid"],
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
expectedErrors: []string{
|
||||||
|
`defaults_visibility: unrecognized visibility rule "//visibility:invalid"`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "defaults_visibility overrides package default",
|
||||||
|
fs: map[string][]byte{
|
||||||
|
"top/Blueprints": []byte(`
|
||||||
|
package {
|
||||||
|
default_visibility: ["//visibility:private"],
|
||||||
|
}
|
||||||
|
mock_defaults {
|
||||||
|
name: "top_defaults",
|
||||||
|
defaults_visibility: ["//visibility:public"],
|
||||||
|
}`),
|
||||||
|
"outsider/Blueprints": []byte(`
|
||||||
|
mock_library {
|
||||||
|
name: "liboutsider",
|
||||||
|
defaults: ["top_defaults"],
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// Package default_visibility tests
|
// Package default_visibility tests
|
||||||
{
|
{
|
||||||
name: "package default_visibility property is checked",
|
name: "package default_visibility property is checked",
|
||||||
|
Reference in New Issue
Block a user