Skip to content

Commit eac6f06

Browse files
authored
Make tests pass on Windows (#1529)
* Make tests pass on Windows Bunch of changes. Here's some highlights: Code Changes - Refactored ScalacWorker to abstract common code between Scala 2 & 3 - Refactored dependency-analyzer plugin javaargs to use ‘;’ as a delimiter instead of ‘:’ - Renamed a couple function names containing rpathlocation to rlocationpath - added lineEndings=preserve to scalafmt.conf - added .bazelrc to enable needed flags for Windows Test Changes - disable running tests for features not-supported on Windows - make tests handle fact that sh_binary outputs .exe on Windows - Handle other Windows specifics where needed (i.e. backslash as pathseparator, crlf linendings, dependence on bash) * Fixed some minor nits
1 parent eb63ea0 commit eac6f06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+416
-545
lines changed

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build --enable_platform_specific_config
2+
3+
#Windows needs --worker_quit_after_build due to workers not being shut down when the compiler tools need to be rebuilt (resulting in 'file in use' errors). See Bazel Issue#10498.
4+
5+
build:windows --worker_quit_after_build --enable_runfiles

.scalafmt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ rewrite.rules = [
1313
SortImports
1414
]
1515
unindentTopLevelOperators = false
16+
lineEndings=preserve

dt_patches/dt_patch_test.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ run_test_local() {
1717
if [ $RESPONSE_CODE -eq 0 ]; then
1818
echo -e "${GREEN} Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
1919
else
20+
echo $RES
2021
echo -e "${RED} Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
2122
return $RESPONSE_CODE
2223
fi
@@ -26,9 +27,12 @@ run_in_test_repo() {
2627
local test_command=$1
2728
local test_repo=$2
2829

29-
cd "${dir}/${test_repo}" || exit 1
30+
cd "${dir}/${test_repo}" || exit 1
3031
${test_command}
3132
RESPONSE_CODE=$?
33+
34+
bazel shutdown
35+
3236
cd ../..
3337

3438
return $RESPONSE_CODE

dt_patches/test_dt_patches/.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import ../../.bazelrc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import ../../.bazelrc
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build --enable_platform_specific_config
2+
windows:build --enable_runfiles
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build --enable_platform_specific_config
2+
windows:build --enable_runfiles

scala/private/common.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ def sanitize_string_for_usage(s):
136136
res_array.append("_")
137137
return "".join(res_array)
138138

139-
#generates rpathlocation that should be used with the rlocation() at runtime. (rpathlocations start with repo name)
139+
#generates an rlocationpath that can be used with the rlocation() at runtime. (rlocationpath starts with repo name)
140+
def rlocationpath_from_file(ctx, file):
141+
return paths.normalize(ctx.workspace_name + "/" + file.short_path)
142+
143+
#generates an rlocationpath that can be used with the rlocation() at runtime. (rlocationpath start with repo name)
140144
#rootpath arg expects "rootpath" format (i.e. relative to runfilesDir/workspacename). Rootpath can be obtained by $rootpath macro or File.short_path
141-
def rpathlocation_from_rootpath(ctx, rootpath):
145+
def rlocationpath_from_rootpath(ctx, rootpath):
142146
return paths.normalize(ctx.workspace_name + "/" + rootpath)

scala/private/rule_impls.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
load("@bazel_skylib//lib:paths.bzl", "paths")
1717
load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_toolchain")
18-
load(":common.bzl", "rpathlocation_from_rootpath", _collect_plugin_paths = "collect_plugin_paths")
18+
load(":common.bzl", "rlocationpath_from_rootpath", _collect_plugin_paths = "collect_plugin_paths")
1919
load(":resources.bzl", _resource_paths = "paths")
2020

2121
def expand_location(ctx, flags):
@@ -213,7 +213,7 @@ def java_bin_windows(ctx):
213213
if paths.is_absolute(java_runtime.java_executable_runfiles_path):
214214
java_bin = java_runtime.java_executable_runfiles_path
215215
else:
216-
java_bin = rpathlocation_from_rootpath(ctx, java_runtime.java_executable_runfiles_path)
216+
java_bin = rlocationpath_from_rootpath(ctx, java_runtime.java_executable_runfiles_path)
217217

218218
return java_bin
219219

src/java/io/bazel/rulesscala/exe/LauncherFileWriter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public static void main(String[] args) throws IOException {
3131
.addKeyValuePair("binary_type", "Java")
3232
.addKeyValuePair("workspace_name", workspaceName)
3333
.addKeyValuePair("symlink_runfiles_enabled", "0")
34-
.addKeyValuePair("java_bin_path", javaBinPath.replace("\\", "/")) //Expects rpathlocation (i.e. with prepended repo name)
35-
.addKeyValuePair("jar_bin_path", rpathlocation_to_rootpath( workspaceName, jarBinPath)) //Expects rootpath location
34+
.addKeyValuePair("java_bin_path", javaBinPath.replace("\\", "/")) //Expects rlocationpath (i.e. with prepended repo name)
35+
.addKeyValuePair("jar_bin_path", rlocationpath_to_rootpath( workspaceName, jarBinPath)) //Expects rootpath location
3636
.addKeyValuePair("java_start_class", javaStartClass)
3737
.addKeyValuePair("classpath", classpath) //Expects rootpath location
3838
.addJoinedValues("jvm_flags", "\t", jvmFlags)
@@ -56,9 +56,9 @@ public static void main(String[] args) throws IOException {
5656
}
5757
}
5858

59-
//Bazel's java_launcher expects some fields(i.e. jar_bin_path and classpaths) to be rootpath. rpathlocation is relative to runfiledir (always prefix with repo). Rootpath is relative to runfiledir/workspacename.
60-
static String rpathlocation_to_rootpath(String workspaceName, String rpathlocation){
61-
Path path = Paths.get(rpathlocation);
59+
//Bazel's java_launcher expects some fields(i.e. jar_bin_path and classpaths) to be rootpath. rlocationpath is relative to runfiledir (always prefix with repo). Rootpath is relative to runfiledir/workspacename.
60+
static String rlocationpath_to_rootpath(String workspaceName, String rlocationpath){
61+
Path path = Paths.get(rlocationpath);
6262

6363
Path result;
6464
if(!path.startsWith(workspaceName)){

0 commit comments

Comments
 (0)