github.com/bazelbuild/rules_webtesting@v0.2.0/web/internal/platform_http_file.bzl (about) 1 # Copyright 2016 The Closure Rules 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 """Downloads files based on local platform.""" 15 16 def _impl(repository_ctx): 17 if repository_ctx.os.name.lower().startswith("mac os"): 18 urls = repository_ctx.attr.macos_urls 19 sha256 = repository_ctx.attr.macos_sha256 20 elif repository_ctx.os.name.lower().startswith("windows"): 21 urls = repository_ctx.attr.windows_urls 22 sha256 = repository_ctx.attr.windows_sha256 23 else: 24 urls = repository_ctx.attr.amd64_urls 25 sha256 = repository_ctx.attr.amd64_sha256 26 basename = urls[0][urls[0].rindex("/") + 1:] 27 28 # sanitize the basename (for filenames with %20 in them) 29 basename = basename.replace("%20", "-") 30 repository_ctx.download(urls, basename, sha256) 31 32 # if archive is a dmg then convert it to a zip 33 if basename.endswith(".dmg"): 34 zipfile = basename.replace(".dmg", ".zip") 35 repository_ctx.execute([repository_ctx.path(Label("//web/internal:convert_dmg.sh")), basename, zipfile]) 36 basename = zipfile 37 repository_ctx.symlink(basename, "file/" + basename) 38 repository_ctx.file( 39 "file/BUILD", 40 "\n".join([ 41 ("# DO NOT EDIT: automatically generated BUILD file for " + 42 "platform_http_file rule " + repository_ctx.name), 43 "licenses(%s)" % repr(repository_ctx.attr.licenses), 44 "filegroup(", 45 " name = 'file',", 46 " srcs = ['%s']," % basename, 47 " visibility = ['//visibility:public'],", 48 ")", 49 ]), 50 ) 51 52 platform_http_file = repository_rule( 53 attrs = { 54 "licenses": attr.string_list(mandatory = True, allow_empty = False), 55 "amd64_urls": attr.string_list(), 56 "amd64_sha256": attr.string(), 57 "macos_urls": attr.string_list(), 58 "macos_sha256": attr.string(), 59 "windows_urls": attr.string_list(), 60 "windows_sha256": attr.string(), 61 }, 62 implementation = _impl, 63 )