From 98ca5438f1ff2eb760a47c0853a77efa0ab364e9 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Tue, 28 Mar 2023 16:41:51 -0400 Subject: [PATCH] Move TraceInfo to a new place --- doc_build/BUILD | 3 ++- rules/BUILD | 2 +- rules/gather_licenses_info.bzl | 2 +- rules/gather_metadata.bzl | 2 +- rules/licenses_core.bzl | 23 ++--------------------- rules_gathering/BUILD | 33 +++++++++++++++++++++++++++++++++ rules_gathering/trace.bzl | 30 ++++++++++++++++++++++++++++++ 7 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 rules_gathering/BUILD create mode 100644 rules_gathering/trace.bzl diff --git a/doc_build/BUILD b/doc_build/BUILD index c50e2d4..6181ca7 100644 --- a/doc_build/BUILD +++ b/doc_build/BUILD @@ -59,6 +59,7 @@ ORDER = [ ("LicenseInfo", "//rules:providers.bzl"), ("LicenseKindInfo", "//rules:providers.bzl"), ("PackageInfo", "//rules:providers.bzl"), + ("trace", "//rules_gathering:trace.bzl"), ] genrule( @@ -90,7 +91,7 @@ bzl_library( "//:version.bzl", "//rules:standard_package", "//rules/private:standard_package", - # "@bazel_skylib//lib:paths", + "//rules_gathering:standard_package", ], visibility = ["//visibility:public"], ) diff --git a/rules/BUILD b/rules/BUILD index 83e8c14..2f510f4 100644 --- a/rules/BUILD +++ b/rules/BUILD @@ -15,7 +15,7 @@ # limitations under the License. """Rules for making license declarations.""" -load("@rules_license//rules:licenses_core.bzl", "trace") +load("@rules_license//rules_gathering:trace.bzl", "trace") package( default_applicable_licenses = ["//:license"], diff --git a/rules/gather_licenses_info.bzl b/rules/gather_licenses_info.bzl index 599cee0..fba6c99 100644 --- a/rules/gather_licenses_info.bzl +++ b/rules/gather_licenses_info.bzl @@ -15,7 +15,6 @@ load( "@rules_license//rules:licenses_core.bzl", - "TraceInfo", "gather_metadata_info_common", "should_traverse", ) @@ -23,6 +22,7 @@ load( "@rules_license//rules/private:gathering_providers.bzl", "TransitiveLicensesInfo", ) +load("@rules_license//rules_gathering:trace.bzl", "TraceInfo") def _strip_null_repo(label): """Removes the null repo name (e.g. @//) from a string. diff --git a/rules/gather_metadata.bzl b/rules/gather_metadata.bzl index be84964..f64fe63 100644 --- a/rules/gather_metadata.bzl +++ b/rules/gather_metadata.bzl @@ -15,7 +15,6 @@ load( "@rules_license//rules:licenses_core.bzl", - "TraceInfo", "gather_metadata_info_common", "should_traverse", ) @@ -28,6 +27,7 @@ load( "@rules_license//rules/private:gathering_providers.bzl", "TransitiveMetadataInfo", ) +load("@rules_license//rules_gathering:trace.bzl", "TraceInfo") def _strip_null_repo(label): """Removes the null repo name (e.g. @//) from a string. diff --git a/rules/licenses_core.bzl b/rules/licenses_core.bzl index 96a313f..075643d 100644 --- a/rules/licenses_core.bzl +++ b/rules/licenses_core.bzl @@ -14,33 +14,14 @@ """Rules and macros for collecting LicenseInfo providers.""" load("@rules_license//rules:filtered_rule_kinds.bzl", "aspect_filters") +load("@rules_license//rules:providers.bzl", "LicenseInfo") load("@rules_license//rules:user_filtered_rule_kinds.bzl", "user_aspect_filters") -load( - "@rules_license//rules:providers.bzl", - "LicenseInfo", -) load( "@rules_license//rules/private:gathering_providers.bzl", "LicensedTargetInfo", "TransitiveLicensesInfo", ) - - -TraceInfo = provider( - doc = """Provides a target (as a string) to assist in debugging dependency issues.""", - fields = { - "trace": "String: a target to trace dependency edges to.", - }, -) - -def _trace_impl(ctx): - return TraceInfo(trace = ctx.build_setting_value) - -trace = rule( - doc = """Used to allow the specification of a target to trace while collecting license dependencies.""", - implementation = _trace_impl, - build_setting = config.string(flag = True), -) +load("@rules_license//rules_gathering:trace.bzl", "TraceInfo") def should_traverse(ctx, attr): """Checks if the dependent attribute should be traversed. diff --git a/rules_gathering/BUILD b/rules_gathering/BUILD new file mode 100644 index 0000000..6798eb6 --- /dev/null +++ b/rules_gathering/BUILD @@ -0,0 +1,33 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Rules for making license declarations.""" + +package( + default_applicable_licenses = ["//:license"], + default_visibility = ["//visibility:public"], +) + +filegroup( + name = "standard_package", + srcs = glob(["**"]), +) + +# Do not create a bzl_library(). That would create a dependency loop back +# to bazel-skylib. We export the .bzl files to the documentation maker. +exports_files( + glob([ + "*.bzl", + ]), + visibility = ["//doc_build:__pkg__"], +) diff --git a/rules_gathering/trace.bzl b/rules_gathering/trace.bzl new file mode 100644 index 0000000..f4a7b25 --- /dev/null +++ b/rules_gathering/trace.bzl @@ -0,0 +1,30 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Rules and macros for collecting package metdata providers.""" + +TraceInfo = provider( + doc = """Provides a target (as a string) to assist in debugging dependency issues.""", + fields = { + "trace": "String: a target to trace dependency edges to.", + }, +) + +def _trace_impl(ctx): + return TraceInfo(trace = ctx.build_setting_value) + +trace = rule( + doc = """Used to allow the specification of a target to trace while collecting license dependencies.""", + implementation = _trace_impl, + build_setting = config.string(flag = True), +)