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"""Dependencies for coverage.py used by the hermetic toolchain. 16""" 17 18load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 19load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 20load("//python/private:version_label.bzl", "version_label") 21 22# START: maintained by 'bazel run //tools/private/update_deps:update_coverage_deps <version>' 23_coverage_deps = { 24 "cp310": { 25 "aarch64-apple-darwin": ( 26 "https://files.pythonhosted.org/packages/a3/36/b5ae380c05f58544a40ff36f87fa1d6e45f5c2f299335586aac140c341ce/coverage-7.4.3-cp310-cp310-macosx_11_0_arm64.whl", 27 "718187eeb9849fc6cc23e0d9b092bc2348821c5e1a901c9f8975df0bc785bfd4", 28 ), 29 "aarch64-unknown-linux-gnu": ( 30 "https://files.pythonhosted.org/packages/9e/48/5ae1ccf4601500af0ca36eba0a2c1f1796e58fb7495de6da55ed43e13e5f/coverage-7.4.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", 31 "767b35c3a246bcb55b8044fd3a43b8cd553dd1f9f2c1eeb87a302b1f8daa0524", 32 ), 33 "x86_64-apple-darwin": ( 34 "https://files.pythonhosted.org/packages/50/5a/d727fcd2e0fc3aba61591b6f0fe1e87865ea9b6275f58f35810d6f85b05b/coverage-7.4.3-cp310-cp310-macosx_10_9_x86_64.whl", 35 "8580b827d4746d47294c0e0b92854c85a92c2227927433998f0d3320ae8a71b6", 36 ), 37 "x86_64-unknown-linux-gnu": ( 38 "https://files.pythonhosted.org/packages/23/0a/ab5b0f6d6b24f7156624e7697ec7ab49f9d5cdac922da90d9927ae5de1cf/coverage-7.4.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", 39 "ba3a8aaed13770e970b3df46980cb068d1c24af1a1968b7818b69af8c4347efb", 40 ), 41 }, 42 "cp311": { 43 "aarch64-apple-darwin": ( 44 "https://files.pythonhosted.org/packages/f8/a1/161102d2e26fde2d878d68cc1ed303758dc7b01ee14cc6aa70f5fd1b910d/coverage-7.4.3-cp311-cp311-macosx_11_0_arm64.whl", 45 "489763b2d037b164846ebac0cbd368b8a4ca56385c4090807ff9fad817de4113", 46 ), 47 "aarch64-unknown-linux-gnu": ( 48 "https://files.pythonhosted.org/packages/a7/af/1510df1132a68ca876013c0417ca46836252e43871d2623b489e4339c980/coverage-7.4.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", 49 "451f433ad901b3bb00184d83fd83d135fb682d780b38af7944c9faeecb1e0bfe", 50 ), 51 "x86_64-apple-darwin": ( 52 "https://files.pythonhosted.org/packages/ca/77/f17a5b199e8ca0443ace312f7e07ff3e4e7ba7d7c52847567d6f1edb22a7/coverage-7.4.3-cp311-cp311-macosx_10_9_x86_64.whl", 53 "cbbe5e739d45a52f3200a771c6d2c7acf89eb2524890a4a3aa1a7fa0695d2a47", 54 ), 55 "x86_64-unknown-linux-gnu": ( 56 "https://files.pythonhosted.org/packages/a9/1a/e2120233177b3e2ea9dcfd49a050748060166c74792b2b1db4a803307da4/coverage-7.4.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", 57 "b3ec74cfef2d985e145baae90d9b1b32f85e1741b04cd967aaf9cfa84c1334f3", 58 ), 59 }, 60 "cp312": { 61 "aarch64-apple-darwin": ( 62 "https://files.pythonhosted.org/packages/9d/d8/111ec1a65fef57ad2e31445af627d481f660d4a9218ee5c774b45187812a/coverage-7.4.3-cp312-cp312-macosx_11_0_arm64.whl", 63 "d6cdecaedea1ea9e033d8adf6a0ab11107b49571bbb9737175444cea6eb72328", 64 ), 65 "aarch64-unknown-linux-gnu": ( 66 "https://files.pythonhosted.org/packages/8f/eb/28416f1721a3b7fa28ea499e8a6f867e28146ea2453839c2bca04a001eeb/coverage-7.4.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", 67 "3b2eccb883368f9e972e216c7b4c7c06cabda925b5f06dde0650281cb7666a30", 68 ), 69 "x86_64-apple-darwin": ( 70 "https://files.pythonhosted.org/packages/11/5c/2cf3e794fa5d1eb443aa8544e2ba3837d75073eaf25a1fda64d232065609/coverage-7.4.3-cp312-cp312-macosx_10_9_x86_64.whl", 71 "b51bfc348925e92a9bd9b2e48dad13431b57011fd1038f08316e6bf1df107d10", 72 ), 73 "x86_64-unknown-linux-gnu": ( 74 "https://files.pythonhosted.org/packages/2f/db/70900f10b85a66f761a3a28950ccd07757d51548b1d10157adc4b9415f15/coverage-7.4.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", 75 "b9a4a8dd3dcf4cbd3165737358e4d7dfbd9d59902ad11e3b15eebb6393b0446e", 76 ), 77 }, 78 "cp38": { 79 "aarch64-apple-darwin": ( 80 "https://files.pythonhosted.org/packages/96/71/1c299b12e80d231e04a2bfd695e761fb779af7ab66f8bd3cb15649be82b3/coverage-7.4.3-cp38-cp38-macosx_11_0_arm64.whl", 81 "280459f0a03cecbe8800786cdc23067a8fc64c0bd51dc614008d9c36e1659d7e", 82 ), 83 "aarch64-unknown-linux-gnu": ( 84 "https://files.pythonhosted.org/packages/c7/a7/b00eaa53d904193478eae01625d784b2af8b522a98028f47c831dcc95663/coverage-7.4.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", 85 "6c0cdedd3500e0511eac1517bf560149764b7d8e65cb800d8bf1c63ebf39edd2", 86 ), 87 "x86_64-apple-darwin": ( 88 "https://files.pythonhosted.org/packages/e2/bc/f54b24b476db0069ac04ff2cdeb28cd890654c8619761bf818726022c76a/coverage-7.4.3-cp38-cp38-macosx_10_9_x86_64.whl", 89 "28ca2098939eabab044ad68850aac8f8db6bf0b29bc7f2887d05889b17346454", 90 ), 91 "x86_64-unknown-linux-gnu": ( 92 "https://files.pythonhosted.org/packages/d0/3a/e882caceca2c7d65791a4a759764a1bf803bbbd10caf38ec41d73a45219e/coverage-7.4.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", 93 "dec9de46a33cf2dd87a5254af095a409ea3bf952d85ad339751e7de6d962cde6", 94 ), 95 }, 96 "cp39": { 97 "aarch64-apple-darwin": ( 98 "https://files.pythonhosted.org/packages/66/f2/57f5d3c9d2e78c088e4c8dbc933b85fa81c424f23641f10c1aa64052ee4f/coverage-7.4.3-cp39-cp39-macosx_11_0_arm64.whl", 99 "77fbfc5720cceac9c200054b9fab50cb2a7d79660609200ab83f5db96162d20c", 100 ), 101 "aarch64-unknown-linux-gnu": ( 102 "https://files.pythonhosted.org/packages/ad/3f/cde6fd2e4cc447bd24e3dc2e79abd2e0fba67ac162996253d3505f8efef4/coverage-7.4.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", 103 "6679060424faa9c11808598504c3ab472de4531c571ab2befa32f4971835788e", 104 ), 105 "x86_64-apple-darwin": ( 106 "https://files.pythonhosted.org/packages/d6/cf/4094ac6410b680c91c5e55a56f25f4b3a878e2fcbf773c1cecfbdbaaec4f/coverage-7.4.3-cp39-cp39-macosx_10_9_x86_64.whl", 107 "3b253094dbe1b431d3a4ac2f053b6d7ede2664ac559705a704f621742e034f1f", 108 ), 109 "x86_64-unknown-linux-gnu": ( 110 "https://files.pythonhosted.org/packages/b5/ad/effc12b8f72321cb847c5ba7f4ea7ce3e5c19c641f6418131f8fb0ab2f61/coverage-7.4.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", 111 "8640f1fde5e1b8e3439fe482cdc2b0bb6c329f4bb161927c28d2e8879c6029ee", 112 ), 113 }, 114} 115# END: maintained by 'bazel run //tools/private/update_deps:update_coverage_deps <version>' 116 117_coverage_patch = Label("//python/private:coverage.patch") 118 119def coverage_dep(name, python_version, platform, visibility): 120 """Register a single coverage dependency based on the python version and platform. 121 122 Args: 123 name: The name of the registered repository. 124 python_version: The full python version. 125 platform: The platform, which can be found in //python:versions.bzl PLATFORMS dict. 126 visibility: The visibility of the coverage tool. 127 128 Returns: 129 The label of the coverage tool if the platform is supported, otherwise - None. 130 """ 131 if "windows" in platform: 132 # NOTE @aignas 2023-01-19: currently we do not support windows as the 133 # upstream coverage wrapper is written in shell. Do not log any warning 134 # for now as it is not actionable. 135 return None 136 137 abi = "cp" + version_label(python_version) 138 url, sha256 = _coverage_deps.get(abi, {}).get(platform, (None, "")) 139 140 if url == None: 141 # Some wheels are not present for some builds, so let's silently ignore those. 142 return None 143 144 maybe( 145 http_archive, 146 name = name, 147 build_file_content = """ 148filegroup( 149 name = "coverage", 150 srcs = ["coverage/__main__.py"], 151 data = glob(["coverage/*.py", "coverage/**/*.py", "coverage/*.so"]), 152 visibility = {visibility}, 153) 154 """.format( 155 visibility = visibility, 156 ), 157 patch_args = ["-p1"], 158 patches = [_coverage_patch], 159 sha256 = sha256, 160 type = "zip", 161 urls = [url], 162 ) 163 164 return "@{name}//:coverage".format(name = name) 165