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

tests: make precompile tests pass when other toolchains are defined #2213

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 14 additions & 23 deletions tests/base_rules/precompile/precompile_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ load(
"//tests/support:support.bzl",
"CC_TOOLCHAIN",
"EXEC_TOOLS_TOOLCHAIN",
"PLATFORM_TOOLCHAIN",
"PRECOMPILE",
"PRECOMPILE_ADD_TO_RUNFILES",
"PRECOMPILE_SOURCE_RETENTION",
"PY_TOOLCHAINS",
)

_TEST_TOOLCHAINS = [PLATFORM_TOOLCHAIN, CC_TOOLCHAIN]
_COMMON_CONFIG_SETTINGS = {
# This isn't enabled in all environments the tests run in, so disable
# it for conformity.
"//command_line_option:allow_unresolved_symlinks": True,
"//command_line_option:extra_toolchains": [PY_TOOLCHAINS, CC_TOOLCHAIN],
EXEC_TOOLS_TOOLCHAIN: "enabled",
}

_tests = []

Expand All @@ -60,10 +66,7 @@ def _test_precompile_enabled_setup(name, py_rule, **kwargs):
name = name,
impl = _test_precompile_enabled_impl,
target = name + "_subject",
config_settings = {
"//command_line_option:extra_toolchains": _TEST_TOOLCHAINS,
EXEC_TOOLS_TOOLCHAIN: "enabled",
},
config_settings = _COMMON_CONFIG_SETTINGS,
)

def _test_precompile_enabled_impl(env, target):
Expand Down Expand Up @@ -118,10 +121,8 @@ def _test_pyc_only(name):
analysis_test(
name = name,
impl = _test_pyc_only_impl,
config_settings = {
"//command_line_option:extra_toolchains": _TEST_TOOLCHAINS,
config_settings = _COMMON_CONFIG_SETTINGS | {
##PRECOMPILE_SOURCE_RETENTION: "omit_source",
EXEC_TOOLS_TOOLCHAIN: "enabled",
PRECOMPILE: "enabled",
},
target = name + "_subject",
Expand Down Expand Up @@ -163,10 +164,7 @@ def _test_precompile_if_generated(name):
name = name,
impl = _test_precompile_if_generated_impl,
target = name + "_subject",
config_settings = {
"//command_line_option:extra_toolchains": _TEST_TOOLCHAINS,
EXEC_TOOLS_TOOLCHAIN: "enabled",
},
config_settings = _COMMON_CONFIG_SETTINGS,
)

_tests.append(_test_precompile_if_generated)
Expand Down Expand Up @@ -205,10 +203,8 @@ def _test_omit_source_if_generated_source(name):
name = name,
impl = _test_omit_source_if_generated_source_impl,
target = name + "_subject",
config_settings = {
"//command_line_option:extra_toolchains": _TEST_TOOLCHAINS,
config_settings = _COMMON_CONFIG_SETTINGS | {
PRECOMPILE_SOURCE_RETENTION: "omit_if_generated_source",
EXEC_TOOLS_TOOLCHAIN: "enabled",
},
)

Expand Down Expand Up @@ -254,11 +250,9 @@ def _test_precompile_add_to_runfiles_decided_elsewhere(name):
"binary": name + "_binary",
"library": name + "_lib",
},
config_settings = {
"//command_line_option:extra_toolchains": _TEST_TOOLCHAINS,
config_settings = _COMMON_CONFIG_SETTINGS | {
PRECOMPILE_ADD_TO_RUNFILES: "decided_elsewhere",
PRECOMPILE: "enabled",
EXEC_TOOLS_TOOLCHAIN: "enabled",
},
)

Expand Down Expand Up @@ -293,10 +287,7 @@ def _test_precompiler_action(name):
name = name,
impl = _test_precompiler_action_impl,
target = name + "_subject",
config_settings = {
"//command_line_option:extra_toolchains": _TEST_TOOLCHAINS,
EXEC_TOOLS_TOOLCHAIN: "enabled",
},
config_settings = _COMMON_CONFIG_SETTINGS,
)

_tests.append(_test_precompiler_action)
Expand Down
23 changes: 0 additions & 23 deletions tests/support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# to force them to resolve in the proper context.
# ====================

load("//python:py_runtime.bzl", "py_runtime")
load("//python:py_runtime_pair.bzl", "py_runtime_pair")
load(":sh_py_run_test.bzl", "current_build_settings")

package(
Expand Down Expand Up @@ -89,27 +87,6 @@ platform(
],
)

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",
)

current_build_settings(
name = "current_build_settings",
)
59 changes: 59 additions & 0 deletions tests/support/py_toolchains/BUILD
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",
)
2 changes: 1 addition & 1 deletion tests/support/support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LINUX_X86_64 = Label("//tests/support:linux_x86_64")
WINDOWS = Label("//tests/support:windows")
WINDOWS_X86_64 = Label("//tests/support:windows_x86_64")

PLATFORM_TOOLCHAIN = str(Label("//tests/support:platform_toolchain"))
PY_TOOLCHAINS = str(Label("//tests/support/py_toolchains:all"))
CC_TOOLCHAIN = str(Label("//tests/support/cc_toolchains:all"))
CROSSTOOL_TOP = Label("//tests/support/cc_toolchains:cc_toolchain_suite")

Expand Down