Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1 | // Copyright 2020 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 ( |
Cole Faust | 2ced8c8 | 2022-11-22 16:51:21 -0800 | [diff] [blame] | 18 | "github.com/google/blueprint" |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 19 | ) |
| 20 | |
| 21 | type licenseKindDependencyTag struct { |
Paul Duffin | 3c298a3 | 2021-03-04 17:44:03 +0000 | [diff] [blame] | 22 | blueprint.BaseDependencyTag |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | var ( |
| 26 | licenseKindTag = licenseKindDependencyTag{} |
| 27 | ) |
| 28 | |
| 29 | func init() { |
| 30 | RegisterLicenseBuildComponents(InitRegistrationContext) |
| 31 | } |
| 32 | |
| 33 | // Register the license module type. |
| 34 | func RegisterLicenseBuildComponents(ctx RegistrationContext) { |
| 35 | ctx.RegisterModuleType("license", LicenseFactory) |
| 36 | } |
| 37 | |
| 38 | type licenseProperties struct { |
| 39 | // Specifies the kinds of license that apply. |
| 40 | License_kinds []string |
| 41 | // Specifies a short copyright notice to use for the license. |
| 42 | Copyright_notice *string |
| 43 | // Specifies the path or label for the text of the license. |
| 44 | License_text []string `android:"path"` |
| 45 | // Specifies the package name to which the license applies. |
| 46 | Package_name *string |
| 47 | // Specifies where this license can be used |
| 48 | Visibility []string |
| 49 | } |
| 50 | |
| 51 | type licenseModule struct { |
| 52 | ModuleBase |
| 53 | DefaultableModuleBase |
| 54 | |
| 55 | properties licenseProperties |
| 56 | } |
| 57 | |
| 58 | func (m *licenseModule) DepsMutator(ctx BottomUpMutatorContext) { |
Cole Faust | 2ced8c8 | 2022-11-22 16:51:21 -0800 | [diff] [blame] | 59 | for i, license := range m.properties.License_kinds { |
| 60 | for j := i + 1; j < len(m.properties.License_kinds); j++ { |
| 61 | if license == m.properties.License_kinds[j] { |
| 62 | ctx.ModuleErrorf("Duplicated license kind: %q", license) |
| 63 | break |
| 64 | } |
| 65 | } |
| 66 | } |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 67 | ctx.AddVariationDependencies(nil, licenseKindTag, m.properties.License_kinds...) |
| 68 | } |
| 69 | |
| 70 | func (m *licenseModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Paul Duffin | df5a905 | 2021-05-06 21:52:31 +0100 | [diff] [blame] | 71 | // license modules have no licenses, but license_kinds must refer to license_kind modules |
Paul Duffin | ec0836a | 2021-05-10 22:53:30 +0100 | [diff] [blame] | 72 | mergeStringProps(&m.base().commonProperties.Effective_licenses, ctx.ModuleName()) |
Bob Badour | 4101c71 | 2022-02-09 11:54:35 -0800 | [diff] [blame] | 73 | namePathProps(&m.base().commonProperties.Effective_license_text, m.properties.Package_name, PathsForModuleSrc(ctx, m.properties.License_text)...) |
Paul Duffin | df5a905 | 2021-05-06 21:52:31 +0100 | [diff] [blame] | 74 | for _, module := range ctx.GetDirectDepsWithTag(licenseKindTag) { |
| 75 | if lk, ok := module.(*licenseKindModule); ok { |
Paul Duffin | ec0836a | 2021-05-10 22:53:30 +0100 | [diff] [blame] | 76 | mergeStringProps(&m.base().commonProperties.Effective_license_conditions, lk.properties.Conditions...) |
| 77 | mergeStringProps(&m.base().commonProperties.Effective_license_kinds, ctx.OtherModuleName(module)) |
Paul Duffin | df5a905 | 2021-05-06 21:52:31 +0100 | [diff] [blame] | 78 | } else { |
| 79 | ctx.ModuleErrorf("license_kinds property %q is not a license_kind module", ctx.OtherModuleName(module)) |
| 80 | } |
| 81 | } |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | func LicenseFactory() Module { |
| 85 | module := &licenseModule{} |
| 86 | |
| 87 | base := module.base() |
Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 88 | module.AddProperties(&base.nameProperties, &module.properties) |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 89 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 90 | // The visibility property needs to be checked and parsed by the visibility module. |
| 91 | setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility) |
| 92 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 93 | initAndroidModuleBase(module) |
| 94 | InitDefaultableModule(module) |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 95 | |
| 96 | return module |
| 97 | } |