Split platform creation out of java_integration_test and simplify.
PiperOrigin-RevId: 262885000
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index 5e2c91c..d6d640f 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -164,6 +164,7 @@
srcs = ["java_integration_test.sh"],
args = ["$(JAVABASE)"],
data = [
+ "java_integration_test_utils.sh",
":test-deps",
"//src/test/shell:shell_utils",
],
diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh
index 9722ef0..68684a9 100755
--- a/src/test/shell/integration/java_integration_test.sh
+++ b/src/test/shell/integration/java_integration_test.sh
@@ -23,6 +23,10 @@
source "${CURRENT_DIR}/../integration_test_setup.sh" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }
+# Load the helper utils.
+source "${CURRENT_DIR}/java_integration_test_utils.sh" \
+ || { echo "java_integration_test_utils.sh not found!" >&2; exit 1; }
+
set -eu
declare -r runfiles_relative_javabase="$1"
@@ -260,50 +264,7 @@
)
EOF
- if [ ! -f buildenv/platforms/BUILD ]; then
- cat >> "$pkg/jvm/BUILD" <<EOF
-constraint_setting(
- name = 'constraint_setting',
-)
-constraint_value(
- name = 'constraint',
- constraint_setting = ':constraint_setting',
-)
-toolchain(
- name = 'java_runtime_toolchain',
- toolchain = ':runtime',
- toolchain_type = '@bazel_tools//tools/jdk:runtime_toolchain_type',
- target_compatible_with = [':constraint'],
-)
-platform(
- name = 'platform',
- parents = ['@bazel_tools//platforms:host_platform'],
- constraint_values = [':constraint'],
-)
-EOF
- else
- cat >> "$pkg/jvm/BUILD" <<EOF
-constraint_value(
- name = 'constraint',
- constraint_setting = '//third_party/bazel_rules/rules_java/java/constraints:runtime',
-)
-toolchain(
- name = 'java_runtime_toolchain',
- toolchain = ':runtime',
- toolchain_type = '//tools/jdk:runtime_toolchain_type',
- target_compatible_with = [':constraint'],
-)
-platform(
- name = 'platform',
- parents = ['//buildenv/platforms:host_platform'],
- constraint_values = [
- ':constraint',
- '//third_party/bazel_rules/rules_java/java/constraints:java8',
- ],
-)
-EOF
- fi
-
+ create_java_test_platforms
# Set javabase to an absolute path.
bazel build //$pkg/java/hello:hello //$pkg/java/hello:hello_deploy.jar \
diff --git a/src/test/shell/integration/java_integration_test_utils.sh b/src/test/shell/integration/java_integration_test_utils.sh
new file mode 100644
index 0000000..c15b800
--- /dev/null
+++ b/src/test/shell/integration/java_integration_test_utils.sh
@@ -0,0 +1,43 @@
+# 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.
+
+# Define platforms needed for java integration tests.
+
+set -euo pipefail
+
+# Assumes integration_test_setup.sh was loaded elsewhere (can't load it twice)
+
+function create_java_test_platforms() {
+ cat >> "$pkg/jvm/BUILD" <<EOF
+constraint_setting(
+ name = 'constraint_setting',
+)
+constraint_value(
+ name = 'constraint',
+ constraint_setting = ':constraint_setting',
+)
+toolchain(
+ name = 'java_runtime_toolchain',
+ toolchain = ':runtime',
+ toolchain_type = '@bazel_tools//tools/jdk:runtime_toolchain_type',
+ target_compatible_with = [':constraint'],
+)
+platform(
+ name = 'platform',
+ parents = ['@bazel_tools//platforms:host_platform'],
+ constraint_values = [':constraint'],
+)
+EOF
+}
+