Merge "Reduce duplication in visibility property management" am: b6b0ca1d87

Change-Id: Id070475dd4bf9ceae3c6b60960d54a3b64fd9f50
This commit is contained in:
Treehugger Robot 2020-05-04 17:42:49 +00:00 committed by Automerger Merge Worker
commit 5879210577
4 changed files with 39 additions and 18 deletions

View file

@ -176,18 +176,18 @@ func InitDefaultsModule(module DefaultsModule) {
defaultsVisibility := module.defaultsVisibility()
module.AddProperties(&base.nameProperties, defaultsVisibility)
// The defaults_visibility property controls the visibility of a defaults module.
base.primaryVisibilityProperty =
newVisibilityProperty("defaults_visibility", &defaultsVisibility.Defaults_visibility)
// 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 clear the
// existing list of properties.
clearVisibilityProperties(module)
// The defaults_visibility property controls the visibility of a defaults module so it must be
// set as the primary property, which also adds it to the list.
setPrimaryVisibilityProperty(module, "defaults_visibility", &defaultsVisibility.Defaults_visibility)
// The visibility property needs to be checked (but not parsed) by the visibility module during
// its checking phase and parsing phase.
base.visibilityPropertyInfo = []visibilityProperty{
base.primaryVisibilityProperty,
newVisibilityProperty("visibility", &commonProperties.Visibility),
}
// its checking phase and parsing phase so add it to the list as a normal property.
AddVisibilityProperty(module, "visibility", &commonProperties.Visibility)
base.module = module
}

View file

@ -611,10 +611,8 @@ func InitAndroidModule(m Module) {
base.customizableProperties = m.GetProperties()
// The default_visibility property needs to be checked and parsed by the visibility module during
// its checking and parsing phases.
base.primaryVisibilityProperty =
newVisibilityProperty("visibility", &base.commonProperties.Visibility)
base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
// its checking and parsing phases so make it the primary visibility property.
setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
}
func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {

View file

@ -101,10 +101,8 @@ func PackageFactory() Module {
module.AddProperties(&module.properties)
// The default_visibility property needs to be checked and parsed by the visibility module during
// its checking and parsing phases.
module.primaryVisibilityProperty =
newVisibilityProperty("default_visibility", &module.properties.Default_visibility)
module.visibilityPropertyInfo = []visibilityProperty{module.primaryVisibilityProperty}
// its checking and parsing phases so make it the primary visibility property.
setPrimaryVisibilityProperty(module, "default_visibility", &module.properties.Default_visibility)
return module
}

View file

@ -480,3 +480,28 @@ func EffectiveVisibilityRules(ctx BaseModuleContext, module Module) []string {
return rule.Strings()
}
// Clear the default visibility properties so they can be replaced.
func clearVisibilityProperties(module Module) {
module.base().visibilityPropertyInfo = nil
}
// Add a property that contains visibility rules so that they are checked for
// correctness.
func AddVisibilityProperty(module Module, name string, stringsProperty *[]string) {
addVisibilityProperty(module, name, stringsProperty)
}
func addVisibilityProperty(module Module, name string, stringsProperty *[]string) visibilityProperty {
base := module.base()
property := newVisibilityProperty(name, stringsProperty)
base.visibilityPropertyInfo = append(base.visibilityPropertyInfo, property)
return property
}
// Set the primary visibility property.
//
// Also adds the property to the list of properties to be validated.
func setPrimaryVisibilityProperty(module Module, name string, stringsProperty *[]string) {
module.base().primaryVisibilityProperty = addVisibilityProperty(module, name, stringsProperty)
}