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 15package android 16 17import "android/soong/bazel" 18 19func 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 37var _ Bazelable = &licenseKindModule{} 38 39type licenseKindModule struct { 40 ModuleBase 41 DefaultableModuleBase 42 BazelModuleBase 43 44 properties licenseKindProperties 45} 46 47type bazelLicenseKindAttributes struct { 48 Conditions []string 49 Url string 50 Visibility []string 51} 52 53func (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 70func (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() 82 module.AddProperties(&base.nameProperties, &module.properties, &base.commonProperties.BazelConversionStatus) 83 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) 89 InitBazelModule(module) 90 91 return module 92} 93