blob: fb237d7e857ff9f85d437837713257acd31ae7ce [file] [log] [blame]
Klaus Aehlig3c9cd822018-05-24 03:35:42 -07001# 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
vladmos20a042f2018-06-01 04:51:21 -070016_BUILD = """
Klaus Aehlig3c9cd822018-05-24 03:35:42 -070017load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
18
19pkg_tar(
20 name="archives",
21 srcs = {srcs},
22 package_dir = "{dirname}",
23 visibility = ["//visibility:public"],
24)
25
26"""
27
28def _distdir_tar_impl(ctx):
vladmos20a042f2018-06-01 04:51:21 -070029 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 Aehlig3c9cd822018-05-24 03:35:42 -070036
37_distdir_tar_attrs = {
vladmos20a042f2018-06-01 04:51:21 -070038 "archives": attr.string_list(),
39 "sha256": attr.string_dict(),
40 "urls": attr.string_list_dict(),
41 "dirname": attr.string(default = "distdir"),
Klaus Aehlig3c9cd822018-05-24 03:35:42 -070042}
43
Klaus Aehlig3c9cd822018-05-24 03:35:42 -070044distdir_tar = repository_rule(
45 implementation = _distdir_tar_impl,
46 attrs = _distdir_tar_attrs,
47)