blob: 7012fc7d82d8ca93b44fa1b1ee9e2b734657b88e [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 (
Paul Duffine2453c72019-05-31 14:00:04 +010018 "github.com/google/blueprint"
Paul Duffincdfcec92020-05-01 11:57:12 +010019 "github.com/google/blueprint/proptools"
Paul Duffine2453c72019-05-31 14:00:04 +010020)
21
22func init() {
Paul Duffinc1327422020-01-14 12:15:29 +000023 RegisterPackageBuildComponents(InitRegistrationContext)
24}
25
Paul Duffincdfcec92020-05-01 11:57:12 +010026// Register the package module type.
Paul Duffinc1327422020-01-14 12:15:29 +000027func RegisterPackageBuildComponents(ctx RegistrationContext) {
28 ctx.RegisterModuleType("package", PackageFactory)
Paul Duffine2453c72019-05-31 14:00:04 +010029}
30
31type packageProperties struct {
Paul Duffine2453c72019-05-31 14:00:04 +010032 // Specifies the default visibility for all modules defined in this package.
33 Default_visibility []string
Bob Badour37af0462021-01-07 03:34:31 +000034 // Specifies the default license terms for all modules defined in this package.
35 Default_applicable_licenses []string
Paul Duffine2453c72019-05-31 14:00:04 +010036}
37
38type packageModule struct {
39 ModuleBase
40
Paul Duffincdfcec92020-05-01 11:57:12 +010041 properties packageProperties
Paul Duffine2453c72019-05-31 14:00:04 +010042}
43
44func (p *packageModule) GenerateAndroidBuildActions(ModuleContext) {
45 // Nothing to do.
46}
47
48func (p *packageModule) GenerateBuildActions(ctx blueprint.ModuleContext) {
49 // Nothing to do.
50}
51
52func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
53 // Override to create a package id.
54 return newPackageId(ctx.ModuleDir())
55}
56
Paul Duffine2453c72019-05-31 14:00:04 +010057func PackageFactory() Module {
58 module := &packageModule{}
59
Paul Duffine2453c72019-05-31 14:00:04 +010060 module.AddProperties(&module.properties)
Paul Duffin63c6e182019-07-24 14:24:38 +010061
Paul Duffincdfcec92020-05-01 11:57:12 +010062 // The name is the relative path from build root to the directory containing this
63 // module. Set that name at the earliest possible moment that information is available
64 // which is in a LoadHook.
65 AddLoadHook(module, func(ctx LoadHookContext) {
66 module.nameProperties.Name = proptools.StringPtr("//" + ctx.ModuleDir())
67 })
68
Paul Duffin63c6e182019-07-24 14:24:38 +010069 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +010070 // its checking and parsing phases so make it the primary visibility property.
71 setPrimaryVisibilityProperty(module, "default_visibility", &module.properties.Default_visibility)
Paul Duffin63c6e182019-07-24 14:24:38 +010072
Bob Badour37af0462021-01-07 03:34:31 +000073 // The default_applicable_licenses property needs to be checked and parsed by the licenses module during
74 // its checking and parsing phases so make it the primary licenses property.
75 setPrimaryLicensesProperty(module, "default_applicable_licenses", &module.properties.Default_applicable_licenses)
76
Paul Duffine2453c72019-05-31 14:00:04 +010077 return module
78}