2019-05-31 15:00:04 +02:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package android
|
|
|
|
|
|
|
|
import (
|
2023-05-05 10:07:15 +02:00
|
|
|
"path/filepath"
|
|
|
|
|
2022-08-04 22:31:14 +02:00
|
|
|
"android/soong/bazel"
|
2019-05-31 15:00:04 +02:00
|
|
|
"github.com/google/blueprint"
|
2020-05-01 12:57:12 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2019-05-31 15:00:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-01-14 13:15:29 +01:00
|
|
|
RegisterPackageBuildComponents(InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
2021-02-27 12:59:02 +01:00
|
|
|
var PrepareForTestWithPackageModule = FixtureRegisterWithContext(RegisterPackageBuildComponents)
|
|
|
|
|
2020-05-01 12:57:12 +02:00
|
|
|
// Register the package module type.
|
2020-01-14 13:15:29 +01:00
|
|
|
func RegisterPackageBuildComponents(ctx RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("package", PackageFactory)
|
2019-05-31 15:00:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type packageProperties struct {
|
|
|
|
// Specifies the default visibility for all modules defined in this package.
|
|
|
|
Default_visibility []string
|
2021-01-07 04:34:31 +01:00
|
|
|
// Specifies the default license terms for all modules defined in this package.
|
|
|
|
Default_applicable_licenses []string
|
2019-05-31 15:00:04 +02:00
|
|
|
}
|
|
|
|
|
2022-08-04 22:31:14 +02:00
|
|
|
type bazelPackageAttributes struct {
|
2023-05-05 10:07:15 +02:00
|
|
|
Default_visibility []string
|
|
|
|
Default_package_metadata bazel.LabelListAttribute
|
2022-08-04 22:31:14 +02:00
|
|
|
}
|
|
|
|
|
2019-05-31 15:00:04 +02:00
|
|
|
type packageModule struct {
|
|
|
|
ModuleBase
|
2022-08-04 22:31:14 +02:00
|
|
|
BazelModuleBase
|
2019-05-31 15:00:04 +02:00
|
|
|
|
2020-05-01 12:57:12 +02:00
|
|
|
properties packageProperties
|
2019-05-31 15:00:04 +02:00
|
|
|
}
|
|
|
|
|
2022-08-04 22:31:14 +02:00
|
|
|
var _ Bazelable = &packageModule{}
|
|
|
|
|
2023-09-19 22:09:00 +02:00
|
|
|
func (p *packageModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
2023-05-05 10:07:15 +02:00
|
|
|
defaultPackageMetadata := bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses))
|
|
|
|
// If METADATA file exists in the package, add it to package(default_package_metadata=) using a
|
|
|
|
// filegroup(name="default_metadata_file") which can be accessed later on each module in Bazel
|
|
|
|
// using attribute "applicable_licenses".
|
|
|
|
// Attribute applicable_licenses of filegroup "default_metadata_file" has to be set to [],
|
|
|
|
// otherwise Bazel reports cyclic reference error.
|
|
|
|
if existed, _, _ := ctx.Config().fs.Exists(filepath.Join(ctx.ModuleDir(), "METADATA")); existed {
|
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "filegroup",
|
|
|
|
},
|
|
|
|
CommonAttributes{Name: "default_metadata_file"},
|
|
|
|
&bazelFilegroupAttributes{
|
|
|
|
Srcs: bazel.MakeLabelListAttribute(BazelLabelForModuleSrc(ctx, []string{"METADATA"})),
|
|
|
|
Applicable_licenses: bazel.LabelListAttribute{Value: bazel.LabelList{Includes: []bazel.Label{}}, EmitEmptyList: true},
|
|
|
|
})
|
|
|
|
defaultPackageMetadata.Value.Add(&bazel.Label{Label: ":default_metadata_file"})
|
|
|
|
}
|
|
|
|
|
2022-08-04 22:31:14 +02:00
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "package",
|
|
|
|
},
|
|
|
|
CommonAttributes{},
|
|
|
|
&bazelPackageAttributes{
|
2023-05-05 10:07:15 +02:00
|
|
|
Default_package_metadata: defaultPackageMetadata,
|
2022-08-04 22:31:14 +02:00
|
|
|
// FIXME(asmundak): once b/221436821 is resolved
|
|
|
|
Default_visibility: []string{"//visibility:public"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-31 15:00:04 +02:00
|
|
|
func (p *packageModule) GenerateAndroidBuildActions(ModuleContext) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *packageModule) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
|
|
|
|
// Override to create a package id.
|
|
|
|
return newPackageId(ctx.ModuleDir())
|
|
|
|
}
|
|
|
|
|
|
|
|
func PackageFactory() Module {
|
|
|
|
module := &packageModule{}
|
|
|
|
|
2022-08-04 22:31:14 +02:00
|
|
|
module.AddProperties(&module.properties, &module.commonProperties.BazelConversionStatus)
|
Refactor visibility to support visibility on defaults modules
Existing modules, either general one or package ones have a single
visibility property, called visibility in general, and
default_visibility on package, that controls access to that module, or
in the case of package sets the default visibility of all modules in
that package. The property is checked and gathered during the similarly
named phases of visibility processing.
The defaults module will be different as it will have two properties.
The first, visibility, will not affect the visibility of the module, it
only affects the visibility of modules that 'extend' the defaults. So,
it will need checking but not parsing. The second property,
defaults_visibility, will affect the visibility of the module and so
will need both checking and parsing.
The current implementation does not handle those cases because:
1) It does not differentiate between the property that affects the
module and those that do not. It checks and gathers all of them with
the last property gathered overriding the rules for the previous
properties.
2) It relies on overriding methods in MethodBase in order to change the
default behavior for the package module. That works because
packageModule embeds ModuleBase but will not work for
DefaultsModuleBase as it does not embed ModuleBase and instead is
embedded alongside it so attempting to override a method in
MethodBase leads to ambiguity.
This change addresses the issues as follows:
1) It adds a new visibility() []string method to get access to the
primary visibility rules, i.e. the ones that affect the module.
2) It adds two fields, 'visibilityPropertyInfo []visibilityProperty'
to provide information about all the properties that need checking,
and 'primaryVisibilityProperty visibilityProperty' to specify the
property that affects the module.
The PackageFactory() and InitAndroidModule(Module) functions are
modified to initialize the fields. The override of the
visibilityProperties() method for packageModule is removed and the
default implementations of visibilityProperties() and visibility()
on ModuleBase return information from the two new fields.
The InitDefaultsModule is updated to also initialize the two new
fields. It uses nil for primaryVisibilityProperty for now but that
will be changed to return defaults_visibility. It also uses the
commonProperties structure created for the defaults directly instead
of having to search for it through properties().
Changed the visibilityProperty to take a pointer to the property that
can be used to retrieve the value rather than a lambda function.
Bug: 130796911
Test: m nothing
Change-Id: Icadd470a5f692a48ec61de02bf3dfde3e2eea2ef
2019-07-24 15:24:38 +02:00
|
|
|
|
2020-05-01 12:57:12 +02:00
|
|
|
// The name is the relative path from build root to the directory containing this
|
|
|
|
// module. Set that name at the earliest possible moment that information is available
|
|
|
|
// which is in a LoadHook.
|
|
|
|
AddLoadHook(module, func(ctx LoadHookContext) {
|
|
|
|
module.nameProperties.Name = proptools.StringPtr("//" + ctx.ModuleDir())
|
|
|
|
})
|
|
|
|
|
Refactor visibility to support visibility on defaults modules
Existing modules, either general one or package ones have a single
visibility property, called visibility in general, and
default_visibility on package, that controls access to that module, or
in the case of package sets the default visibility of all modules in
that package. The property is checked and gathered during the similarly
named phases of visibility processing.
The defaults module will be different as it will have two properties.
The first, visibility, will not affect the visibility of the module, it
only affects the visibility of modules that 'extend' the defaults. So,
it will need checking but not parsing. The second property,
defaults_visibility, will affect the visibility of the module and so
will need both checking and parsing.
The current implementation does not handle those cases because:
1) It does not differentiate between the property that affects the
module and those that do not. It checks and gathers all of them with
the last property gathered overriding the rules for the previous
properties.
2) It relies on overriding methods in MethodBase in order to change the
default behavior for the package module. That works because
packageModule embeds ModuleBase but will not work for
DefaultsModuleBase as it does not embed ModuleBase and instead is
embedded alongside it so attempting to override a method in
MethodBase leads to ambiguity.
This change addresses the issues as follows:
1) It adds a new visibility() []string method to get access to the
primary visibility rules, i.e. the ones that affect the module.
2) It adds two fields, 'visibilityPropertyInfo []visibilityProperty'
to provide information about all the properties that need checking,
and 'primaryVisibilityProperty visibilityProperty' to specify the
property that affects the module.
The PackageFactory() and InitAndroidModule(Module) functions are
modified to initialize the fields. The override of the
visibilityProperties() method for packageModule is removed and the
default implementations of visibilityProperties() and visibility()
on ModuleBase return information from the two new fields.
The InitDefaultsModule is updated to also initialize the two new
fields. It uses nil for primaryVisibilityProperty for now but that
will be changed to return defaults_visibility. It also uses the
commonProperties structure created for the defaults directly instead
of having to search for it through properties().
Changed the visibilityProperty to take a pointer to the property that
can be used to retrieve the value rather than a lambda function.
Bug: 130796911
Test: m nothing
Change-Id: Icadd470a5f692a48ec61de02bf3dfde3e2eea2ef
2019-07-24 15:24:38 +02:00
|
|
|
// The default_visibility property needs to be checked and parsed by the visibility module during
|
2020-05-01 18:52:01 +02:00
|
|
|
// its checking and parsing phases so make it the primary visibility property.
|
|
|
|
setPrimaryVisibilityProperty(module, "default_visibility", &module.properties.Default_visibility)
|
Refactor visibility to support visibility on defaults modules
Existing modules, either general one or package ones have a single
visibility property, called visibility in general, and
default_visibility on package, that controls access to that module, or
in the case of package sets the default visibility of all modules in
that package. The property is checked and gathered during the similarly
named phases of visibility processing.
The defaults module will be different as it will have two properties.
The first, visibility, will not affect the visibility of the module, it
only affects the visibility of modules that 'extend' the defaults. So,
it will need checking but not parsing. The second property,
defaults_visibility, will affect the visibility of the module and so
will need both checking and parsing.
The current implementation does not handle those cases because:
1) It does not differentiate between the property that affects the
module and those that do not. It checks and gathers all of them with
the last property gathered overriding the rules for the previous
properties.
2) It relies on overriding methods in MethodBase in order to change the
default behavior for the package module. That works because
packageModule embeds ModuleBase but will not work for
DefaultsModuleBase as it does not embed ModuleBase and instead is
embedded alongside it so attempting to override a method in
MethodBase leads to ambiguity.
This change addresses the issues as follows:
1) It adds a new visibility() []string method to get access to the
primary visibility rules, i.e. the ones that affect the module.
2) It adds two fields, 'visibilityPropertyInfo []visibilityProperty'
to provide information about all the properties that need checking,
and 'primaryVisibilityProperty visibilityProperty' to specify the
property that affects the module.
The PackageFactory() and InitAndroidModule(Module) functions are
modified to initialize the fields. The override of the
visibilityProperties() method for packageModule is removed and the
default implementations of visibilityProperties() and visibility()
on ModuleBase return information from the two new fields.
The InitDefaultsModule is updated to also initialize the two new
fields. It uses nil for primaryVisibilityProperty for now but that
will be changed to return defaults_visibility. It also uses the
commonProperties structure created for the defaults directly instead
of having to search for it through properties().
Changed the visibilityProperty to take a pointer to the property that
can be used to retrieve the value rather than a lambda function.
Bug: 130796911
Test: m nothing
Change-Id: Icadd470a5f692a48ec61de02bf3dfde3e2eea2ef
2019-07-24 15:24:38 +02:00
|
|
|
|
2021-01-07 04:34:31 +01:00
|
|
|
// The default_applicable_licenses property needs to be checked and parsed by the licenses module during
|
|
|
|
// its checking and parsing phases so make it the primary licenses property.
|
|
|
|
setPrimaryLicensesProperty(module, "default_applicable_licenses", &module.properties.Default_applicable_licenses)
|
|
|
|
|
2022-08-04 22:31:14 +02:00
|
|
|
InitBazelModule(module)
|
|
|
|
|
2019-05-31 15:00:04 +02:00
|
|
|
return module
|
|
|
|
}
|