Skip to content

Commit f758956

Browse files
authored
Pass rlocationpaths to Test Runner (#1645)
* pass rlocationpaths to scalatest Runner - fixes paths passed to scalatest Runner that was broken in a recent commit. - Now properly uses rlocationpaths. * lint fix
1 parent 4faf94f commit f758956

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

scala/private/phases/phase_runfiles.bzl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@io_bazel_rules_scala//scala/private:common.bzl", "rlocationpath_from_file")
2+
13
#
24
# PHASE: runfiles
35
#
@@ -13,7 +15,7 @@ def phase_runfiles_library(ctx, p):
1315
def phase_runfiles_scalatest(ctx, p):
1416
args = "\n".join([
1517
"-R",
16-
ctx.outputs.jar.short_path.replace("../", "external/"),
18+
rlocationpath_from_file(ctx, ctx.outputs.jar),
1719
_scala_test_flags(ctx),
1820
"-C",
1921
ctx.attr.reporter_class,

scala/private/phases/phase_write_executable.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ load(
1414
"runfiles_root",
1515
"specified_java_runtime",
1616
)
17+
load("@io_bazel_rules_scala//scala/private:common.bzl", "rlocationpath_from_file")
1718

1819
def phase_write_executable_scalatest(ctx, p):
1920
# jvm_flags passed in on the target override scala_test_jvm_flags passed in on the
@@ -27,7 +28,7 @@ def phase_write_executable_scalatest(ctx, p):
2728
rjars = p.coverage_runfiles.rjars,
2829
jvm_flags = [
2930
"-DRULES_SCALA_MAIN_WS_NAME=%s" % ctx.workspace_name,
30-
"-DRULES_SCALA_ARGS_FILE=%s" % p.runfiles.args_file.short_path.replace("../", "external/"),
31+
"-DRULES_SCALA_ARGS_FILE=%s" % rlocationpath_from_file(ctx, p.runfiles.args_file),
3132
] + expand_location(ctx, final_jvm_flags) + _allow_security_manager_for_specified_java_runtime(ctx),
3233
use_jacoco = ctx.configuration.coverage_enabled,
3334
)

src/java/io/bazel/rulesscala/scala_test/Runner.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.io.IOException;
66
import java.nio.charset.Charset;
77
import java.nio.file.Files;
8-
import java.nio.file.Path;
98
import java.nio.file.Paths;
109
import java.util.List;
1110
import java.util.Map;
@@ -49,9 +48,7 @@ private static String[] extendFromFileArgs(String[] args) throws IOException {
4948
if (workspace == null || workspace.trim().isEmpty())
5049
throw new IllegalArgumentException(RULES_SCALA_MAIN_WS_NAME + " is null or empty.");
5150

52-
53-
Path runnerArgsUnresolvedFileLocation = Paths.get(workspace + "/" + runnerArgsFileKey).normalize();
54-
String runnerArgsFilePath = Runfiles.create().rlocation(runnerArgsUnresolvedFileLocation.toString());
51+
String runnerArgsFilePath = Runfiles.create().rlocation(runnerArgsFileKey);
5552
if (runnerArgsFilePath == null)
5653
throw new IllegalArgumentException("rlocation value is null for key: " + runnerArgsFileKey);
5754

@@ -92,9 +89,8 @@ private static void rlocateRunpathValue(String rulesWorkspace, List<String> runn
9289
if (runpathFlag >= 0) {
9390
String[] runpathElements = runnerArgs.get(runpathFlag + 1).split(File.pathSeparator);
9491
Runfiles runfiles = Runfiles.create();
95-
for (int i = 0; i < runpathElements.length; i++) {
96-
Path runPathElementPath = Paths.get(rulesWorkspace + "/" + runpathElements[i]).normalize();
97-
runpathElements[i] = runfiles.rlocation(runPathElementPath.toString());
92+
for (int i = 0; i < runpathElements.length; i++) {
93+
runpathElements[i] = runfiles.rlocation(runpathElements[i].toString());
9894
}
9995
String runpath = String.join(File.separator, runpathElements);
10096
runnerArgs.set(runpathFlag + 1, runpath);

0 commit comments

Comments
 (0)