1"""This module defines the cipd_install repository rule. 2 3The cipd_install rule is a wrapper around http_archive to download the CIPD 4package at the specified version over HTTPS. This does not require depot_tools nor a cipd binary 5on the host machine. 6""" 7 8load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 9 10def cipd_install( 11 name, 12 cipd_package, 13 sha256, 14 tag, 15 build_file = None, 16 build_file_content = None, 17 postinstall_cmds_posix = None, 18 postinstall_cmds_win = None): 19 """Download and extract the zipped archive from CIPD, making it available for Bazel rules. 20 21 Args: 22 name: The name of the Bazel "repository" created. For example, if name is "alpha_beta", 23 the full Bazel label will start with "@alpha_beta//". 24 cipd_package: The full name of the CIPD package. This is a "path" from the root of CIPD. 25 This should be a publicly accessible package, as authentication is not 26 supported. 27 sha256: The sha256 hash of the zip archive downloaded from CIPD. This should match the 28 official CIPD website. 29 tag: Represents the version of the CIPD package to download, e.g. "git_package:abc123...". 30 build_file: The file to use as the BUILD.bazel file for this repository. Such build files 31 typically contain "exports_files" and/or "filegroup" rules. Since CIPD packages do not 32 include BUILD.bazel files, we must provide our own. Either build_file or 33 build_file_content can be specified, but not both. 34 build_file_content: The content for the BUILD file for this repository. Either build_file 35 or build_file_content can be specified, but not both. 36 postinstall_cmds_posix: Optional Bash commands to run on Mac/Linux after download. 37 postinstall_cmds_win: Optional Powershell commands to run on Windows after download. 38 """ 39 cipd_url = "https://chrome-infra-packages.appspot.com/dl/" 40 cipd_url += cipd_package 41 cipd_url += "/+/" 42 cipd_url += tag 43 44 mirror_url = "https://storage.googleapis.com/skia-world-readable/bazel/" 45 mirror_url += sha256 46 mirror_url += ".zip" 47 48 http_archive( 49 name = name, 50 sha256 = sha256, 51 urls = [ 52 cipd_url, 53 mirror_url, 54 ], 55 type = "zip", 56 build_file = build_file, 57 build_file_content = build_file_content, 58 patch_cmds = postinstall_cmds_posix, 59 patch_cmds_win = postinstall_cmds_win, 60 ) 61