Klaus Aehlig | 3c9cd82 | 2018-05-24 03:35:42 -0700 | [diff] [blame] | 1 | # Copyright 2018 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 | """Defines a repository rule that generates an archive consisting of the specified files to fetch""" |
| 15 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 16 | _BUILD = """ |
Klaus Aehlig | 3c9cd82 | 2018-05-24 03:35:42 -0700 | [diff] [blame] | 17 | load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") |
| 18 | |
| 19 | pkg_tar( |
| 20 | name="archives", |
| 21 | srcs = {srcs}, |
| 22 | package_dir = "{dirname}", |
| 23 | visibility = ["//visibility:public"], |
| 24 | ) |
| 25 | |
| 26 | """ |
| 27 | |
| 28 | def _distdir_tar_impl(ctx): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 29 | for name in ctx.attr.archives: |
| 30 | ctx.download(ctx.attr.urls[name], name, ctx.attr.sha256[name], False) |
| 31 | ctx.file("WORKSPACE", "") |
| 32 | ctx.file( |
| 33 | "BUILD", |
| 34 | _BUILD.format(srcs = ctx.attr.archives, dirname = ctx.attr.dirname), |
| 35 | ) |
Klaus Aehlig | 3c9cd82 | 2018-05-24 03:35:42 -0700 | [diff] [blame] | 36 | |
| 37 | _distdir_tar_attrs = { |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 38 | "archives": attr.string_list(), |
| 39 | "sha256": attr.string_dict(), |
| 40 | "urls": attr.string_list_dict(), |
| 41 | "dirname": attr.string(default = "distdir"), |
Klaus Aehlig | 3c9cd82 | 2018-05-24 03:35:42 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Klaus Aehlig | 3c9cd82 | 2018-05-24 03:35:42 -0700 | [diff] [blame] | 44 | distdir_tar = repository_rule( |
| 45 | implementation = _distdir_tar_impl, |
| 46 | attrs = _distdir_tar_attrs, |
| 47 | ) |