Skip to content

Commit

Permalink
Add default_applicable_license and remove obsolete licenses() in …
Browse files Browse the repository at this point in the history
…all BUILD files (#504)
  • Loading branch information
tetromino committed May 1, 2024
1 parent 16bf90d commit a16ebb4
Show file tree
Hide file tree
Showing 26 changed files with 104 additions and 31 deletions.
12 changes: 10 additions & 2 deletions 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
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions distribution/BUILD
Expand Up @@ -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"],
)

Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
4 changes: 3 additions & 1 deletion docs/private/BUILD
@@ -1 +1,3 @@
# No targets in this package
# This package only contains source targets

package(default_applicable_licenses = ["//:license"])
9 changes: 9 additions & 0 deletions 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"])

Expand Down
3 changes: 2 additions & 1 deletion gazelle/MODULE.bazel
Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions 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(
Expand Down
10 changes: 10 additions & 0 deletions gazelle/workspace.bzl
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions 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(
Expand Down
7 changes: 4 additions & 3 deletions 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",
Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
5 changes: 4 additions & 1 deletion tests/BUILD
Expand Up @@ -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"],
Expand Down
5 changes: 5 additions & 0 deletions 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"],
Expand Down
7 changes: 4 additions & 3 deletions 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",
Expand Down
7 changes: 4 additions & 3 deletions tests/copy_directory/BUILD.bazel
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions tests/copy_file/BUILD
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions tests/diff_test/BUILD
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions tests/expand_template/BUILD
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/native_binary/BUILD
Expand Up @@ -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"],
)
Expand Down
1 change: 1 addition & 0 deletions tests/run_binary/BUILD
Expand Up @@ -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"],
)
Expand Down
5 changes: 4 additions & 1 deletion 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",
Expand Down
5 changes: 4 additions & 1 deletion tests/unittest_test.sh
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/write_file/BUILD
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
11 changes: 11 additions & 0 deletions workspace.bzl
Expand Up @@ -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()

0 comments on commit a16ebb4

Please sign in to comment.