Skip to content

Commit

Permalink
fix: support acceptance_tests on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
  • Loading branch information
f0rmiga committed Mar 4, 2022
1 parent 9549c4a commit 2258d33
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions python/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ platform-specific repositories.

load(
"//python:versions.bzl",
"PLATFORMS",
"MACOS_NAME",
"LINUX_NAME",
"MACOS_NAME",
"PLATFORMS",
"WINDOWS_NAME",
)

Expand Down
53 changes: 33 additions & 20 deletions python/tests/toolchains/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,50 @@ def _acceptance_test_impl(ctx):
if not interpreter_path:
interpreter_path = py3_runtime.interpreter.short_path

executable = ctx.actions.declare_file("run_test_{}.sh".format(ctx.attr.python_version))
ctx.actions.write(
output = executable,
content = """\
#!/bin/bash
exec "{interpreter_path}" "{run_acceptance_test_py}"
""".format(
interpreter_path = interpreter_path,
run_acceptance_test_py = run_acceptance_test_py.short_path,
),
is_executable = True,
)
if ctx.attr.is_windows:
executable = ctx.actions.declare_file("run_test_{}.bat".format(ctx.attr.python_version))
ctx.actions.write(
output = executable,
content = "{interpreter_path} {run_acceptance_test_py}".format(
interpreter_path = interpreter_path.replace("/", "\\"),
run_acceptance_test_py = run_acceptance_test_py.short_path.replace("/", "\\"),
),
is_executable = True,
)
else:
executable = ctx.actions.declare_file("run_test_{}.sh".format(ctx.attr.python_version))
ctx.actions.write(
output = executable,
content = "exec '{interpreter_path}' '{run_acceptance_test_py}'".format(
interpreter_path = interpreter_path,
run_acceptance_test_py = run_acceptance_test_py.short_path,
),
is_executable = True,
)

files = [
build_bazel,
executable,
python_version_test,
run_acceptance_test_py,
workspace,
] + py3_runtime.files.to_list()
return [DefaultInfo(
executable = executable,
files = depset(files),
runfiles = ctx.runfiles(files),
runfiles = ctx.runfiles(
files = files,
collect_data = True,
collect_default = True,
),
)]

_acceptance_test = rule(
_acceptance_test_impl,
attrs = {
"python_version": attr.string(
mandatory = True,
),
"test_location": attr.string(
mandatory = True,
),
"is_windows": attr.bool(mandatory = True),
"python_version": attr.string(mandatory = True),
"test_location": attr.string(mandatory = True),
"_build_bazel_tmpl": attr.label(
allow_single_file = True,
default = "//python/tests/toolchains/workspace_template:BUILD.bazel.tmpl",
Expand All @@ -115,6 +124,10 @@ _acceptance_test = rule(

def acceptance_test(python_version, **kwargs):
_acceptance_test(
is_windows = select({
"@bazel_tools//src/conditions:host_windows": True,
"//conditions:default": False,
}),
python_version = python_version,
test_location = native.package_name(),
**kwargs
Expand Down

0 comments on commit 2258d33

Please sign in to comment.