diff --git a/BUILD b/BUILD index 3a0651a..505d249 100644 --- a/BUILD +++ b/BUILD @@ -1,8 +1,16 @@ +load("@rules_license//rules:license.bzl", "license") load("//:bzl_library.bzl", "bzl_library") -licenses(["notice"]) +package( + default_applicable_licenses = ["//:license"], + default_visibility = ["//visibility:public"], +) -package(default_visibility = ["//visibility:public"]) +license( + name = "license", + package_name = "bazelbuild/bazel_skylib", + license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"], +) # buildifier: disable=skylark-comment # gazelle:exclude skylark_library.bzl diff --git a/MODULE.bazel b/MODULE.bazel index 289ac32..13cd955 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -11,6 +11,7 @@ register_toolchains( ) bazel_dep(name = "platforms", version = "0.0.4") +bazel_dep(name = "rules_license", version = "0.0.7") ### INTERNAL ONLY - lines after this are not included in the release packaging. diff --git a/distribution/BUILD b/distribution/BUILD index 4465779..92f121b 100644 --- a/distribution/BUILD +++ b/distribution/BUILD @@ -4,6 +4,7 @@ load("@rules_pkg//:pkg.bzl", "pkg_tar") load("distribution.bzl", "remove_internal_only") package( + default_applicable_licenses = ["//:license"], default_visibility = ["//visibility:private"], ) diff --git a/docs/BUILD b/docs/BUILD index b25bcce..7cef661 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -1,6 +1,6 @@ load("//docs/private:stardoc_with_diff_test.bzl", "stardoc_with_diff_test", "update_docs") -licenses(["notice"]) +package(default_applicable_licenses = ["//:license"]) stardoc_with_diff_test( name = "analysis_test", diff --git a/docs/private/BUILD b/docs/private/BUILD index f8c832b..2064516 100644 --- a/docs/private/BUILD +++ b/docs/private/BUILD @@ -1 +1,3 @@ -# No targets in this package +# This package only contains source targets + +package(default_applicable_licenses = ["//:license"]) diff --git a/gazelle/BUILD b/gazelle/BUILD index d1c6daa..2e5f191 100644 --- a/gazelle/BUILD +++ b/gazelle/BUILD @@ -1,4 +1,13 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@rules_license//rules:license.bzl", "license") + +package(default_applicable_licenses = ["@bazel_skylib//:license"]) + +license( + name = "license", + package_name = "bazelbuild/bazel_skylib_gazelle_module", + license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"], +) exports_files(["WORKSPACE.bzlmod"]) diff --git a/gazelle/MODULE.bazel b/gazelle/MODULE.bazel index 3c9c243..6b81405 100644 --- a/gazelle/MODULE.bazel +++ b/gazelle/MODULE.bazel @@ -6,7 +6,8 @@ module( ) # Keep in sync with @bazel_skylib//:MODULE.bazel and @bazel_skylib//:version.bzl -bazel_dep(name = "bazel_skylib", version = "1.4.2") +bazel_dep(name = "bazel_skylib", version = "1.6.1") +bazel_dep(name = "rules_license", version = "0.0.7") bazel_dep(name = "gazelle", version = "0.29.0", repo_name = "bazel_gazelle") bazel_dep(name = "rules_go", version = "0.41.0", repo_name = "io_bazel_rules_go") diff --git a/gazelle/bzl/BUILD b/gazelle/bzl/BUILD index 0b8e6d3..c32236e 100644 --- a/gazelle/bzl/BUILD +++ b/gazelle/bzl/BUILD @@ -1,6 +1,8 @@ load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +package(default_applicable_licenses = ["//:license"]) + # gazelle:exclude testdata go_library( diff --git a/gazelle/workspace.bzl b/gazelle/workspace.bzl index 0eca993..4f18eb5 100644 --- a/gazelle/workspace.bzl +++ b/gazelle/workspace.bzl @@ -22,6 +22,16 @@ def bazel_skylib_gazelle_plugin_workspace(): """Loads dependencies required to use skylib's gazelle plugin""" bazel_skylib_workspace() + maybe( + http_archive, + name = "rules_license", + sha256 = "4531deccb913639c30e5c7512a054d5d875698daeb75d8cf90f284375fe7c360", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz", + "https://github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz", + ], + ) + maybe( http_archive, name = "io_bazel_rules_go", diff --git a/lib/BUILD b/lib/BUILD index 08a7173..08c00a8 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -1,8 +1,9 @@ load("//:bzl_library.bzl", "bzl_library") -licenses(["notice"]) - -package(default_visibility = ["//visibility:public"]) +package( + default_applicable_licenses = ["//:license"], + default_visibility = ["//visibility:public"], +) # export bzl files for the documentation exports_files( diff --git a/rules/BUILD b/rules/BUILD index 3a06554..6de7b2c 100644 --- a/rules/BUILD +++ b/rules/BUILD @@ -1,8 +1,9 @@ load("//:bzl_library.bzl", "bzl_library") -licenses(["notice"]) - -package(default_visibility = ["//visibility:public"]) +package( + default_applicable_licenses = ["//:license"], + default_visibility = ["//visibility:public"], +) bzl_library( name = "analysis_test", diff --git a/rules/private/BUILD b/rules/private/BUILD index 7bd3652..429e6cb 100644 --- a/rules/private/BUILD +++ b/rules/private/BUILD @@ -1,6 +1,6 @@ load("//:bzl_library.bzl", "bzl_library") -licenses(["notice"]) +package(default_applicable_licenses = ["//:license"]) bzl_library( name = "copy_common", diff --git a/tests/BUILD b/tests/BUILD index 9cfe7d6..f0b2a1f 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -15,7 +15,10 @@ load(":types_tests.bzl", "types_test_suite") load(":unittest_tests.bzl", "unittest_passing_tests_suite") load(":versions_tests.bzl", "versions_test_suite") -licenses(["notice"]) +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) exports_files( ["unittest.bash"], diff --git a/tests/bzl_library/BUILD b/tests/bzl_library/BUILD index 72a4b9c..e6a8cda 100644 --- a/tests/bzl_library/BUILD +++ b/tests/bzl_library/BUILD @@ -1,6 +1,11 @@ load("//:bzl_library.bzl", "bzl_library") load(":bzl_library_test.bzl", "bzl_library_test") +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) + filegroup( name = "a", srcs = ["testdata/a.bzl"], diff --git a/tests/common_settings/BUILD b/tests/common_settings/BUILD index 606a4f6..f21ba50 100644 --- a/tests/common_settings/BUILD +++ b/tests/common_settings/BUILD @@ -1,8 +1,9 @@ load("//rules:common_settings.bzl", "int_flag", "string_flag") -licenses(["notice"]) - -package(default_testonly = 1) +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) int_flag( name = "my_int_flag", diff --git a/tests/copy_directory/BUILD.bazel b/tests/copy_directory/BUILD.bazel index f766e99..c706561 100644 --- a/tests/copy_directory/BUILD.bazel +++ b/tests/copy_directory/BUILD.bazel @@ -3,9 +3,10 @@ load("//rules:copy_directory.bzl", "copy_directory") load(":empty_directory.bzl", "empty_directory") -licenses(["notice"]) - -package(default_testonly = 1) +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) # Copy of directory containing files a and b, and a subdir containing c copy_directory( diff --git a/tests/copy_file/BUILD b/tests/copy_file/BUILD index 2e6914c..f9cb94c 100644 --- a/tests/copy_file/BUILD +++ b/tests/copy_file/BUILD @@ -33,9 +33,10 @@ load("//rules:copy_file.bzl", "copy_file") -licenses(["notice"]) - -package(default_testonly = 1) +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) sh_test( name = "copy_file_tests", diff --git a/tests/diff_test/BUILD b/tests/diff_test/BUILD index aa381d8..475f156 100644 --- a/tests/diff_test/BUILD +++ b/tests/diff_test/BUILD @@ -2,9 +2,10 @@ load("//rules:diff_test.bzl", "diff_test") -licenses(["notice"]) - -package(default_testonly = 1) +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) sh_test( name = "diff_test_tests", diff --git a/tests/expand_template/BUILD b/tests/expand_template/BUILD index 0607111..07fc579 100644 --- a/tests/expand_template/BUILD +++ b/tests/expand_template/BUILD @@ -16,6 +16,11 @@ load("//rules:expand_template.bzl", "expand_template") +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) + expand_template( name = "filled_template", out = "foo/test.yaml", diff --git a/tests/native_binary/BUILD b/tests/native_binary/BUILD index ad32cba..5ec2d54 100644 --- a/tests/native_binary/BUILD +++ b/tests/native_binary/BUILD @@ -2,6 +2,7 @@ load("//rules:copy_file.bzl", "copy_file") load("//rules:native_binary.bzl", "native_binary", "native_test") package( + default_applicable_licenses = ["//:license"], default_testonly = 1, default_visibility = ["//visibility:private"], ) diff --git a/tests/run_binary/BUILD b/tests/run_binary/BUILD index 18682f6..0d5b5ac 100644 --- a/tests/run_binary/BUILD +++ b/tests/run_binary/BUILD @@ -3,6 +3,7 @@ load("//rules:run_binary.bzl", "run_binary") load("//rules:write_file.bzl", "write_file") package( + default_applicable_licenses = ["//:license"], default_testonly = 1, default_visibility = ["//visibility:private"], ) diff --git a/tests/select_file/BUILD b/tests/select_file/BUILD index a91c231..6f1e8f7 100644 --- a/tests/select_file/BUILD +++ b/tests/select_file/BUILD @@ -1,7 +1,10 @@ load("//rules:diff_test.bzl", "diff_test") load("//rules:select_file.bzl", "select_file") -licenses(["notice"]) +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) filegroup( name = "fg", diff --git a/tests/unittest_test.sh b/tests/unittest_test.sh index c773d70..271f156 100755 --- a/tests/unittest_test.sh +++ b/tests/unittest_test.sh @@ -79,7 +79,10 @@ EOF ln -sf "$(rlocation $TEST_WORKSPACE/lib/unittest.bzl)" lib/unittest.bzl mkdir -p toolchains/unittest - ln -sf "$(rlocation $TEST_WORKSPACE/toolchains/unittest/BUILD)" toolchains/unittest/BUILD + # Remove `package(default_applicable_license = ...)` line to avoid depending on rules_license inside this test + sed -e '/package(default_applicable_licenses = .*)/d' \ + "$(rlocation $TEST_WORKSPACE/toolchains/unittest/BUILD)" \ + > toolchains/unittest/BUILD # Create test files. mkdir -p testdir diff --git a/tests/write_file/BUILD b/tests/write_file/BUILD index e4f2a94..faae93d 100644 --- a/tests/write_file/BUILD +++ b/tests/write_file/BUILD @@ -35,9 +35,10 @@ load("//rules:diff_test.bzl", "diff_test") load("//rules:write_file.bzl", "write_file") -licenses(["notice"]) - -package(default_testonly = 1) +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) sh_test( name = "write_file_tests", diff --git a/toolchains/unittest/BUILD b/toolchains/unittest/BUILD index dd23962..cf50c3f 100644 --- a/toolchains/unittest/BUILD +++ b/toolchains/unittest/BUILD @@ -1,6 +1,6 @@ load("//lib:unittest.bzl", "TOOLCHAIN_TYPE", "unittest_toolchain") -licenses(["notice"]) +package(default_applicable_licenses = ["//:license"]) toolchain_type( name = "toolchain_type", diff --git a/workspace.bzl b/workspace.bzl index 29fd1e3..0997ec3 100644 --- a/workspace.bzl +++ b/workspace.bzl @@ -15,7 +15,18 @@ """Dependency registration helpers for repositories which need to load bazel-skylib.""" load("@bazel_skylib//lib:unittest.bzl", "register_unittest_toolchains") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") def bazel_skylib_workspace(): """Registers toolchains and declares repository dependencies of the bazel_skylib repository.""" + maybe( + http_archive, + name = "rules_license", + sha256 = "4531deccb913639c30e5c7512a054d5d875698daeb75d8cf90f284375fe7c360", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz", + "https://github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz", + ], + ) register_unittest_toolchains()