kythe.io@v0.0.68-0.20240422202219-7225dbc01741/third_party/bazel/bazel_repository_files.bzl (about) 1 """Repository rule for downloading selected files from Bazel's github repository.""" 2 3 _URL_TEMPLATE = "https://raw.githubusercontent.com/bazelbuild/bazel/{commit}/{path}" 4 5 def _impl(repository_ctx): 6 commit = repository_ctx.attr.commit 7 for path in repository_ctx.attr.files: 8 repository_ctx.download( 9 url = _URL_TEMPLATE.format(commit = commit, path = path), 10 output = path, 11 canonical_id = "{commit}/{path}".format(commit = commit, path = path), 12 ) 13 if path.endswith(".proto"): 14 # Hack to deal with the awkward lack of flexibility for proto includes and imports. 15 script = r's/\(import[^"]*\)"src\//\1"third_party\/bazel\/src\//' 16 result = repository_ctx.execute(["sed", "--in-place", "-e", script, path]) 17 if result.return_code != 0: 18 fail(result.stderr) 19 20 for src, dest in repository_ctx.attr.overlay.items(): 21 repository_ctx.symlink(src, dest) 22 23 bazel_repository_files = repository_rule( 24 implementation = _impl, 25 attrs = { 26 "commit": attr.string(mandatory = True), 27 "files": attr.string_list(mandatory = True), 28 "overlay": attr.label_keyed_string_dict(), 29 }, 30 )