Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 1 | // 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 18 | "github.com/google/blueprint" |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 19 | "github.com/google/blueprint/proptools" |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | func init() { |
Paul Duffin | c132742 | 2020-01-14 12:15:29 +0000 | [diff] [blame] | 23 | RegisterPackageBuildComponents(InitRegistrationContext) |
| 24 | } |
| 25 | |
Paul Duffin | cfd3374 | 2021-02-27 11:59:02 +0000 | [diff] [blame] | 26 | var PrepareForTestWithPackageModule = FixtureRegisterWithContext(RegisterPackageBuildComponents) |
| 27 | |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 28 | // Register the package module type. |
Paul Duffin | c132742 | 2020-01-14 12:15:29 +0000 | [diff] [blame] | 29 | func RegisterPackageBuildComponents(ctx RegistrationContext) { |
| 30 | ctx.RegisterModuleType("package", PackageFactory) |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | type packageProperties struct { |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 34 | // Specifies the default visibility for all modules defined in this package. |
| 35 | Default_visibility []string |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 36 | // Specifies the default license terms for all modules defined in this package. |
| 37 | Default_applicable_licenses []string |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame] | 38 | Default_team *string `android:"path"` |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Yu Liu | 95cef3a | 2025-02-25 00:54:20 +0000 | [diff] [blame] | 41 | type PackageInfo struct { |
| 42 | Properties packageProperties |
| 43 | } |
| 44 | |
| 45 | var PackageInfoProvider = blueprint.NewProvider[PackageInfo]() |
| 46 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 47 | type packageModule struct { |
| 48 | ModuleBase |
| 49 | |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 50 | properties packageProperties |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | func (p *packageModule) GenerateAndroidBuildActions(ModuleContext) { |
| 54 | // Nothing to do. |
| 55 | } |
| 56 | |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame] | 57 | func (p *packageModule) DepsMutator(ctx BottomUpMutatorContext) { |
| 58 | // Add the dependency to do a validity check |
| 59 | if p.properties.Default_team != nil { |
| 60 | ctx.AddDependency(ctx.Module(), nil, *p.properties.Default_team) |
| 61 | } |
| 62 | } |
| 63 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 64 | func (p *packageModule) GenerateBuildActions(ctx blueprint.ModuleContext) { |
Yu Liu | f22120f | 2025-03-13 18:36:35 +0000 | [diff] [blame] | 65 | ctx.SetProvider(CommonModuleInfoProvider, &CommonModuleInfo{ |
Yu Liu | 367827f | 2025-02-15 00:18:33 +0000 | [diff] [blame] | 66 | Enabled: true, |
| 67 | PrimaryLicensesProperty: p.primaryLicensesProperty, |
| 68 | }) |
Yu Liu | 95cef3a | 2025-02-25 00:54:20 +0000 | [diff] [blame] | 69 | |
| 70 | ctx.SetProvider(PackageInfoProvider, PackageInfo{ |
| 71 | Properties: p.properties, |
| 72 | }) |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName { |
| 76 | // Override to create a package id. |
| 77 | return newPackageId(ctx.ModuleDir()) |
| 78 | } |
| 79 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 80 | func PackageFactory() Module { |
| 81 | module := &packageModule{} |
| 82 | |
Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 83 | module.AddProperties(&module.properties) |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 84 | |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 85 | // The name is the relative path from build root to the directory containing this |
| 86 | // module. Set that name at the earliest possible moment that information is available |
| 87 | // which is in a LoadHook. |
| 88 | AddLoadHook(module, func(ctx LoadHookContext) { |
| 89 | module.nameProperties.Name = proptools.StringPtr("//" + ctx.ModuleDir()) |
| 90 | }) |
| 91 | |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 92 | // The default_visibility property needs to be checked and parsed by the visibility module during |
Paul Duffin | 5ec73ec | 2020-05-01 17:52:01 +0100 | [diff] [blame] | 93 | // its checking and parsing phases so make it the primary visibility property. |
| 94 | setPrimaryVisibilityProperty(module, "default_visibility", &module.properties.Default_visibility) |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 95 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 96 | // The default_applicable_licenses property needs to be checked and parsed by the licenses module during |
| 97 | // its checking and parsing phases so make it the primary licenses property. |
| 98 | setPrimaryLicensesProperty(module, "default_applicable_licenses", &module.properties.Default_applicable_licenses) |
| 99 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 100 | return module |
| 101 | } |