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 | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame^] | 26 | // Register the package module type. |
Paul Duffin | c132742 | 2020-01-14 12:15:29 +0000 | [diff] [blame] | 27 | func RegisterPackageBuildComponents(ctx RegistrationContext) { |
| 28 | ctx.RegisterModuleType("package", PackageFactory) |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | type packageProperties struct { |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 32 | // Specifies the default visibility for all modules defined in this package. |
| 33 | Default_visibility []string |
| 34 | } |
| 35 | |
| 36 | type packageModule struct { |
| 37 | ModuleBase |
| 38 | |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame^] | 39 | properties packageProperties |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | func (p *packageModule) GenerateAndroidBuildActions(ModuleContext) { |
| 43 | // Nothing to do. |
| 44 | } |
| 45 | |
| 46 | func (p *packageModule) GenerateBuildActions(ctx blueprint.ModuleContext) { |
| 47 | // Nothing to do. |
| 48 | } |
| 49 | |
| 50 | func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName { |
| 51 | // Override to create a package id. |
| 52 | return newPackageId(ctx.ModuleDir()) |
| 53 | } |
| 54 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 55 | func PackageFactory() Module { |
| 56 | module := &packageModule{} |
| 57 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 58 | module.AddProperties(&module.properties) |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 59 | |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame^] | 60 | // The name is the relative path from build root to the directory containing this |
| 61 | // module. Set that name at the earliest possible moment that information is available |
| 62 | // which is in a LoadHook. |
| 63 | AddLoadHook(module, func(ctx LoadHookContext) { |
| 64 | module.nameProperties.Name = proptools.StringPtr("//" + ctx.ModuleDir()) |
| 65 | }) |
| 66 | |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 67 | // 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] | 68 | // its checking and parsing phases so make it the primary visibility property. |
| 69 | setPrimaryVisibilityProperty(module, "default_visibility", &module.properties.Default_visibility) |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 70 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 71 | return module |
| 72 | } |