@@ -52,11 +52,6 @@ case "$(uname -s | tr [:upper:] [:lower:])" in
52
52
msys* )
53
53
# As of 2018-08-14, Bazel on Windows only supports MSYS Bash.
54
54
declare -r is_windows=true
55
- # As of 2019-05-18, this test is disabled on Windows (via "no_windows" tag),
56
- # so this code shouldn't even have run.
57
- # TODO(#7844): Enable this test for Windows once our autodetecting toolchain
58
- # works transparently for this platform.
59
- fail " This test does not run on Windows."
60
55
;;
61
56
* )
62
57
declare -r is_windows=false
72
67
73
68
# ### TESTS #############################################################
74
69
75
- # Sanity test that our environment setup above works.
70
+ # Sanity test that our environment setup works.
76
71
function test_can_run_py_binaries() {
77
72
mkdir -p test
78
73
@@ -94,7 +89,6 @@ import platform
94
89
print("I am Python " + platform.python_version_tuple()[0])
95
90
EOF
96
91
cp test/main2.py test/main3.py
97
- chmod u+x test/main2.py test/main3.py
98
92
99
93
bazel run //test:main2 \
100
94
& > $TEST_log || fail " bazel run failed"
@@ -142,18 +136,23 @@ EOF
142
136
}
143
137
144
138
# Regression test for #5104. This test ensures that it's possible to use
145
- # --build_python_zip in combination with a py_runtime (as opposed to not using
146
- # a py_runtime, i.e., the legacy --python_path mechanism).
147
- #
148
- # Note that with --incompatible_use_python_toolchains flipped, we're always
149
- # using a py_runtime, so in that case this amounts to a test that
150
- # --build_python_zip works at all.
139
+ # --build_python_zip in combination with an in-workspace runtime, as opposed to
140
+ # with a system runtime or not using a py_runtime at all (the legacy
141
+ # --python_path mechanism).
151
142
#
152
143
# The specific issue #5104 was caused by file permissions being lost when
153
144
# unzipping runfiles, which led to an unexecutable runtime.
154
- function test_build_python_zip_works_with_py_runtime () {
145
+ function test_build_python_zip_works_with_workspace_runtime () {
155
146
mkdir -p test
156
147
148
+ # The runfiles interpreter is either a sh script or bat script depending on
149
+ # the current platform.
150
+ if " $is_windows " ; then
151
+ INTERPRETER_FILE=" mockpy.bat"
152
+ else
153
+ INTERPRETER_FILE=" mockpy.sh"
154
+ fi
155
+
157
156
cat > test/BUILD << EOF
158
157
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
159
158
@@ -164,7 +163,7 @@ py_binary(
164
163
165
164
py_runtime(
166
165
name = "mock_runtime",
167
- interpreter = ":mockpy.sh ",
166
+ interpreter = ":$INTERPRETER_FILE ",
168
167
python_version = "PY3",
169
168
)
170
169
@@ -184,11 +183,17 @@ EOF
184
183
# executes the Python code.
185
184
print("I am pybin!")
186
185
EOF
187
- cat > test/mockpy.sh << EOF
188
- #!/bin/bash
186
+ if " $is_windows " ; then
187
+ cat > " test/$INTERPRETER_FILE " << EOF
188
+ @ECHO I am mockpy!
189
+ EOF
190
+ else
191
+ cat > " test/$INTERPRETER_FILE " << EOF
192
+ #!/bin/sh
189
193
echo "I am mockpy!"
190
194
EOF
191
- chmod u+x test/mockpy.sh
195
+ chmod u+x test/mockpy.sh
196
+ fi
192
197
193
198
bazel run //test:pybin \
194
199
--extra_toolchains=//test:mock_toolchain --build_python_zip \
197
202
}
198
203
199
204
function test_pybin_can_have_different_version_pybin_as_data_dep() {
205
+ # TODO(#8503): Fix this test for windows.
206
+ if " $is_windows " ; then
207
+ return
208
+ fi
209
+
200
210
mkdir -p test
201
211
202
212
cat > test/BUILD << EOF
@@ -231,22 +241,22 @@ import platform
231
241
232
242
print("Inner bin uses Python " + platform.python_version_tuple()[0])
233
243
EOF
234
- chmod u+x test/py2bin.py
235
244
cp test/py2bin.py test/py3bin.py
236
245
237
246
cat > test/py2bin_calling_py3bin.py << EOF
238
247
import platform
239
248
import subprocess
240
249
from bazel_tools.tools.python.runfiles import runfiles
241
250
251
+ print("Outer bin uses Python " + platform.python_version_tuple()[0])
252
+
242
253
r = runfiles.Create()
243
254
bin_path = r.Rlocation("$WORKSPACE_NAME /test/py3bin")
255
+ assert bin_path is not None
244
256
245
- print("Outer bin uses Python " + platform.python_version_tuple()[0])
246
257
subprocess.call([bin_path])
247
258
EOF
248
259
sed s/py3bin/py2bin/ test/py2bin_calling_py3bin.py > test/py3bin_calling_py2bin.py
249
- chmod u+x test/py2bin_calling_py3bin.py test/py3bin_calling_py2bin.py
250
260
251
261
EXPFLAG=" --incompatible_allow_python_version_transitions=true \
252
262
--incompatible_py3_is_default=false \
267
277
}
268
278
269
279
function test_shbin_can_have_different_version_pybins_as_data_deps() {
280
+ # Uses bash, disable on windows.
281
+ if " $is_windows " ; then
282
+ return
283
+ fi
284
+
270
285
mkdir -p test
271
286
272
287
cat > test/BUILD << EOF
394
409
}
395
410
396
411
function test_can_build_same_target_for_both_versions_in_one_build() {
412
+ # Uses bash, disable on windows.
413
+ if " $is_windows " ; then
414
+ return
415
+ fi
416
+
397
417
mkdir -p test
398
418
399
419
cat > test/BUILD << EOF
0 commit comments