-
-
Notifications
You must be signed in to change notification settings - Fork 634
tests: make toolchain tests run in the same build instead of bazel-in-bazel integration tests #2095
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
Merged
rickeylev
merged 5 commits into
bazel-contrib:main
from
rickeylev:refactor.same.build.toolchain.tests
Aug 1, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0e85b6
wip: making toolchain tests be in-build, not bazel-in-bazel tests
rickeylev bf00aaf
fix extra calls being treated as default=true
rickeylev 2edb20a
fixup! fix extra calls being treated as default=true
rickeylev 8e6ed8e
skip toolchains+platform combos that dont exist
rickeylev c51d0df
fixup! skip toolchains+platform combos that dont exist
rickeylev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
load("@bazel_features//:features.bzl", "bazel_features") | ||
load("//python:repositories.bzl", "python_register_toolchains") | ||
load("//python:versions.bzl", "TOOL_VERSIONS") | ||
load(":pythons_hub.bzl", "hub_repo") | ||
load(":text_util.bzl", "render") | ||
load(":toolchains_repo.bzl", "multi_toolchain_aliases") | ||
|
@@ -78,7 +79,9 @@ def _python_impl(module_ctx): | |
for mod in module_ctx.modules: | ||
module_toolchain_versions = [] | ||
|
||
for toolchain_attr in mod.tags.toolchain: | ||
toolchain_attr_structs = _create_toolchain_attr_structs(mod) | ||
|
||
for toolchain_attr in toolchain_attr_structs: | ||
toolchain_version = toolchain_attr.python_version | ||
toolchain_name = "python_" + toolchain_version.replace(".", "_") | ||
|
||
|
@@ -95,9 +98,7 @@ def _python_impl(module_ctx): | |
# * rules_python needs to set a soft default in case the root module doesn't, | ||
# e.g. if the root module doesn't use Python itself. | ||
# * The root module is allowed to override the rules_python default. | ||
|
||
# A single toolchain is treated as the default because it's unambiguous. | ||
is_default = toolchain_attr.is_default or len(mod.tags.toolchain) == 1 | ||
is_default = toolchain_attr.is_default | ||
|
||
# Also only the root module should be able to decide ignore_root_user_error. | ||
# Modules being depended upon don't know the final environment, so they aren't | ||
|
@@ -251,6 +252,43 @@ def _fail_multiple_default_toolchains(first, second): | |
second = second, | ||
)) | ||
|
||
def _create_toolchain_attr_structs(mod): | ||
arg_structs = [] | ||
seen_versions = {} | ||
for tag in mod.tags.toolchain: | ||
arg_structs.append(_create_toolchain_attrs_struct(tag = tag, toolchain_tag_count = len(mod.tags.toolchain))) | ||
seen_versions[tag.python_version] = True | ||
|
||
if mod.is_root: | ||
register_all = False | ||
for tag in mod.tags.rules_python_private_testing: | ||
if tag.register_all_versions: | ||
register_all = True | ||
break | ||
if register_all: | ||
arg_structs.extend([ | ||
_create_toolchain_attrs_struct(python_version = v) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
for v in TOOL_VERSIONS.keys() | ||
if v not in seen_versions | ||
]) | ||
return arg_structs | ||
|
||
def _create_toolchain_attrs_struct(*, tag = None, python_version = None, toolchain_tag_count = None): | ||
if tag and python_version: | ||
fail("Only one of tag and python version can be specified") | ||
if tag: | ||
# A single toolchain is treated as the default because it's unambiguous. | ||
is_default = tag.is_default or toolchain_tag_count == 1 | ||
else: | ||
is_default = False | ||
|
||
return struct( | ||
is_default = is_default, | ||
python_version = python_version if python_version else tag.python_version, | ||
configure_coverage_tool = getattr(tag, "configure_coverage_tool", False), | ||
ignore_root_user_error = getattr(tag, "ignore_root_user_error", False), | ||
) | ||
|
||
def _get_bazel_version_specific_kwargs(): | ||
kwargs = {} | ||
|
||
|
@@ -264,6 +302,11 @@ python = module_extension( | |
""", | ||
implementation = _python_impl, | ||
tag_classes = { | ||
"rules_python_private_testing": tag_class( | ||
attrs = { | ||
"register_all_versions": attr.bool(default = False), | ||
}, | ||
), | ||
"toolchain": tag_class( | ||
doc = """Tag class used to register Python toolchains. | ||
Use this tag class to register one or more Python toolchains. This class | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this could be super useful in registering
minor_major
versions by default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had a similar thought. I'll post in slack.