1# Copyright 2022 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"" 16 17load("//python:versions.bzl", "PLATFORMS", "TOOL_VERSIONS") 18load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test") 19 20def define_toolchain_tests(name): 21 """Define the toolchain tests. 22 23 Args: 24 name: Only present to satisfy tooling. 25 """ 26 for platform_key, platform_info in PLATFORMS.items(): 27 native.config_setting( 28 name = "_is_{}".format(platform_key), 29 flag_values = platform_info.flag_values, 30 constraint_values = platform_info.compatible_with, 31 ) 32 33 for python_version, meta in TOOL_VERSIONS.items(): 34 target_compatible_with = { 35 "//conditions:default": ["@platforms//:incompatible"], 36 } 37 for platform_key in meta["sha256"].keys(): 38 is_platform = "_is_{}".format(platform_key) 39 target_compatible_with[is_platform] = [] 40 41 py_reconfig_test( 42 name = "python_{}_test".format(python_version), 43 srcs = ["python_toolchain_test.py"], 44 main = "python_toolchain_test.py", 45 python_version = python_version, 46 env = { 47 "EXPECT_PYTHON_VERSION": python_version, 48 }, 49 deps = ["//python/runfiles"], 50 data = ["//tests/support:current_build_settings"], 51 target_compatible_with = select(target_compatible_with), 52 ) 53