1# Copyright 2022 Google LLC 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# https://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"""Proof of concept. License restriction.""" 15 16load("@rules_license//rules:providers.bzl", "LicenseKindInfo") 17 18# 19# License Kind: The declaration of a well known category of license, for example, 20# Apache, MIT, LGPL v2. An organization may also declare its own license kinds 21# that it may user privately. 22# 23 24def _license_kind_impl(ctx): 25 provider = LicenseKindInfo( 26 name = ctx.attr.name, 27 label = "@%s//%s:%s" % ( 28 ctx.label.workspace_name, 29 ctx.label.package, 30 ctx.label.name, 31 ), 32 long_name = ctx.attr.long_name, 33 conditions = ctx.attr.conditions, 34 ) 35 return [provider] 36 37_license_kind = rule( 38 implementation = _license_kind_impl, 39 attrs = { 40 "conditions": attr.string_list( 41 doc = "Conditions to be met when using software under this license." + 42 " Conditions are defined by the organization using this license.", 43 mandatory = True, 44 ), 45 "canonical_text": attr.label( 46 doc = "File containing the canonical text for this license. Must be UTF-8 encoded.", 47 allow_single_file = True, 48 ), 49 "long_name": attr.string(doc = "Human readable long name of license."), 50 "url": attr.string(doc = "URL pointing to canonical license definition"), 51 }, 52) 53 54def license_kind(name, **kwargs): 55 """Wrapper for license_kind. 56 57 @wraps(_license_kind) 58 """ 59 if "conditions" not in kwargs: 60 kwargs["conditions"] = [] 61 if "long_name" not in kwargs: 62 kwargs["long_name"] = name 63 _license_kind( 64 name = name, 65 applicable_licenses = [], 66 **kwargs 67 ) 68