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

feat: multi-toolchain support #846

Merged
merged 38 commits into from
Nov 28, 2022
Merged
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5d004e0
feat: multi-toolchain support
f0rmiga Oct 3, 2022
ecc3ba9
feat: cross-version testing
f0rmiga Oct 3, 2022
ae419f2
fix: error message
f0rmiga Oct 3, 2022
4d79a84
doc: add link to bazelbuild/bazel PR fixing expand_location
f0rmiga Oct 4, 2022
3441145
fix: set environment variables for py_binary too
f0rmiga Oct 4, 2022
44d6cb4
test: extra case for default version taking another version
f0rmiga Oct 4, 2022
557848a
fix: fail if args attribute is set
f0rmiga Oct 4, 2022
5755c01
fix: remove confusing output with same target name
f0rmiga Oct 4, 2022
cbe5a11
fix: buildifier
f0rmiga Oct 4, 2022
30e520d
revert: use testing.TestEnvironment
f0rmiga Oct 5, 2022
9eb0f3b
fix: linting issues
f0rmiga Oct 5, 2022
3891e54
fix: black linter
f0rmiga Oct 5, 2022
3f65659
refactor: move tests to a sub-dir
f0rmiga Oct 5, 2022
0ec1d4f
feat: add multi_pip_parse
f0rmiga Oct 7, 2022
c412a2e
fix: add missing aliases
f0rmiga Oct 7, 2022
32fa462
fix: use requirement function in example
f0rmiga Oct 7, 2022
17b0ba1
fix: deleted packages
f0rmiga Oct 7, 2022
835d25f
fix: update generated docs
f0rmiga Oct 7, 2022
75ad960
refactor: version checking of the rule is already done by other tests
f0rmiga Oct 7, 2022
ffe07ac
fix: add python_interpreter_target to multi_pip_parse
f0rmiga Oct 11, 2022
8bc79c1
fix: windows
f0rmiga Oct 12, 2022
174663a
refactor: unify py_test and py_binary transition impls
f0rmiga Oct 12, 2022
519f762
fix: test compatible with all platforms
f0rmiga Oct 12, 2022
059aa98
rebase: adjust multi_python_versions on ci
f0rmiga Oct 12, 2022
1053ab0
refactor: use usr flags instead of platforms in transition
f0rmiga Nov 18, 2022
d813740
refactor: rename rule -> rule_impl
f0rmiga Nov 21, 2022
161f068
refactor: reduce repetition of args
f0rmiga Nov 21, 2022
66b33f3
fix: missing test and binary-specific attributes
f0rmiga Nov 21, 2022
cecb3c8
fix: add srcs and deps attrs for path expansion
f0rmiga Nov 21, 2022
90e3314
Merge remote-tracking branch 'origin/main' into f0rmiga/multi-python-…
f0rmiga Nov 22, 2022
562ee9b
fix: missing bazel_skylib on integration tests
f0rmiga Nov 22, 2022
ca49f8b
refactor: use ctx.target_platform_has_constraint over select
f0rmiga Nov 28, 2022
906bb6a
doc: why symlink <name>.zip under Windows
f0rmiga Nov 28, 2022
3316928
fix: apply suggestions from code review
f0rmiga Nov 28, 2022
9c833f1
fix: use incoming edge transitions
f0rmiga Nov 28, 2022
aa0fc9f
fix: use RunEnvironmentInfo when available
f0rmiga Nov 28, 2022
070ec92
Merge remote-tracking branch 'origin/main' into f0rmiga/multi-python-…
f0rmiga Nov 28, 2022
6896f15
fix: cfg should be target not exec
f0rmiga Nov 28, 2022
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
36 changes: 22 additions & 14 deletions python/config_settings/transition.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ _transition_python_version = transition(
)

def _transition_py_impl(ctx):
target = ctx.attr.target[0]
executable = ctx.actions.declare_file(ctx.attr.name + (".exe" if ctx.attr.is_windows else ""))
target = ctx.attr.target
windows_constraint = ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]
target_is_windows = ctx.target_platform_has_constraint(windows_constraint)
executable = ctx.actions.declare_file(ctx.attr.name + (".exe" if target_is_windows else ""))
ctx.actions.symlink(
is_executable = True,
output = executable,
target_file = target[DefaultInfo].files_to_run.executable,
)
zipfile_symlink = None
if ctx.attr.is_windows:
if target_is_windows:
# Under Windows, the expected "<name>.zip" does not exist, so we have to
# create the symlink ourselves to achieve the same behaviour as in macOS
# and Linux.
zipfile = None
expected_target_path = target[DefaultInfo].files_to_run.executable.short_path[:-4] + ".zip"
for file in target[DefaultInfo].default_runfiles.files.to_list():
Expand All @@ -38,6 +43,7 @@ def _transition_py_impl(ctx):
env = {}
for k, v in ctx.attr.env.items():
env[k] = ctx.expand_location(v)

providers = [
DefaultInfo(
executable = executable,
Expand All @@ -46,12 +52,16 @@ def _transition_py_impl(ctx):
),
target[PyInfo],
target[PyRuntimeInfo],
target[InstrumentedFilesInfo],
# Ensure that the binary we're wrapping is included in code coverage.
coverage_common.instrumented_files_info(
ctx,
dependency_attributes = ["target"],
),
target[OutputGroupInfo],
# TODO(f0rmiga): testing.TestEnvironment is deprecated in favour of RunEnvironmentInfo but
# testing.TestEnvironment is deprecated in favour of RunEnvironmentInfo but
# RunEnvironmentInfo is not exposed in Bazel < 5.3.
# https://github.com/bazelbuild/bazel/commit/dbdfa07e92f99497be9c14265611ad2920161483
testing.TestEnvironment(environment = env),
(RunEnvironmentInfo if hasattr(native, "RunEnvironmentInfo") else testing.TestEnvironment)(environment = env),
]
return providers

Expand All @@ -62,9 +72,6 @@ _COMMON_ATTRS = {
"env": attr.string_dict(
mandatory = False,
),
"is_windows": attr.bool(
mandatory = True,
),
"python_version": attr.string(
mandatory = True,
),
Expand All @@ -74,7 +81,7 @@ _COMMON_ATTRS = {
),
"target": attr.label(
executable = True,
cfg = _transition_python_version,
cfg = "exec",
f0rmiga marked this conversation as resolved.
Show resolved Hide resolved
mandatory = True,
providers = [PyInfo],
),
Expand All @@ -96,17 +103,22 @@ _COMMON_ATTRS = {
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"_windows_constraint": attr.label(
default = "@platforms//os:windows",
),
}

_transition_py_binary = rule(
_transition_py_impl,
attrs = _COMMON_ATTRS,
cfg = _transition_python_version,
executable = True,
)

_transition_py_test = rule(
_transition_py_impl,
attrs = _COMMON_ATTRS,
cfg = _transition_python_version,
test = True,
)

Expand Down Expand Up @@ -180,10 +192,6 @@ def _py_rule(rule_impl, transition_rule, name, python_version, **kwargs):
args = args,
deps = deps,
env = env,
is_windows = select({
"@platforms//os:windows": True,
"//conditions:default": False,
}),
python_version = python_version,
srcs = srcs,
tags = tags,
Expand Down