blob: 78df938352fed54b27fb4b55c909d399a1ab81fa [file] [log] [blame]
Bob Badour37af0462021-01-07 03:34:31 +00001// 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
15package android
16
Sasha Smundaka93c62b2022-09-14 13:40:03 -070017import "android/soong/bazel"
18
Bob Badour37af0462021-01-07 03:34:31 +000019func init() {
20 RegisterLicenseKindBuildComponents(InitRegistrationContext)
21}
22
23// Register the license_kind module type.
24func RegisterLicenseKindBuildComponents(ctx RegistrationContext) {
25 ctx.RegisterModuleType("license_kind", LicenseKindFactory)
26}
27
28type 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 Smundaka93c62b2022-09-14 13:40:03 -070037var _ Bazelable = &licenseKindModule{}
38
Bob Badour37af0462021-01-07 03:34:31 +000039type licenseKindModule struct {
40 ModuleBase
41 DefaultableModuleBase
Sasha Smundaka93c62b2022-09-14 13:40:03 -070042 BazelModuleBase
Bob Badour37af0462021-01-07 03:34:31 +000043
44 properties licenseKindProperties
45}
46
Sasha Smundaka93c62b2022-09-14 13:40:03 -070047type bazelLicenseKindAttributes struct {
48 Conditions []string
49 Url string
50 Visibility []string
51}
52
Chris Parsons637458d2023-09-19 20:09:00 +000053func (m *licenseKindModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
Sasha Smundaka93c62b2022-09-14 13:40:03 -070054 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 Badour37af0462021-01-07 03:34:31 +000070func (m *licenseKindModule) DepsMutator(ctx BottomUpMutatorContext) {
71 // Nothing to do.
72}
73
74func (m *licenseKindModule) GenerateAndroidBuildActions(ModuleContext) {
75 // Nothing to do.
76}
77
78func LicenseKindFactory() Module {
79 module := &licenseKindModule{}
80
81 base := module.base()
Sasha Smundaka93c62b2022-09-14 13:40:03 -070082 module.AddProperties(&base.nameProperties, &module.properties, &base.commonProperties.BazelConversionStatus)
Bob Badour37af0462021-01-07 03:34:31 +000083
Bob Badour37af0462021-01-07 03:34:31 +000084 // 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 Smundaka93c62b2022-09-14 13:40:03 -070089 InitBazelModule(module)
Bob Badour37af0462021-01-07 03:34:31 +000090
91 return module
92}