Skip to content

Commit

Permalink
Make buildifier happy
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorcloudy committed Nov 10, 2021
1 parent 9a60e85 commit 4888a6e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 41 deletions.
15 changes: 8 additions & 7 deletions java/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module extensions for rules_java."""
load("//java:repositories.bzl", "local_jdk_repo", "remote_jdk11_repos", "remote_jdk15_repos", "remote_jdk16_repos", "remote_jdk17_repos", "java_tools_javac11_repos")

load("//java:repositories.bzl", "java_tools_javac11_repos", "local_jdk_repo", "remote_jdk11_repos", "remote_jdk15_repos", "remote_jdk16_repos", "remote_jdk17_repos")

def _toolchains_impl(ctx):
local_jdk_repo()
java_tools_javac11_repos()
remote_jdk11_repos()
remote_jdk15_repos()
remote_jdk16_repos()
remote_jdk17_repos()
local_jdk_repo()
java_tools_javac11_repos()
remote_jdk11_repos()
remote_jdk15_repos()
remote_jdk16_repos()
remote_jdk17_repos()

toolchains = module_extension(implementation = _toolchains_impl)
9 changes: 6 additions & 3 deletions java/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def java_tools_javac11_repos():
],
)


http_archive(
name = "remote_java_tools_windows",
sha256 = "36766802f7ec684cecb1a14c122428de6be9784e88419e2ab5912ad4b59a8c7d",
Expand Down Expand Up @@ -385,8 +384,12 @@ def rules_java_dependencies():
java_tools_javac11_repos()
bazel_skylib()

def rules_java_toolchains():
"""An utility method to load all Java toolchains."""
def rules_java_toolchains(name = "toolchains"):
"""An utility method to load all Java toolchains.
Args:
name: The name of this macro (not used)
"""
JDK_VERSIONS = ["11", "15", "16", "17"]
PLATFORMS = ["linux", "macos", "macos_aarch64", "win"]

Expand Down
38 changes: 15 additions & 23 deletions toolchains/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_java//java:defs.bzl", "java_import")
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
load(
"//toolchains:default_java_toolchain.bzl",
"DEFAULT_TOOLCHAIN_CONFIGURATION",
"JVM8_TOOLCHAIN_CONFIGURATION",
"PREBUILT_TOOLCHAIN_CONFIGURATION",
"VANILLA_TOOLCHAIN_CONFIGURATION",
"bootclasspath",
"default_java_toolchain",
"java_runtime_files",
)
Expand All @@ -15,7 +16,6 @@ load(
"java_runtime_version_alias",
"java_toolchain_alias",
)
load("@rules_python//python:defs.bzl", "py_binary", "py_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -100,27 +100,27 @@ java_runtime_files(
cc_library(
name = "jni",
hdrs = [":jni_header"] + select({
"@bazel_tools//src/conditions:darwin": [":jni_md_header-darwin"],
"@bazel_tools//src/conditions:freebsd": [":jni_md_header-freebsd"],
"@bazel_tools//src/conditions:linux_aarch64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_ppc64le": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_s390x": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_mips64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_ppc64le": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_riscv64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_s390x": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_x86_64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:darwin": [":jni_md_header-darwin"],
"@bazel_tools//src/conditions:freebsd": [":jni_md_header-freebsd"],
"@bazel_tools//src/conditions:openbsd": [":jni_md_header-openbsd"],
"@bazel_tools//src/conditions:windows": [":jni_md_header-windows"],
"//conditions:default": [],
}),
includes = ["include"] + select({
"@bazel_tools//src/conditions:darwin": ["include/darwin"],
"@bazel_tools//src/conditions:freebsd": ["include/freebsd"],
"@bazel_tools//src/conditions:linux_aarch64": ["include/linux"],
"@bazel_tools//src/conditions:linux_ppc64le": ["include/linux"],
"@bazel_tools//src/conditions:linux_s390x": ["include/linux"],
"@bazel_tools//src/conditions:linux_mips64": [":include/linux"],
"@bazel_tools//src/conditions:linux_ppc64le": ["include/linux"],
"@bazel_tools//src/conditions:linux_riscv64": [":include/linux"],
"@bazel_tools//src/conditions:linux_s390x": ["include/linux"],
"@bazel_tools//src/conditions:linux_x86_64": ["include/linux"],
"@bazel_tools//src/conditions:darwin": ["include/darwin"],
"@bazel_tools//src/conditions:freebsd": ["include/freebsd"],
"@bazel_tools//src/conditions:openbsd": ["include/openbsd"],
"@bazel_tools//src/conditions:windows": ["include/win32"],
"//conditions:default": [],
Expand Down Expand Up @@ -178,8 +178,8 @@ alias(
alias(
name = "ijar_prebuilt_binary_or_cc_binary",
actual = select({
"@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
"@bazel_tools//src/conditions:darwin": ":ijar_prebuilt_binary_darwin",
"@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
"@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows",
"//conditions:default": "@remote_java_tools//:ijar_cc_binary",
}),
Expand All @@ -188,8 +188,8 @@ alias(
alias(
name = "ijar_prebuilt_binary",
actual = select({
"@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
"@bazel_tools//src/conditions:darwin": ":ijar_prebuilt_binary_darwin",
"@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
"@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows",
}),
)
Expand All @@ -208,8 +208,8 @@ alias(
alias(
name = "singlejar_prebuilt_or_cc_binary",
actual = select({
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
"@bazel_tools//src/conditions:darwin": ":prebuilt_singlejar_darwin",
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
"@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows",
"//conditions:default": "@remote_java_tools//:singlejar_cc_bin",
}),
Expand All @@ -218,8 +218,8 @@ alias(
alias(
name = "prebuilt_singlejar",
actual = select({
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
"@bazel_tools//src/conditions:darwin": ":prebuilt_singlejar_darwin",
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
"@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows",
}),
)
Expand Down Expand Up @@ -311,14 +311,6 @@ alias(
actual = "@remote_java_tools//:proguard",
)

BOOTCLASS_JARS = [
"rt.jar",
"resources.jar",
"jsse.jar",
"jce.jar",
"charsets.jar",
]

# TODO(cushon): this isn't compatible with JDK 9
alias(
name = "bootclasspath",
Expand Down
19 changes: 14 additions & 5 deletions toolchains/default_java_toolchain.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
# Copyright 2021 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.
Expand All @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Bazel rules for creating Java toolchains."""
"""Rules for defining default_java_toolchain"""

