Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An attempt to run Python exe in a more hermetic way #863

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 14 additions & 3 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ def _python_repository_impl(rctx):
"share/**",
]

python_wrapper = "python_wrapper.sh"
python_wrapper_content = """\
#!/bin/bash

set -o errexit -o nounset -o pipefail

external/{repo_name}/{python_bin} -B -s "$@"
""".format(repo_name = rctx.name, python_bin = python_bin)
rctx.file(python_wrapper, python_wrapper_content, executable = True)

build_content = """\
# Generated by python/repositories.bzl

Expand Down Expand Up @@ -235,8 +245,8 @@ exports_files(["python", "{python_path}"])

py_runtime(
name = "py3_runtime",
files = [":files"],
interpreter = "{python_path}",
files = [":files", "{python_wrapper}"],
interpreter = "{python_wrapper}",
python_version = "PY3",
)

Expand All @@ -248,10 +258,11 @@ py_runtime_pair(
""".format(
glob_include = repr(glob_include),
python_path = python_bin,
python_wrapper = python_wrapper,
python_version = python_short_version,
)
rctx.delete("python")
rctx.symlink(python_bin, "python")
rctx.symlink(python_wrapper, "python")
rctx.file(STANDALONE_INTERPRETER_FILENAME, "# File intentionally left blank. Indicates that this is an interpreter repo created by rules_python.")
rctx.file("BUILD.bazel", build_content)

Expand Down