Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use java macros in java_tools. #8758

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ distdir_tar(
"android_tools_pkg-0.7.tar.gz",
# bazelbuild/platforms
"441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
],
dirname = "derived/distdir",
sha256 = {
Expand All @@ -134,6 +136,8 @@ distdir_tar(
"android_tools_pkg-0.7.tar.gz": "a8e48f2fdee2c34b31f45bd47ce050a75ac774f19e0a1f6694fa49fc11d88718", # built at 6bb5ae2a8353d75867ac9136d374df7916450449
# bazelbuild/platforms
"441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip": "a07fe5e75964361885db725039c2ba673f0ee0313d971ae4f50c9b18cd28b0b5",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": "bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598",
},
urls = {
"e0b0291b2c51fbe5a7cfa14473a1ae850f94f021.zip": [
Expand Down Expand Up @@ -176,6 +180,10 @@ distdir_tar(
"https://mirror.bazel.build/github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
"https://github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
],
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": [
"https://github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
]
},
)

Expand Down Expand Up @@ -418,6 +426,8 @@ distdir_tar(
"android_tools_pkg-0.7.tar.gz",
# bazelbuild/platforms
"441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
],
dirname = "test_WORKSPACE/distdir",
sha256 = {
Expand All @@ -443,6 +453,8 @@ distdir_tar(
"android_tools_pkg-0.7.tar.gz": "a8e48f2fdee2c34b31f45bd47ce050a75ac774f19e0a1f6694fa49fc11d88718", # built at 6bb5ae2a8353d75867ac9136d374df7916450449
# bazelbuild/platforms
"441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip": "a07fe5e75964361885db725039c2ba673f0ee0313d971ae4f50c9b18cd28b0b5",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": "bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598",
},
urls = {
"zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz"],
Expand Down Expand Up @@ -472,6 +484,10 @@ distdir_tar(
"https://mirror.bazel.build/github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
"https://github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
],
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": [
"https://github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip"
]
},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# External dependencies for the java_* rules.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

new_local_repository(
name = "local_jdk",
Expand Down Expand Up @@ -238,4 +239,12 @@ http_archive(
],
)

maybe(
http_archive,
"rules_java",
sha256 = "bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598",
urls = ["https://github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip"],
strip_prefix = "rules_java-7cf3cefd652008d0a64a419c34c13bdca6c8f178"
)

register_toolchains("@bazel_tools//tools/jdk:all")
9 changes: 9 additions & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ sh_test(
shard_count = 3,
)

sh_test(
name = "bazel_rules_java_test",
srcs = ["bazel_rules_java_test.sh"],
data = [
":test-deps",
"@bazel_tools//tools/bash/runfiles",
],
)

sh_test(
name = "bazel_test_test",
timeout = "long",
Expand Down
16 changes: 16 additions & 0 deletions src/test/shell/bazel/bazel_java_tools_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,20 @@ function test_java_tools_has_proguard() {
expect_path_in_java_tools "java_tools/third_party/java/proguard/GPL.html"
}

function test_java_tools_toolchain_builds() {
iirina marked this conversation as resolved.
Show resolved Hide resolved
local java_tools_rlocation=$(rlocation io_bazel/src/java_tools_${JAVA_TOOLS_JAVA_VERSION}.zip)
local java_tools_zip_file_url="file://${java_tools_rlocation}"
if "$is_windows"; then
java_tools_zip_file_url="file:///${java_tools_rlocation}"
fi
cat >WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "local_java_tools",
urls = ["${java_tools_zip_file_url}"]
)
EOF
bazel build @local_java_tools//:toolchain || fail "toolchain failed to build"
}

run_suite "Java tools archive tests"
87 changes: 87 additions & 0 deletions src/test/shell/bazel/bazel_rules_java_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
#
# Copyright 2019 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.
#
# Tests the examples provided in Bazel
#

# --- begin runfiles.bash initialization ---
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
if [[ -f "$0.runfiles_manifest" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
export RUNFILES_DIR="$0.runfiles"
fi
fi
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
else
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
exit 1
fi
# --- end runfiles.bash initialization ---

source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

case "$(uname -s | tr [:upper:] [:lower:])" in
msys*|mingw*|cygwin*)
declare -r is_windows=true
;;
*)
declare -r is_windows=false
;;
esac

if "$is_windows"; then
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL="*"
fi

function test_rules_java_can_be_overridden() {
# We test that a custom repository can override @platforms in their
# WORKSPACE file.
mkdir -p rules_java_can_be_overridden || fail "couldn't create directory"
touch rules_java_can_be_overridden/BUILD || \ fail "couldn't touch BUILD file"
cat > rules_java_can_be_overridden/WORKSPACE <<EOF
local_repository(
name = 'rules_java',
path = '../override',
)
EOF

mkdir -p override || fail "couldn't create override directory"
touch override/WORKSPACE || fail "couldn't touch override/WORKSPACE"
cat > override/BUILD <<EOF
filegroup(name = 'yolo')
EOF

cd rules_java_can_be_overridden || fail "couldn't cd into workspace"
bazel build @rules_java//:yolo &> $TEST_log || \
fail "Bazel failed to build @rules_java"
}

function test_rules_java_repository_builds_itself() {
# We test that a built-in @rules_java repository is buildable.
bazel build @rules_java//... &> $TEST_log \
|| fail "Build failed unexpectedly"
}

run_suite "rules_java tests"
2 changes: 2 additions & 0 deletions tools/jdk/BUILD.java_tools
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

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

java_toolchain(
name = "toolchain",
bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath"],
Expand Down