blob: 2bf65212600aa6d70549b11a69ccf30ad48c0230 [file] [log] [blame]
Paul Duffine2453c72019-05-31 14:00:04 +01001// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package android
16
17import (
Sasha Smundak8bea2672022-08-04 13:31:14 -070018 "android/soong/bazel"
Paul Duffine2453c72019-05-31 14:00:04 +010019 "github.com/google/blueprint"
Paul Duffincdfcec92020-05-01 11:57:12 +010020 "github.com/google/blueprint/proptools"
Paul Duffine2453c72019-05-31 14:00:04 +010021)
22
23func init() {
Paul Duffinc1327422020-01-14 12:15:29 +000024 RegisterPackageBuildComponents(InitRegistrationContext)
25}
26
Paul Duffincfd33742021-02-27 11:59:02 +000027var PrepareForTestWithPackageModule = FixtureRegisterWithContext(RegisterPackageBuildComponents)
28
Paul Duffincdfcec92020-05-01 11:57:12 +010029// Register the package module type.
Paul Duffinc1327422020-01-14 12:15:29 +000030func RegisterPackageBuildComponents(ctx RegistrationContext) {
31 ctx.RegisterModuleType("package", PackageFactory)
Paul Duffine2453c72019-05-31 14:00:04 +010032}
33
34type packageProperties struct {
Paul Duffine2453c72019-05-31 14:00:04 +010035 // Specifies the default visibility for all modules defined in this package.
36 Default_visibility []string
Bob Badour37af0462021-01-07 03:34:31 +000037 // Specifies the default license terms for all modules defined in this package.
38 Default_applicable_licenses []string
Paul Duffine2453c72019-05-31 14:00:04 +010039}
40
Sasha Smundak8bea2672022-08-04 13:31:14 -070041type bazelPackageAttributes struct {
42 Default_visibility []string
43 Default_applicable_licenses bazel.LabelListAttribute
44}
45
Paul Duffine2453c72019-05-31 14:00:04 +010046type packageModule struct {
47 ModuleBase
Sasha Smundak8bea2672022-08-04 13:31:14 -070048 BazelModuleBase
Paul Duffine2453c72019-05-31 14:00:04 +010049
Paul Duffincdfcec92020-05-01 11:57:12 +010050 properties packageProperties
Paul Duffine2453c72019-05-31 14:00:04 +010051}
52
Sasha Smundak8bea2672022-08-04 13:31:14 -070053var _ Bazelable = &packageModule{}
54
55func (p *packageModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
56 ctx.CreateBazelTargetModule(
57 bazel.BazelTargetModuleProperties{
58 Rule_class: "package",
59 },
60 CommonAttributes{},
61 &bazelPackageAttributes{
62 Default_applicable_licenses: bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses)),
63 // FIXME(asmundak): once b/221436821 is resolved
64 Default_visibility: []string{"//visibility:public"},
65 })
66}
67
Paul Duffine2453c72019-05-31 14:00:04 +010068func (p *packageModule) GenerateAndroidBuildActions(ModuleContext) {
69 // Nothing to do.
70}
71
72func (p *packageModule) GenerateBuildActions(ctx blueprint.ModuleContext) {
73 // Nothing to do.
74}
75
76func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
77 // Override to create a package id.
78 return newPackageId(ctx.ModuleDir())
79}
80
Paul Duffine2453c72019-05-31 14:00:04 +010081func PackageFactory() Module {
82 module := &packageModule{}
83
Sasha Smundak8bea2672022-08-04 13:31:14 -070084 module.AddProperties(&module.properties, &module.commonProperties.BazelConversionStatus)
Paul Duffin63c6e182019-07-24 14:24:38 +010085
Paul Duffincdfcec92020-05-01 11:57:12 +010086 // The name is the relative path from build root to the directory containing this
87 // module. Set that name at the earliest possible moment that information is available
88 // which is in a LoadHook.
89 AddLoadHook(module, func(ctx LoadHookContext) {
90 module.nameProperties.Name = proptools.StringPtr("//" + ctx.ModuleDir())
91 })
92
Paul Duffin63c6e182019-07-24 14:24:38 +010093 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +010094 // its checking and parsing phases so make it the primary visibility property.
95 setPrimaryVisibilityProperty(module, "default_visibility", &module.properties.Default_visibility)
Paul Duffin63c6e182019-07-24 14:24:38 +010096
Bob Badour37af0462021-01-07 03:34:31 +000097 // The default_applicable_licenses property needs to be checked and parsed by the licenses module during
98 // its checking and parsing phases so make it the primary licenses property.
99 setPrimaryLicensesProperty(module, "default_applicable_licenses", &module.properties.Default_applicable_licenses)
100
Sasha Smundak8bea2672022-08-04 13:31:14 -0700101 InitBazelModule(module)
102
Paul Duffine2453c72019-05-31 14:00:04 +0100103 return module
104}