Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export LOCALAPPDATA="$TEST_TMPDIR"

cd examples/$1

if [[ -n "$WINDIR" ]] && ! grep -q "^startup --windows_enable_symlinks$" .bazelrc; then
if [[ -n "$WINDIR" ]] && ! grep -qE "^startup --(no)?windows_enable_symlinks$" .bazelrc; then
echo "Skip $1 test on Windows"
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
startup --windows_enable_symlinks
startup --nowindows_enable_symlinks
build --sandbox_default_allow_network=false
build --nolegacy_external_runfiles
build --incompatible_default_to_explicit_init_py
Expand Down
2 changes: 1 addition & 1 deletion examples/transitions/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
startup --windows_enable_symlinks
startup --nowindows_enable_symlinks
build --sandbox_default_allow_network=false
build --nolegacy_external_runfiles
build --incompatible_default_to_explicit_init_py
Expand Down
29 changes: 25 additions & 4 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,33 @@ def _internal_definitions_repo_impl(rctx):
python_host_path = python_host_path.dirname
if not [path for path in python_host_path.readdir() if path.basename in ["BUILD", "BUILD.bazel"]]:
fail("can not find build file for {} at {}".format(rctx.attr.python_host, rctx.os.name))
if rctx.os.name.startswith("windows") and rctx.attr.python_host.workspace_name in python_host_path.basename:
fail("on windows use 'startup --windows_enable_symlinks' to link real Python toolchain path")

for target in python_host_path.readdir():
rctx.symlink(target, target.basename)
if rctx.attr.python_host.workspace_name in python_host_path.basename:
# If symbolic links are disabled than resolved Python host path basename should not change.
# In this case create a BUILD file with a generic py3_runtime target.

rctx.file("BUILD.bazel", """{banner}

load("@rules_python//python:py_runtime.bzl", "py_runtime")

py_runtime(
name = "py3_runtime",
interpreter = "{python}",
visibility = ["//visibility:public"],
)

""".format(
banner = banner,
python = str(rctx.attr.python_host),
))
else:
# If symbolic links are enabled than resolved Python host path basename should point to Python toolchain.
# Create first-level symbolic links into the current repository together with the BUILD file which containes.
# Python toolchain with py3_runtime runtime definition.
for target in python_host_path.readdir():
rctx.symlink(target, target.basename)

# Create defs.bzl file with resolved variables
rctx.file("defs.bzl", """{banner}

python_host = "{python_host}"
Expand Down
Loading