Change target to targets for license_policy_check
diff --git a/examples/policy_checker/BUILD b/examples/policy_checker/BUILD index 49f77aa..1b89067 100644 --- a/examples/policy_checker/BUILD +++ b/examples/policy_checker/BUILD
@@ -47,7 +47,7 @@ license_policy_check( name = "check_server", policy = ":production_service", - target = "//examples/src:my_server", + targets = ["//examples/src:my_server"], ) @@ -59,5 +59,5 @@ tags = [ "manual", ], - target = "//examples/src:my_violating_server", + targets = ["//examples/src:my_violating_server"], )
diff --git a/examples/policy_checker/license_policy_check.bzl b/examples/policy_checker/license_policy_check.bzl index 7dccb35..9b4045d 100644 --- a/examples/policy_checker/license_policy_check.bzl +++ b/examples/policy_checker/license_policy_check.bzl
@@ -25,31 +25,34 @@ load("@rules_license//rules:providers.bzl", "LicenseInfo") load("@rules_license//rules_gathering:gathering_providers.bzl", "TransitiveLicensesInfo") -# This is a crude example of the kind of thing which can be done. +# This is a crude example of the kind of license reporting which can be done. def _license_policy_check_impl(ctx): policy = ctx.attr.policy[LicensePolicyInfo] allowed_conditions = policy.conditions - if TransitiveLicensesInfo in ctx.attr.target: - for license in ctx.attr.target[TransitiveLicensesInfo].licenses.to_list(): - for kind in license.license_kinds: - # print(kind.conditions) - for condition in kind.conditions: - if condition not in allowed_conditions: - fail("Condition %s violates policy %s" % ( - condition, - policy.label, - )) - if LicenseInfo in ctx.attr.target: - for license in ctx.attr.target[LicenseInfo].licenses.to_list(): - for kind in license.license_kinds: - # print(kind.conditions) - for condition in kind.conditions: - if condition not in allowed_conditions: - fail("Condition %s violates policy %s" % ( - condition, - policy.label, - )) + for target in ctx.attr.targets: + if TransitiveLicensesInfo in target: + for license in target[TransitiveLicensesInfo].licenses.to_list(): + for kind in license.license_kinds: + for condition in kind.conditions: + if condition not in allowed_conditions: + fail("Condition %s violates policy %s of %s" % ( + condition, + policy.label, + target.label, + )) + + for target in ctx.attr.targets: + if LicenseInfo in target: + for license in target[LicenseInfo].licenses.to_list(): + for kind in license.license_kinds: + for condition in kind.conditions: + if condition not in allowed_conditions: + fail("Condition %s violates policy %s of %s" % ( + condition, + policy.label, + target.label, + )) return [DefaultInfo()] _license_policy_check = rule( @@ -61,21 +64,20 @@ mandatory = True, providers = [LicensePolicyInfo], ), - "target": attr.label( + "targets": attr.label_list( doc = """Target to collect LicenseInfo for.""", aspects = [gather_licenses_info], mandatory = True, - allow_single_file = True, ), }, ) -def license_policy_check(name, target, policy, **kwargs): - """Checks a target against a policy. +def license_policy_check(name, targets, policy, **kwargs): + """Checks a list of targets against a policy. Args: name: The target. - target: A target to test for compliance with a policy + targets: A list of targets to test for compliance with a policy policy: A rule providing LicensePolicyInfo. **kwargs: other args. @@ -83,8 +85,8 @@ license_policy_check( name = "license_info", - target = ":my_app", + targets = [":my_app"], policy = "//my_org/compliance/policies:mobile_application", ) """ - _license_policy_check(name = name, target = target, policy = policy, **kwargs) + _license_policy_check(name = name, targets = targets, policy = policy, **kwargs)