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 ( |
Sasha Smundak | 8bea267 | 2022-08-04 13:31:14 -0700 | [diff] [blame^] | 18 | "android/soong/bazel" |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 19 | "github.com/google/blueprint" |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 20 | "github.com/google/blueprint/proptools" |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | func init() { |
Paul Duffin | c132742 | 2020-01-14 12:15:29 +0000 | [diff] [blame] | 24 | RegisterPackageBuildComponents(InitRegistrationContext) |
| 25 | } |
| 26 | |
Paul Duffin | cfd3374 | 2021-02-27 11:59:02 +0000 | [diff] [blame] | 27 | var PrepareForTestWithPackageModule = FixtureRegisterWithContext(RegisterPackageBuildComponents) |
| 28 | |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 29 | // Register the package module type. |
Paul Duffin | c132742 | 2020-01-14 12:15:29 +0000 | [diff] [blame] | 30 | func RegisterPackageBuildComponents(ctx RegistrationContext) { |
| 31 | ctx.RegisterModuleType("package", PackageFactory) |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | type packageProperties struct { |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 35 | // Specifies the default visibility for all modules defined in this package. |
| 36 | Default_visibility []string |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 37 | // Specifies the default license terms for all modules defined in this package. |
| 38 | Default_applicable_licenses []string |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Sasha Smundak | 8bea267 | 2022-08-04 13:31:14 -0700 | [diff] [blame^] | 41 | type bazelPackageAttributes struct { |
| 42 | Default_visibility []string |
| 43 | Default_applicable_licenses bazel.LabelListAttribute |
| 44 | } |
| 45 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 46 | type packageModule struct { |
| 47 | ModuleBase |
Sasha Smundak | 8bea267 | 2022-08-04 13:31:14 -0700 | [diff] [blame^] | 48 | BazelModuleBase |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 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 | |
Sasha Smundak | 8bea267 | 2022-08-04 13:31:14 -0700 | [diff] [blame^] | 53 | var _ Bazelable = &packageModule{} |
| 54 | |
| 55 | func (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 Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 68 | func (p *packageModule) GenerateAndroidBuildActions(ModuleContext) { |
| 69 | // Nothing to do. |
| 70 | } |
| 71 | |
| 72 | func (p *packageModule) GenerateBuildActions(ctx blueprint.ModuleContext) { |
| 73 | // Nothing to do. |
| 74 | } |
| 75 | |
| 76 | func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName { |
| 77 | // Override to create a package id. |
| 78 | return newPackageId(ctx.ModuleDir()) |
| 79 | } |
| 80 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 81 | func PackageFactory() Module { |
| 82 | module := &packageModule{} |
| 83 | |
Sasha Smundak | 8bea267 | 2022-08-04 13:31:14 -0700 | [diff] [blame^] | 84 | module.AddProperties(&module.properties, &module.commonProperties.BazelConversionStatus) |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 85 | |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 86 | // 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 Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 93 | // 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] | 94 | // its checking and parsing phases so make it the primary visibility property. |
| 95 | setPrimaryVisibilityProperty(module, "default_visibility", &module.properties.Default_visibility) |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 96 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 97 | // 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 Smundak | 8bea267 | 2022-08-04 13:31:14 -0700 | [diff] [blame^] | 101 | InitBazelModule(module) |
| 102 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 103 | return module |
| 104 | } |