From 042d70872fdede13394a13747628fee761c50917 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Mon, 16 Sep 2019 09:39:50 +0000 Subject: [PATCH] Bazel: Pass current host java runtime to sh_test rule Change-Id: I5f41dc1d8c46160b6870a53544293c44531adc81 --- prologtests/examples/BUILD | 17 +++++++---------- prologtests/examples/run.sh | 11 ++++++++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/prologtests/examples/BUILD b/prologtests/examples/BUILD index f4ebe901b8..ebf2c68111 100644 --- a/prologtests/examples/BUILD +++ b/prologtests/examples/BUILD @@ -1,15 +1,12 @@ package(default_visibility = ["//visibility:public"]) -DUMMY = ["dummy.sh"] - -# Enable prologtests on newer Java versions again, when this Bazel bug is fixed: -# https://github.com/bazelbuild/bazel/issues/9391 sh_test( name = "test_examples", - srcs = select({ - "//:java11": DUMMY, - "//:java_next": DUMMY, - "//conditions:default": ["run.sh"], - }), - data = glob(["*.pl"]) + ["//:gerrit.war"], + srcs = ["run.sh"], + args = ["$(JAVA)"], + data = glob(["*.pl"]) + [ + "//:gerrit.war", + "@bazel_tools//tools/jdk:current_host_java_runtime", + ], + toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"], ) diff --git a/prologtests/examples/run.sh b/prologtests/examples/run.sh index 947c1532f6..b2883ebe48 100755 --- a/prologtests/examples/run.sh +++ b/prologtests/examples/run.sh @@ -1,5 +1,14 @@ #!/bin/bash +# TODO(davido): Figure out what to do if running alone and not invoked from bazel +# $1 is equal to the $(JAVABASE)/bin/java make variable +JAVA=$1 + +# Checks whether or not the $1 is starting with a slash: '/' and thus considered to be +# an absolute path. If it is, then it is left as is, if it isn't then "$PWD/ is prepended +# (in sh_test case it is relative and thus the runfiles directory is prepended). +[[ "$JAVA" =~ ^(/|[^/]+$) ]] || JAVA="$PWD/$JAVA" + TESTS="t1 t2 t3" # Note that both t1.pl and t2.pl test code in rules.pl. @@ -36,7 +45,7 @@ do # Unit tests do not need to define clauses in packages. # Use one prolog-shell per unit test, to avoid name collision. echo "### Running test ${T}.pl" - echo "[$T]." | java -jar ${GERRIT_WAR} prolog-shell -q -s load.pl + echo "[$T]." | "${JAVA}" -jar ${GERRIT_WAR} prolog-shell -q -s load.pl if [ "x$?" != "x0" ]; then echo "### Test ${T}.pl failed."