Skip to content

Commit 2ee2311

Browse files
committed
move implementation to //python/private
1 parent c71629f commit 2ee2311

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

python/bin/interpreter.bzl

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
load("@bazel_skylib//lib:paths.bzl", "paths")
2-
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
3-
load("//python:py_runtime_info.bzl", "PyRuntimeInfo")
4-
load("//python/private:sentinel.bzl", "SentinelInfo")
5-
load("//python/private:toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE")
1+
load("//python/private:interpreter.bzl", _interpeter="interpreter")
62

7-
def _interpreter_impl(ctx):
8-
if SentinelInfo in ctx.attr.binary:
9-
toolchain = ctx.toolchains[TARGET_TOOLCHAIN_TYPE]
10-
runtime = toolchain.py3_runtime
11-
else:
12-
runtime = ctx.attr.binary[PyRuntimeInfo]
13-
14-
# NOTE: We name the output filename after the underlying file name
15-
# because of things like pyenv: they use $0 to determine what to
16-
# re-exec. If it's not a recognized name, then they fail.
17-
if runtime.interpreter:
18-
executable = ctx.actions.declare_file(runtime.interpreter.basename)
19-
ctx.actions.symlink(output = executable, target_file = runtime.interpreter, is_executable = True)
20-
else:
21-
executable = ctx.actions.declare_symlink(paths.basename(runtime.interpreter_path))
22-
ctx.actions.symlink(output = executable, target_path = runtime.interpreter_path)
23-
24-
return [
25-
DefaultInfo(
26-
executable = executable,
27-
runfiles = ctx.runfiles([executable], transitive_files = runtime.files),
28-
),
29-
]
30-
31-
interpreter = rule(
32-
implementation = _interpreter_impl,
33-
toolchains = [TARGET_TOOLCHAIN_TYPE],
34-
executable = True,
35-
attrs = {
36-
"binary": attr.label(
37-
mandatory = True,
38-
),
39-
},
40-
)
3+
interpreter = _interpeter

python/private/interpreter.bzl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
load("@bazel_skylib//lib:paths.bzl", "paths")
2+
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
3+
load("//python:py_runtime_info.bzl", "PyRuntimeInfo")
4+
load(":sentinel.bzl", "SentinelInfo")
5+
load(":toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE")
6+
7+
def _interpreter_impl(ctx):
8+
if SentinelInfo in ctx.attr.binary:
9+
toolchain = ctx.toolchains[TARGET_TOOLCHAIN_TYPE]
10+
runtime = toolchain.py3_runtime
11+
else:
12+
runtime = ctx.attr.binary[PyRuntimeInfo]
13+
14+
# NOTE: We name the output filename after the underlying file name
15+
# because of things like pyenv: they use $0 to determine what to
16+
# re-exec. If it's not a recognized name, then they fail.
17+
if runtime.interpreter:
18+
executable = ctx.actions.declare_file(runtime.interpreter.basename)
19+
ctx.actions.symlink(output = executable, target_file = runtime.interpreter, is_executable = True)
20+
else:
21+
executable = ctx.actions.declare_symlink(paths.basename(runtime.interpreter_path))
22+
ctx.actions.symlink(output = executable, target_path = runtime.interpreter_path)
23+
24+
return [
25+
DefaultInfo(
26+
executable = executable,
27+
runfiles = ctx.runfiles([executable], transitive_files = runtime.files),
28+
),
29+
]
30+
31+
interpreter = rule(
32+
implementation = _interpreter_impl,
33+
toolchains = [TARGET_TOOLCHAIN_TYPE],
34+
executable = True,
35+
attrs = {
36+
"binary": attr.label(
37+
mandatory = True,
38+
),
39+
},
40+
)

0 commit comments

Comments
 (0)