1# Copyright 2023 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"""Extension only used for development purposes.""" 16 17def _dev_ext_impl(mctx): 18 module = mctx.modules[0] 19 _dev_toolchains_repo( 20 name = "rules_testing_dev_toolchains", 21 is_root = module.is_root, 22 ) 23 24dev = module_extension( 25 implementation = _dev_ext_impl, 26) 27 28def _dev_toolchains_repo_impl(rctx): 29 # If its the root module, then we're in rules_testing and 30 # it's a dev dependency situation. 31 if rctx.attr.is_root: 32 toolchain_build = Label("@python_3_11_toolchains//:BUILD.bazel") 33 34 # NOTE: This is brittle. It only works because, luckily, 35 # rules_python's toolchain BUILD file is essentially self-contained. 36 # It only uses absolute references and doesn't load anything, 37 # so we can copy it elsewhere and it still works. 38 rctx.symlink(toolchain_build, "BUILD.bazel") 39 else: 40 rctx.file("BUILD.bazel", "") 41 42_dev_toolchains_repo = repository_rule( 43 implementation = _dev_toolchains_repo_impl, 44 attrs = { 45 "is_root": attr.bool(), 46 }, 47) 48