-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: make precompile tests pass when other toolchains are defined (#…
…2213) This makes the precompile_tests pass when the environment defines custom toolchains that don't match what rules_python defines in its dev environment. This keeps the tests independent of whatever the user's environment is. Basically, the tests rely on a fake Python version 4.5 toolchain for the precompiler being defined. They pass today because they fallback to a real toolchain (as setup by MODULE.bazel), which doesn't have any version constraints on it. In comparison, within Google, there is no "default" toolchain, so the tests fail to find what they need. To fix, explicitly define a fake precompiler toolchain and tell the test to use it. Along the way: * Also force `--allow_unresolved_symlinks=true` in the tests. This flag isn't enabled in certain environments, but is implicitly relied upon by the `current_interpreter_executable` rule when a platform runtime is used (as they are in the tests). * Move the Python testing toolchains to support/py_toolchains, to match where the cc testing toolchains were moved.
- Loading branch information
Showing
4 changed files
with
74 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# ==================== | ||
# NOTE: tests/support/support.bzl has constants to easily refer to | ||
# these toolchains. | ||
# ==================== | ||
|
||
load("//python:py_runtime.bzl", "py_runtime") | ||
load("//python:py_runtime_pair.bzl", "py_runtime_pair") | ||
load("//python/private:py_exec_tools_toolchain.bzl", "py_exec_tools_toolchain") # buildifier: disable=bzl-visibility | ||
|
||
# NOTE: A platform runtime is used because it doesn't include any files. This | ||
# makes it easier for analysis tests to verify content. | ||
py_runtime( | ||
name = "platform_runtime", | ||
implementation_name = "fakepy", | ||
interpreter_path = "/fake/python3.9", | ||
interpreter_version_info = { | ||
"major": "4", | ||
"minor": "5", | ||
}, | ||
) | ||
|
||
py_runtime_pair( | ||
name = "platform_runtime_pair", | ||
py3_runtime = ":platform_runtime", | ||
) | ||
|
||
toolchain( | ||
name = "platform_toolchain", | ||
toolchain = ":platform_runtime_pair", | ||
toolchain_type = "//python:toolchain_type", | ||
) | ||
|
||
toolchain( | ||
name = "exec_toolchain", | ||
toolchain = ":exec_toolchain_impl", | ||
toolchain_type = "//python:exec_tools_toolchain_type", | ||
) | ||
|
||
# An exec toolchain is explicitly defined so that the tests pass when run | ||
# in environments that aren't using the toolchains generated by the | ||
# hermetic runtimes. | ||
py_exec_tools_toolchain( | ||
name = "exec_toolchain_impl", | ||
precompiler = "//tools/precompiler:precompiler", | ||
) |
This file contains 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