diff --git a/src/BUILD b/src/BUILD index 8ee52eb9a55b7f..dfd06309177bc4 100644 --- a/src/BUILD +++ b/src/BUILD @@ -1,5 +1,6 @@ # Packaging +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@rules_python//python:defs.bzl", "py_binary", "py_library") load("//src:release_archive.bzl", "release_archive") load(":embedded_tools.bzl", "srcsfile") @@ -600,3 +601,8 @@ filegroup( "@workspace_repo_cache//:files", ], ) + +bzl_library( + name = "build_defs_bzl", + srcs = ["build_defs.bzl"], +) diff --git a/src/build_defs.bzl b/src/build_defs.bzl new file mode 100644 index 00000000000000..b1d3206f14cdf0 --- /dev/null +++ b/src/build_defs.bzl @@ -0,0 +1,25 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# 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 +# +# http://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. + +"""Utility for restricting java_library to Java 11 APIs.""" + +load("@rules_java//java:defs.bzl", "java_library") + +# Drop in replacement for java_library that builds the library at Java language level 11. +def java_11_library(**attrs): + javacopts = attrs.pop("javacopts", []) + java_library( + javacopts = javacopts + ["-source 11", "-target 11"], + **attrs + ) diff --git a/src/java_tools/singlejar/java/com/google/devtools/build/zip/BUILD b/src/java_tools/singlejar/java/com/google/devtools/build/zip/BUILD index 3631e3792878d4..f368926f3e365e 100644 --- a/src/java_tools/singlejar/java/com/google/devtools/build/zip/BUILD +++ b/src/java_tools/singlejar/java/com/google/devtools/build/zip/BUILD @@ -1,4 +1,4 @@ -load("@rules_java//java:defs.bzl", "java_library") +load("//src:build_defs.bzl", "java_11_library") # Description: # Zip provides a library for reading and writing zip files, allowing more @@ -21,7 +21,7 @@ filegroup( srcs = glob(["*.java"]), ) -java_library( +java_11_library( name = "zip", srcs = glob(["*.java"]), visibility = ["//visibility:public"], diff --git a/src/main/java/com/google/devtools/build/lib/util/BUILD b/src/main/java/com/google/devtools/build/lib/util/BUILD index 279b3c8dc5b40a..996fcda87fd563 100644 --- a/src/main/java/com/google/devtools/build/lib/util/BUILD +++ b/src/main/java/com/google/devtools/build/lib/util/BUILD @@ -1,3 +1,4 @@ +load("//src:build_defs.bzl", "java_11_library") load("@rules_java//java:defs.bzl", "java_library") package( @@ -30,7 +31,7 @@ java_library( ], ) -java_library( +java_11_library( name = "os", srcs = ["OS.java"], ) @@ -156,7 +157,7 @@ java_library( ], ) -java_library( +java_11_library( name = "pair", srcs = [ "Pair.java", diff --git a/src/main/java/com/google/devtools/build/lib/windows/BUILD b/src/main/java/com/google/devtools/build/lib/windows/BUILD index 88187f2f23cd65..3a7ab1ca7adf07 100644 --- a/src/main/java/com/google/devtools/build/lib/windows/BUILD +++ b/src/main/java/com/google/devtools/build/lib/windows/BUILD @@ -1,3 +1,4 @@ +load("//src:build_defs.bzl", "java_11_library") load("@rules_java//java:defs.bzl", "java_library") package( @@ -12,7 +13,7 @@ filegroup( visibility = ["//src:__subpackages__"], ) -java_library( +java_11_library( name = "file", srcs = ["WindowsFileOperations.java"], deps = ["//src/main/java/com/google/devtools/build/lib/jni"], diff --git a/src/main/java/com/google/devtools/common/options/BUILD b/src/main/java/com/google/devtools/common/options/BUILD index b5120de838dc0c..4df7d7fbc94c3d 100644 --- a/src/main/java/com/google/devtools/common/options/BUILD +++ b/src/main/java/com/google/devtools/common/options/BUILD @@ -1,3 +1,4 @@ +load("//src:build_defs.bzl", "java_11_library") load("@rules_java//java:defs.bzl", "java_library") # Description: @@ -33,13 +34,13 @@ java_library( ], ) -java_library( +java_11_library( name = "options", exported_plugins = ["//src/main/java/com/google/devtools/common/options/processor:options_preprocessor"], exports = [":options_internal"], ) -java_library( +java_11_library( name = "options_internal", srcs = glob( ["*.java"],