| 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 |  | 
| Sasha Smundak | a93c62b | 2022-09-14 13:40:03 -0700 | [diff] [blame] | 17 | import "android/soong/bazel" | 
|  | 18 |  | 
| Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 19 | func init() { | 
|  | 20 | RegisterLicenseKindBuildComponents(InitRegistrationContext) | 
|  | 21 | } | 
|  | 22 |  | 
|  | 23 | // Register the license_kind module type. | 
|  | 24 | func RegisterLicenseKindBuildComponents(ctx RegistrationContext) { | 
|  | 25 | ctx.RegisterModuleType("license_kind", LicenseKindFactory) | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | type licenseKindProperties struct { | 
|  | 29 | // Specifies the conditions for all licenses of the kind. | 
|  | 30 | Conditions []string | 
|  | 31 | // Specifies the url to the canonical license definition. | 
|  | 32 | Url string | 
|  | 33 | // Specifies where this license can be used | 
|  | 34 | Visibility []string | 
|  | 35 | } | 
|  | 36 |  | 
| Sasha Smundak | a93c62b | 2022-09-14 13:40:03 -0700 | [diff] [blame] | 37 | var _ Bazelable = &licenseKindModule{} | 
|  | 38 |  | 
| Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 39 | type licenseKindModule struct { | 
|  | 40 | ModuleBase | 
|  | 41 | DefaultableModuleBase | 
| Sasha Smundak | a93c62b | 2022-09-14 13:40:03 -0700 | [diff] [blame] | 42 | BazelModuleBase | 
| Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 43 |  | 
|  | 44 | properties licenseKindProperties | 
|  | 45 | } | 
|  | 46 |  | 
| Sasha Smundak | a93c62b | 2022-09-14 13:40:03 -0700 | [diff] [blame] | 47 | type bazelLicenseKindAttributes struct { | 
|  | 48 | Conditions []string | 
|  | 49 | Url        string | 
|  | 50 | Visibility []string | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | func (m *licenseKindModule) ConvertWithBp2build(ctx TopDownMutatorContext) { | 
|  | 54 | attrs := &bazelLicenseKindAttributes{ | 
|  | 55 | Conditions: m.properties.Conditions, | 
|  | 56 | Url:        m.properties.Url, | 
|  | 57 | Visibility: m.properties.Visibility, | 
|  | 58 | } | 
|  | 59 | ctx.CreateBazelTargetModule( | 
|  | 60 | bazel.BazelTargetModuleProperties{ | 
|  | 61 | Rule_class:        "license_kind", | 
|  | 62 | Bzl_load_location: "@rules_license//rules:license_kind.bzl", | 
|  | 63 | }, | 
|  | 64 | CommonAttributes{ | 
|  | 65 | Name: m.Name(), | 
|  | 66 | }, | 
|  | 67 | attrs) | 
|  | 68 | } | 
|  | 69 |  | 
| Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 70 | func (m *licenseKindModule) DepsMutator(ctx BottomUpMutatorContext) { | 
|  | 71 | // Nothing to do. | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | func (m *licenseKindModule) GenerateAndroidBuildActions(ModuleContext) { | 
|  | 75 | // Nothing to do. | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | func LicenseKindFactory() Module { | 
|  | 79 | module := &licenseKindModule{} | 
|  | 80 |  | 
|  | 81 | base := module.base() | 
| Sasha Smundak | a93c62b | 2022-09-14 13:40:03 -0700 | [diff] [blame] | 82 | module.AddProperties(&base.nameProperties, &module.properties, &base.commonProperties.BazelConversionStatus) | 
| Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 83 |  | 
| Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 84 | // The visibility property needs to be checked and parsed by the visibility module. | 
|  | 85 | setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility) | 
|  | 86 |  | 
|  | 87 | initAndroidModuleBase(module) | 
|  | 88 | InitDefaultableModule(module) | 
| Sasha Smundak | a93c62b | 2022-09-14 13:40:03 -0700 | [diff] [blame] | 89 | InitBazelModule(module) | 
| Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 90 |  | 
|  | 91 | return module | 
|  | 92 | } |