load("@rules_java//java:defs.bzl", "java_toolchain")

JDK8_JVM_OPTS = [
"-Xbootclasspath/p:$(location @remote_java_tools//:javac_jar)",
Expand Down Expand Up @@ -162,12 +164,19 @@ NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict(
)

def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, **kwargs):
"""Defines a remote java_toolchain with appropriate defaults for Bazel."""
"""Defines a remote java_toolchain with appropriate defaults for Bazel.
Args:
name: The name of the toolchain
configuration: Toolchain configuration
toolchain_definition: Whether to define toolchain target and its config setting
**kwargs: More arguments for the java_toolchain target
"""

toolchain_args = dict(_BASE_TOOLCHAIN_CONFIGURATION)
toolchain_args.update(configuration)
toolchain_args.update(kwargs)
native.java_toolchain(
java_toolchain(
name = name,
**toolchain_args
)
Expand Down Expand Up @@ -274,14 +283,14 @@ _bootclasspath = rule(
cfg = "host",
providers = [java_common.JavaRuntimeInfo],
),
"output_jar": attr.output(mandatory = True),
"src": attr.label(
cfg = "host",
allow_single_file = True,
),
"target_javabase": attr.label(
providers = [java_common.JavaRuntimeInfo],
),
"output_jar": attr.output(mandatory = True),
},
)

Expand Down
2 changes: 2 additions & 0 deletions toolchains/java_toolchain_alias.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def _java_toolchain_alias(ctx):
"""An experimental implementation of java_toolchain_alias using toolchain resolution."""
toolchain_info = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"]
toolchain = toolchain_info.java

# buildifier: disable=rule-impl-return
return struct(
providers = [
toolchain_info,
Expand Down
7 changes: 4 additions & 3 deletions toolchains/local_java_repository.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The Bazel Authors. All rights reserved.
# Copyright 2021 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.
Expand All @@ -14,6 +14,7 @@

"""Rules for importing and registering a local JDK."""

load("@rules_java//java:defs.bzl", "java_runtime")
load(":default_java_toolchain.bzl", "JVM8_TOOLCHAIN_CONFIGURATION", "default_java_toolchain")

def _detect_java_version(repository_ctx, java_bin):
Expand Down Expand Up @@ -64,7 +65,7 @@ def local_java_runtime(name, java_home, version, runtime_name = None, visibility

if runtime_name == None:
runtime_name = name
native.java_runtime(
java_runtime(
name = runtime_name,
java_home = java_home,
visibility = visibility,
Expand Down Expand Up @@ -210,9 +211,9 @@ _local_java_repository_rule = repository_rule(
local = True,
configure = True,
attrs = {
"build_file": attr.label(),
"java_home": attr.string(),
"version": attr.string(),
"build_file": attr.label(),
},
)

Expand Down

0 comments on commit 4888a6e

Please sign in to comment.