Skip to content

Commit db6a180

Browse files
authored
test: make venv_tree transition to linux (#1308)
### Changes are visible to end-users: no ### Test plan - Covered by existing test cases - Manual testing; run on macos
1 parent 583a2c1 commit db6a180

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

py/private/py_venv/py_venv.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def _common_providers(ctx, shared, executable = None):
117117
bin_python = shared.venv.bin_python,
118118
imports = shared.imports_depset,
119119
transitive_sources = shared.srcs_depset,
120-
all_files = depset(direct = shared.venv.all_files),
121120
),
122121
# `bazel coverage` finds this by walking the consumer's `venv` attr.
123122
coverage_common.instrumented_files_info(

py/private/py_venv/tests/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ genrule(
3737
tools = [":venv"],
3838
)
3939

40+
# venv_tree pins the snapshot here so every host regenerates identical bytes.
41+
platform(
42+
name = "snapshot_platform",
43+
constraint_values = [
44+
"@platforms//os:linux",
45+
"@platforms//cpu:x86_64",
46+
],
47+
)
48+
4049
venv_tree(
4150
name = "venv_tree_snap",
4251
testonly = True,

py/private/py_venv/tests/venv_tree.bzl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@ Produces a deterministic text file listing every symlink (with target)
44
and text file (with content) inside a ``py_venv`` target's output tree.
55
Used via ``write_source_files`` so changes to the venv assembly surface
66
as a reviewable diff.
7+
8+
The venv is transitioned to a fixed platform so interpreter repo names
9+
and pyvenv.cfg contents are identical on every host.
710
"""
811

912
load("//py/private/py_venv:defs.bzl", "VirtualenvInfo")
1013

14+
def _snapshot_platform_transition_impl(_settings, _attr):
15+
return {
16+
"//command_line_option:platforms": "//py/private/py_venv/tests:snapshot_platform",
17+
}
18+
19+
_snapshot_platform_transition = transition(
20+
implementation = _snapshot_platform_transition_impl,
21+
inputs = [],
22+
outputs = ["//command_line_option:platforms"],
23+
)
24+
1125
def _venv_tree_impl(ctx):
1226
output = ctx.actions.declare_file(ctx.label.name + ".snap")
13-
bin_python = ctx.attr.venv[VirtualenvInfo].bin_python
27+
venv = ctx.attr.venv[0]
28+
bin_python = venv[VirtualenvInfo].bin_python
1429
ctx.actions.run_shell(
15-
inputs = ctx.attr.venv[VirtualenvInfo].all_files,
30+
inputs = venv[DefaultInfo].default_runfiles.files,
1631
outputs = [output],
1732
arguments = [output.path, bin_python.path],
1833
command = r"""
@@ -56,7 +71,11 @@ venv_tree = rule(
5671
"venv": attr.label(
5772
providers = [VirtualenvInfo],
5873
mandatory = True,
74+
cfg = _snapshot_platform_transition,
5975
doc = "A `py_venv` target whose venv tree to snapshot.",
6076
),
77+
"_allowlist_function_transition": attr.label(
78+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
79+
),
6180
},
6281
)

py/private/py_venv/types.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ binary's launcher exec's the venv's `bin_python`.
1818
"bin_python": "File — the venv's bin/python symlink. Callers needing a launcher target point here.",
1919
"imports": "depset[str] — rlocation-root-relative import paths covered by this venv. Mirrors `PyInfo.imports` of the venv's dep closure.",
2020
"transitive_sources": "depset[File] — first-party Python sources carried by this venv (its own `srcs` plus those of any `deps` that emit `PyInfo`). Surfaced by py_binary as `PyInfo.transitive_sources` so downstream consumers see the same source closure they'd see if srcs/deps lived on the binary directly.",
21-
"all_files": "depset[File] — every file and symlink declared by `assemble_venv`, for snapshot/test consumers that need the full venv output set.",
2221
},
2322
)

0 commit comments

Comments
 (0)