Skip to content

Commit f76e97b

Browse files
gregmagolanalexeagle
authored andcommitted
fix(protractor): update rules_webtesting patch to include additional windows fixes (bazel-contrib#1140)
Cannot update to latest rules_webtesting commit as we need to depend on the release package which does not have a rules_go dependency. This patch can be removed once we update to the next rules_webtesting release.
1 parent 0c165b7 commit f76e97b

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

rules_webtesting.patch

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,161 @@ index 384d018..2cbbb4a 100644
1111
},
1212
}),
1313
visibility = ["//browsers:__subpackages__"],
14+
--
15+
2.20.1
16+
17+
From a7c1f6b825640a95e687adc884a442fde23ccd95 Mon Sep 17 00:00:00 2001
18+
From: Yun Peng <pcloudy@google.com>
19+
Date: Tue, 3 Sep 2019 19:24:02 +0200
20+
Subject: [PATCH] Update rlocation funciton in windows_utils.bzl (#387)
21+
22+
---
23+
web/internal/windows_utils.bzl | 76 ++++++++++++++++++++++++++--------
24+
1 file changed, 59 insertions(+), 17 deletions(-)
25+
26+
diff --git a/web/internal/windows_utils.bzl b/web/internal/windows_utils.bzl
27+
index 429a01a..576053a 100644
28+
--- a/web/internal/windows_utils.bzl
29+
+++ b/web/internal/windows_utils.bzl
30+
@@ -17,6 +17,49 @@
31+
These functions help making rules work on Windows.
32+
"""
33+
34+
+BATCH_RLOCATION_FUNCTION = r"""
35+
+rem Usage of rlocation function:
36+
+rem call :rlocation <runfile_path> <abs_path>
37+
+rem The rlocation function maps the given <runfile_path> to its absolute
38+
+rem path and stores the result in a variable named <abs_path>.
39+
+rem This function fails if the <runfile_path> doesn't exist in mainifest
40+
+rem file.
41+
+:: Start of rlocation
42+
+goto :rlocation_end
43+
+:rlocation
44+
+if "%~2" equ "" (
45+
+ echo>&2 ERROR: Expected two arguments for rlocation function.
46+
+ exit 1
47+
+)
48+
+if "%RUNFILES_MANIFEST_ONLY%" neq "1" (
49+
+ set %~2=%~1
50+
+ exit /b 0
51+
+)
52+
+if "%RUNFILES_MANIFEST_FILE%" equ "" (
53+
+ set RUNFILES_MANIFEST_FILE=%~f0.runfiles\MANIFEST
54+
+)
55+
+if not exist "%RUNFILES_MANIFEST_FILE%" (
56+
+ set RUNFILES_MANIFEST_FILE=%~f0.runfiles_manifest
57+
+)
58+
+set MF=%RUNFILES_MANIFEST_FILE:/=\%
59+
+if not exist "%MF%" (
60+
+ echo>&2 ERROR: Manifest file %MF% does not exist.
61+
+ exit 1
62+
+)
63+
+set runfile_path=%~1
64+
+for /F "tokens=2* usebackq" %%i in (`%SYSTEMROOT%\system32\findstr.exe /l /c:"!runfile_path! " "%MF%"`) do (
65+
+ set abs_path=%%i
66+
+)
67+
+if "!abs_path!" equ "" (
68+
+ echo>&2 ERROR: !runfile_path! not found in runfiles manifest
69+
+ exit 1
70+
+)
71+
+set %~2=!abs_path!
72+
+exit /b 0
73+
+:rlocation_end
74+
+:: End of rlocation
75+
+"""
76+
+
77+
def is_windows(ctx):
78+
"""
79+
Check if we are building for Windows.
80+
@@ -27,6 +70,14 @@ def is_windows(ctx):
81+
# https://github.com/bazelbuild/bazel/issues/9209 is resolved.
82+
return ctx.configuration.host_path_separator == ";"
83+
84+
+# Helper function to convert a file to a path in the MANIFEST file
85+
+def _file_to_manifest_path(ctx, f):
86+
+ p = f.short_path
87+
+ if p.startswith("../"):
88+
+ return p[3:]
89+
+ else:
90+
+ return ctx.workspace_name + "/" + p
91+
+
92+
def create_windows_native_launcher_script(ctx, shell_script):
93+
"""
94+
Create a Windows Batch file to launch the given shell script.
95+
@@ -41,25 +92,16 @@ def create_windows_native_launcher_script(ctx, shell_script):
96+
content = r"""@echo off
97+
SETLOCAL ENABLEEXTENSIONS
98+
SETLOCAL ENABLEDELAYEDEXPANSION
99+
-if "%RUNFILES_MANIFEST_ONLY%" neq "1" (
100+
- set run_script={sh_script}
101+
- goto :run
102+
-)
103+
-set MF=%RUNFILES_MANIFEST_FILE:/=\%
104+
-set script={sh_script}
105+
-if "!script:~0,9!" equ "external/" (set script=!script:~9!) else (set script=!TEST_WORKSPACE!/!script!)
106+
-for /F "tokens=2* usebackq" %%i in (`findstr.exe /l /c:"!script! " "%MF%"`) do (
107+
- set run_script=%%i
108+
-)
109+
-if "!run_script!" equ "" (
110+
- echo>&2 ERROR: !script! not found in runfiles manifest
111+
- exit /b 1
112+
-)
113+
-:run
114+
-{bash_bin} -c "!run_script!"
115+
+set RUNFILES_MANIFEST_ONLY=1
116+
+{rlocation_function}
117+
+call :rlocation "{sh_script}" run_script
118+
+for %%a in ("{bash_bin}") do set "bash_bin_dir=%%~dpa"
119+
+set PATH=%bash_bin_dir%;%PATH%
120+
+{bash_bin} -c "!run_script! %*"
121+
""".format(
122+
bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path,
123+
- sh_script = shell_script.short_path,
124+
+ sh_script = _file_to_manifest_path(ctx, shell_script),
125+
+ rlocation_function = BATCH_RLOCATION_FUNCTION,
126+
),
127+
is_executable = True,
128+
)
129+
--
130+
2.20.1
131+
132+
From 9c1e6ce41e458f41654fe609d76220770562c9b4 Mon Sep 17 00:00:00 2001
133+
From: Paul Gschwendtner <paulgschwendtner@gmail.com>
134+
Date: Mon, 9 Sep 2019 20:43:49 +0200
135+
Subject: [PATCH] web test not launching on windows if shell toolchain path
136+
contains whitespace (#389)
137+
138+
The windows launcher code does currently break if the path to the bash binary contains
139+
a whitespace. This is common on windows where programs are stored under `C:\Program Files`.
140+
141+
e.g.
142+
143+
```
144+
:run
145+
C:/Program Files/msys2/usr/bin/bash.exe -c "!run_script!"
146+
```
147+
148+
The path needs to be quoted so that it won't be incorrectly picked up as two separate commands. Resulting in an
149+
exception like:
150+
151+
```
152+
'C:/Program' is not recognized as an internal or external command,
153+
operable program or batch file.
154+
```
155+
---
156+
web/internal/windows_utils.bzl | 2 +-
157+
1 file changed, 1 insertion(+), 1 deletion(-)
158+
159+
diff --git a/web/internal/windows_utils.bzl b/web/internal/windows_utils.bzl
160+
index 576053a..4bec20e 100644
161+
--- a/web/internal/windows_utils.bzl
162+
+++ b/web/internal/windows_utils.bzl
163+
@@ -97,7 +97,7 @@ set RUNFILES_MANIFEST_ONLY=1
164+
call :rlocation "{sh_script}" run_script
165+
for %%a in ("{bash_bin}") do set "bash_bin_dir=%%~dpa"
166+
set PATH=%bash_bin_dir%;%PATH%
167+
-{bash_bin} -c "!run_script! %*"
168+
+"{bash_bin}" -c "!run_script! %*"
169+
""".format(
170+
bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path,
171+
sh_script = _file_to_manifest_path(ctx, shell_script),

0 commit comments

Comments
 (0)