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"""Defs to implement tests.""" 15 16def _py_cc_toolchain_available_test_impl(ctx): 17 toolchain = ctx.toolchains["@rules_python//python/cc:toolchain_type"] 18 19 if toolchain == None: 20 fail("expected @rules_python//python/cc:toolchain_type toolchain " + 21 "to be found, but it was not found") 22 23 executable = ctx.actions.declare_file(ctx.label.name) 24 ctx.actions.write(executable, "# no-op file", is_executable = True) 25 return [DefaultInfo( 26 executable = executable, 27 )] 28 29py_cc_toolchain_available_test = rule( 30 implementation = _py_cc_toolchain_available_test_impl, 31 toolchains = [ 32 config_common.toolchain_type( 33 "@rules_python//python/cc:toolchain_type", 34 mandatory = False, 35 ), 36 ], 37 test = True, 38) 39