1# Copyright 2020 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 15"""license_policy rule. 16 17A license_policy names a set of conditions allowed in the union of all 18license_kinds use by a target. The name of the rule is typically an 19application type (e.g. production_server, mobile_application, ...) 20 21""" 22 23load( 24 "@rules_license//examples/policy_checker:license_policy_provider.bzl", 25 "LicensePolicyInfo" 26) 27 28def _license_policy_impl(ctx): 29 provider = LicensePolicyInfo( 30 name = ctx.attr.name, 31 label = "@%s//%s:%s" % ( 32 ctx.label.workspace_name, 33 ctx.label.package, 34 ctx.label.name, 35 ), 36 conditions = ctx.attr.conditions, 37 ) 38 return [provider] 39 40_license_policy = rule( 41 implementation = _license_policy_impl, 42 attrs = { 43 "conditions": attr.string_list( 44 doc = "Conditions to be met when using software under this license." + 45 " Conditions are defined by the organization using this license.", 46 mandatory = True, 47 ), 48 }, 49) 50 51def license_policy(name, conditions): 52 _license_policy( 53 name = name, 54 conditions = conditions, 55 applicable_licenses = [], 56 ) 57