From e4449ba24809b2043932edd0f7504dbdc0239e52 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 30 Aug 2024 14:34:37 -0700 Subject: [PATCH] Harmonize license rules between google3 and OSS This simplifies upb by removing differences between google3 and OSS. This also points upb at the protobuf license, instead of keeping a separate copy around for upb. PiperOrigin-RevId: 669447145 --- BUILD.bazel | 7 +++++++ MODULE.bazel | 5 +++++ bazel/common/BUILD | 2 ++ bazel/private/BUILD | 2 ++ bazel/tests/BUILD | 2 ++ bazel/tests/testdata/BUILD | 5 ++++- bazel/toolchains/BUILD | 2 ++ benchmarks/BUILD | 4 +--- editions/codegen_tests/BUILD | 4 ++++ hpb/BUILD | 2 +- hpb/backend/upb/BUILD | 2 +- hpb/bazel/BUILD | 4 +--- hpb/internal/BUILD | 2 +- hpb_generator/BUILD | 2 +- hpb_generator/tests/BUILD | 4 +--- protobuf_deps.bzl | 10 ++++++++++ protos/BUILD | 2 +- python/BUILD.bazel | 4 +--- python/pb_unit_tests/BUILD | 4 +--- rust/test/upb/BUILD | 2 ++ rust/upb/BUILD | 4 +--- third_party/utf8_range/BUILD.bazel | 12 +++++++++++- third_party/utf8_range/fuzz/BUILD.bazel | 2 ++ upb/BUILD | 10 +--------- upb/bazel/BUILD | 4 +--- upb/cmake/make_cmakelists.py | 2 ++ upb/conformance/BUILD | 4 +--- upb/hash/BUILD | 4 +--- upb/io/BUILD | 4 +--- upb/json/BUILD | 4 +--- upb/lex/BUILD | 4 +--- upb/test/BUILD | 4 +--- upb/util/BUILD | 4 +--- upb_generator/BUILD | 4 +--- upb_generator/c/BUILD | 4 +--- upb_generator/minitable/BUILD | 4 +--- upb_generator/reflection/BUILD | 4 +--- 37 files changed, 79 insertions(+), 70 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 42175b5ed1..89d8e98f00 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1,7 @@ # Bazel (https://bazel.build/) BUILD file for Protobuf. load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("@rules_license//rules:license.bzl", "license") load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") load("//bazel:cc_proto_library.bzl", "cc_proto_library") load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library") @@ -17,6 +18,12 @@ exports_files([ "PrivacyInfo.xcprivacy", ]) +license( + name = "license", + package_name = "protobuf", + license_text = ":LICENSE", +) + ################################################################################ # Well Known Types Proto Library Rules # diff --git a/MODULE.bazel b/MODULE.bazel index 25038f8308..3511b13991 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -53,6 +53,11 @@ bazel_dep( version = "1.9.0", ) +bazel_dep( + name = "rules_license", + version = "0.0.8", +) + bazel_dep( name = "rules_pkg", version = "0.7.0", diff --git a/bazel/common/BUILD b/bazel/common/BUILD index 91d5f62ac5..200f4fd876 100644 --- a/bazel/common/BUILD +++ b/bazel/common/BUILD @@ -1,5 +1,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +package(default_applicable_licenses = ["//:license"]) + bzl_library( name = "proto_common_bzl", srcs = [ diff --git a/bazel/private/BUILD b/bazel/private/BUILD index 4a44f3334f..5726c77296 100644 --- a/bazel/private/BUILD +++ b/bazel/private/BUILD @@ -1,6 +1,8 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("//bazel/private:native_bool_flag.bzl", "native_bool_flag") +package(default_applicable_licenses = ["//:license"]) + toolchain_type( name = "proto_toolchain_type", ) diff --git a/bazel/tests/BUILD b/bazel/tests/BUILD index 54cc42150e..886b4c471c 100644 --- a/bazel/tests/BUILD +++ b/bazel/tests/BUILD @@ -1,3 +1,5 @@ load(":proto_common_compile_tests.bzl", "proto_common_compile_test_suite") +package(default_applicable_licenses = ["//:license"]) + proto_common_compile_test_suite(name = "proto_common_compile_test_suite") diff --git a/bazel/tests/testdata/BUILD b/bazel/tests/testdata/BUILD index 6ae81e08c2..d5cdd6bebf 100644 --- a/bazel/tests/testdata/BUILD +++ b/bazel/tests/testdata/BUILD @@ -1,4 +1,7 @@ -package(default_visibility = ["//visibility:public"]) +package( + default_applicable_licenses = ["//:license"], + default_visibility = ["//visibility:public"], +) proto_lang_toolchain( name = "toolchain", diff --git a/bazel/toolchains/BUILD b/bazel/toolchains/BUILD index 6a6bfbc7ec..0faf75ab10 100644 --- a/bazel/toolchains/BUILD +++ b/bazel/toolchains/BUILD @@ -1,5 +1,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +package(default_applicable_licenses = ["//:license"]) + bzl_library( name = "proto_toolchain_bzl", srcs = [ diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 766f36644d..010cedc305 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -20,9 +20,7 @@ load( "tmpl_cc_binary", ) -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/editions/codegen_tests/BUILD b/editions/codegen_tests/BUILD index 08c63555d6..1ee0a9ef50 100644 --- a/editions/codegen_tests/BUILD +++ b/editions/codegen_tests/BUILD @@ -1,5 +1,9 @@ load("//bazel:cc_proto_library.bzl", "cc_proto_library") +package( + default_applicable_licenses = ["//:license"], +) + exports_files( glob(["*.proto"]), visibility = [ diff --git a/hpb/BUILD b/hpb/BUILD index 2f5296dc9a..8f7aa7e4b0 100644 --- a/hpb/BUILD +++ b/hpb/BUILD @@ -15,7 +15,7 @@ load( ) # begin:google_only -# package(default_applicable_licenses = ["//src/google/protobuf:license"]) +# package(default_applicable_licenses = ["//:license"]) # end:google_only licenses(["notice"]) diff --git a/hpb/backend/upb/BUILD b/hpb/backend/upb/BUILD index 007dcf7aac..e81d239411 100644 --- a/hpb/backend/upb/BUILD +++ b/hpb/backend/upb/BUILD @@ -6,7 +6,7 @@ # https://developers.google.com/open-source/licenses/bsd # begin:google_only -# package(default_applicable_licenses = ["//src/google/protobuf:license"]) +# package(default_applicable_licenses = ["//:license"]) # end:google_only cc_library( diff --git a/hpb/bazel/BUILD b/hpb/bazel/BUILD index 95fa04885d..4097ec3b30 100644 --- a/hpb/bazel/BUILD +++ b/hpb/bazel/BUILD @@ -7,9 +7,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/hpb/internal/BUILD b/hpb/internal/BUILD index d956b3587f..67d58f0e79 100644 --- a/hpb/internal/BUILD +++ b/hpb/internal/BUILD @@ -11,7 +11,7 @@ load( ) # begin:google_only -# package(default_applicable_licenses = ["//src/google/protobuf:license"]) +# package(default_applicable_licenses = ["//:license"]) # end:google_only cc_library( diff --git a/hpb_generator/BUILD b/hpb_generator/BUILD index fba7127106..367eaaf0fe 100644 --- a/hpb_generator/BUILD +++ b/hpb_generator/BUILD @@ -11,7 +11,7 @@ load( ) # begin:google_only -# package(default_applicable_licenses = ["//src/google/protobuf:license"]) +# package(default_applicable_licenses = ["//:license"]) # end:google_only licenses(["notice"]) diff --git a/hpb_generator/tests/BUILD b/hpb_generator/tests/BUILD index 308a3334ba..82889c7013 100644 --- a/hpb_generator/tests/BUILD +++ b/hpb_generator/tests/BUILD @@ -25,9 +25,7 @@ # ) # end:google_only -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) # todo: re-add post migration # begin:google_only diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 0c90a525d4..9802bcc3ed 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -178,6 +178,16 @@ def protobuf_deps(): url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.9.0/rules_kotlin-v1.9.0.tar.gz", ) + if not native.existing_rule("rules_license"): + http_archive( + name = "rules_license", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.8/rules_license-0.0.8.tar.gz", + "https://github.com/bazelbuild/rules_license/releases/download/0.0.8/rules_license-0.0.8.tar.gz", + ], + sha256 = "241b06f3097fd186ff468832150d6cc142247dc42a32aaefb56d0099895fd229", + ) + # Python Downloads python_source_archive( name = "python-3.8.0", diff --git a/protos/BUILD b/protos/BUILD index ba1783eb5b..645367ec14 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -11,7 +11,7 @@ # "UPB_DEFAULT_CPPOPTS", # ) # -# package(default_applicable_licenses = ["//upb:license"]) +# package(default_applicable_licenses = ["//:license"]) # # licenses(["notice"]) # diff --git a/python/BUILD.bazel b/python/BUILD.bazel index e8a7625018..ec05cae11b 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -20,9 +20,7 @@ build_targets(name = "python") licenses(["notice"]) package( - # begin:google_only - # default_applicable_licenses = ["//upb:license"], - # end:google_only + default_applicable_licenses = ["//:license"], default_visibility = ["//python/dist:__pkg__"], ) diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index 4d6244b0ea..b46bcbb1b3 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -11,9 +11,7 @@ load("@pip_deps//:requirements.bzl", "requirement") load(":pyproto_test_wrapper.bzl", "pyproto_test_wrapper") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/rust/test/upb/BUILD b/rust/test/upb/BUILD index 8cfc78f4c7..4076c66515 100644 --- a/rust/test/upb/BUILD +++ b/rust/test/upb/BUILD @@ -19,6 +19,8 @@ load("@rules_rust//rust:defs.bzl", "rust_test") +package(default_applicable_licenses = ["//:license"]) + licenses(["notice"]) # TODO: Enable this for the cpp kernel and move these tests to shared. diff --git a/rust/upb/BUILD b/rust/upb/BUILD index 8fd5505a04..05e6ec55d0 100644 --- a/rust/upb/BUILD +++ b/rust/upb/BUILD @@ -10,9 +10,7 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) rust_library( name = "upb", diff --git a/third_party/utf8_range/BUILD.bazel b/third_party/utf8_range/BUILD.bazel index fdc1a49b1e..90b1088c4c 100644 --- a/third_party/utf8_range/BUILD.bazel +++ b/third_party/utf8_range/BUILD.bazel @@ -4,13 +4,23 @@ # license that can be found in the LICENSE file or at # https://opensource.org/licenses/MIT. +load("@rules_license//rules:license.bzl", "license") + DEFAULT_VISIBILITY = [ "//src/google/protobuf:__subpackages__", "//third_party/utf8_range:__subpackages__", "//util/utf8/internal:__subpackages__", ] -package(default_visibility = ["//visibility:public"]) +package( + default_applicable_licenses = ["//third_party/utf8_range:license"], + default_visibility = ["//visibility:public"], +) + +license( + name = "license", + package_name = "utf8_range", +) licenses(["notice"]) diff --git a/third_party/utf8_range/fuzz/BUILD.bazel b/third_party/utf8_range/fuzz/BUILD.bazel index 43e153eb87..d16d1acd20 100644 --- a/third_party/utf8_range/fuzz/BUILD.bazel +++ b/third_party/utf8_range/fuzz/BUILD.bazel @@ -1,5 +1,7 @@ load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test") +package(default_applicable_licenses = ["//third_party/utf8_range:license"]) + cc_fuzz_test( name = "utf8_validity_fuzzer", testonly = 1, diff --git a/upb/BUILD b/upb/BUILD index d817017399..db8b2e96dc 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -12,7 +12,6 @@ load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") # begin:google_only # load("//tools/build_defs/kotlin/native:rules.bzl", "kt_native_interop_hint") -# load("//tools/build_defs/license:license.bzl", "license") # end:google_only # begin:github_only @@ -22,14 +21,7 @@ load( ) # end:github_only -# begin:google_only -# package(default_applicable_licenses = [":license"]) -# -# license( -# name = "license", -# package_name = "upb", -# ) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/upb/bazel/BUILD b/upb/bazel/BUILD index 03e7f3615b..dba415635e 100644 --- a/upb/bazel/BUILD +++ b/upb/bazel/BUILD @@ -8,9 +8,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects") load("@rules_python//python:defs.bzl", "py_binary") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/upb/cmake/make_cmakelists.py b/upb/cmake/make_cmakelists.py index bd959178f4..271ff8a255 100755 --- a/upb/cmake/make_cmakelists.py +++ b/upb/cmake/make_cmakelists.py @@ -238,6 +238,8 @@ class BuildFileFunctions(object): def alias(self, **kwargs): pass + def package(self, **kwargs): + pass class Converter(object): def __init__(self): diff --git a/upb/conformance/BUILD b/upb/conformance/BUILD index 9630c016bc..72a13b99b9 100644 --- a/upb/conformance/BUILD +++ b/upb/conformance/BUILD @@ -16,9 +16,7 @@ load( "make_shell_script", ) -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/upb/hash/BUILD b/upb/hash/BUILD index 51f2da3941..ce45ad22b2 100644 --- a/upb/hash/BUILD +++ b/upb/hash/BUILD @@ -7,9 +7,7 @@ load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) cc_library( name = "hash", diff --git a/upb/io/BUILD b/upb/io/BUILD index c1886185c2..700eb046d0 100644 --- a/upb/io/BUILD +++ b/upb/io/BUILD @@ -1,6 +1,4 @@ -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) cc_library( name = "string", diff --git a/upb/json/BUILD b/upb/json/BUILD index 8979918fe8..dd22455852 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -7,9 +7,7 @@ load( ) load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) cc_library( name = "json", diff --git a/upb/lex/BUILD b/upb/lex/BUILD index efcf9e9e40..da8fb158a5 100644 --- a/upb/lex/BUILD +++ b/upb/lex/BUILD @@ -7,9 +7,7 @@ load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) cc_library( name = "lex", diff --git a/upb/test/BUILD b/upb/test/BUILD index d85f03e9ca..ad359e6e4e 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -19,9 +19,7 @@ load( "UPB_DEFAULT_CPPOPTS", ) -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) cc_library( name = "parse_text_proto", diff --git a/upb/util/BUILD b/upb/util/BUILD index 40b1f63af7..ec992ac311 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -4,9 +4,7 @@ load( "upb_proto_reflection_library", ) -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/upb_generator/BUILD b/upb_generator/BUILD index 703beb90e4..0c625cbf68 100644 --- a/upb_generator/BUILD +++ b/upb_generator/BUILD @@ -25,9 +25,7 @@ load( "bootstrap_upb_proto_library", ) -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/upb_generator/c/BUILD b/upb_generator/c/BUILD index 057894b52d..70d22c3cf1 100644 --- a/upb_generator/c/BUILD +++ b/upb_generator/c/BUILD @@ -8,9 +8,7 @@ load( "bootstrap_cc_library", ) -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/upb_generator/minitable/BUILD b/upb_generator/minitable/BUILD index f60b1b1acc..42ed36172c 100644 --- a/upb_generator/minitable/BUILD +++ b/upb_generator/minitable/BUILD @@ -12,9 +12,7 @@ load( "bootstrap_cc_library", ) -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"]) diff --git a/upb_generator/reflection/BUILD b/upb_generator/reflection/BUILD index f432cd4dcd..be01fb7f19 100644 --- a/upb_generator/reflection/BUILD +++ b/upb_generator/reflection/BUILD @@ -7,9 +7,7 @@ load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS") -# begin:google_only -# package(default_applicable_licenses = ["//upb:license"]) -# end:google_only +package(default_applicable_licenses = ["//:license"]) licenses(["notice"])