xref: /aosp_15_r20/build/soong/android/license_kind.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright 2020 Google Inc. All rights reserved.
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage android
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerfunc init() {
18*333d2b36SAndroid Build Coastguard Worker	RegisterLicenseKindBuildComponents(InitRegistrationContext)
19*333d2b36SAndroid Build Coastguard Worker}
20*333d2b36SAndroid Build Coastguard Worker
21*333d2b36SAndroid Build Coastguard Worker// Register the license_kind module type.
22*333d2b36SAndroid Build Coastguard Workerfunc RegisterLicenseKindBuildComponents(ctx RegistrationContext) {
23*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("license_kind", LicenseKindFactory)
24*333d2b36SAndroid Build Coastguard Worker}
25*333d2b36SAndroid Build Coastguard Worker
26*333d2b36SAndroid Build Coastguard Workertype licenseKindProperties struct {
27*333d2b36SAndroid Build Coastguard Worker	// Specifies the conditions for all licenses of the kind.
28*333d2b36SAndroid Build Coastguard Worker	Conditions []string
29*333d2b36SAndroid Build Coastguard Worker	// Specifies the url to the canonical license definition.
30*333d2b36SAndroid Build Coastguard Worker	Url string
31*333d2b36SAndroid Build Coastguard Worker	// Specifies where this license can be used
32*333d2b36SAndroid Build Coastguard Worker	Visibility []string
33*333d2b36SAndroid Build Coastguard Worker}
34*333d2b36SAndroid Build Coastguard Worker
35*333d2b36SAndroid Build Coastguard Workertype licenseKindModule struct {
36*333d2b36SAndroid Build Coastguard Worker	ModuleBase
37*333d2b36SAndroid Build Coastguard Worker	DefaultableModuleBase
38*333d2b36SAndroid Build Coastguard Worker
39*333d2b36SAndroid Build Coastguard Worker	properties licenseKindProperties
40*333d2b36SAndroid Build Coastguard Worker}
41*333d2b36SAndroid Build Coastguard Worker
42*333d2b36SAndroid Build Coastguard Workerfunc (m *licenseKindModule) DepsMutator(ctx BottomUpMutatorContext) {
43*333d2b36SAndroid Build Coastguard Worker	// Nothing to do.
44*333d2b36SAndroid Build Coastguard Worker}
45*333d2b36SAndroid Build Coastguard Worker
46*333d2b36SAndroid Build Coastguard Workerfunc (m *licenseKindModule) GenerateAndroidBuildActions(ModuleContext) {
47*333d2b36SAndroid Build Coastguard Worker	// Nothing to do.
48*333d2b36SAndroid Build Coastguard Worker}
49*333d2b36SAndroid Build Coastguard Worker
50*333d2b36SAndroid Build Coastguard Workerfunc LicenseKindFactory() Module {
51*333d2b36SAndroid Build Coastguard Worker	module := &licenseKindModule{}
52*333d2b36SAndroid Build Coastguard Worker
53*333d2b36SAndroid Build Coastguard Worker	base := module.base()
54*333d2b36SAndroid Build Coastguard Worker	module.AddProperties(&base.nameProperties, &module.properties)
55*333d2b36SAndroid Build Coastguard Worker
56*333d2b36SAndroid Build Coastguard Worker	// The visibility property needs to be checked and parsed by the visibility module.
57*333d2b36SAndroid Build Coastguard Worker	setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility)
58*333d2b36SAndroid Build Coastguard Worker
59*333d2b36SAndroid Build Coastguard Worker	initAndroidModuleBase(module)
60*333d2b36SAndroid Build Coastguard Worker	InitDefaultableModule(module)
61*333d2b36SAndroid Build Coastguard Worker
62*333d2b36SAndroid Build Coastguard Worker	return module
63*333d2b36SAndroid Build Coastguard Worker}
64