aboutsummaryrefslogtreecommitdiffhomepage
path: root/distdir.bzl
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-05-24 03:35:42 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-24 03:37:17 -0700
commit3c9cd82b847f3ece8ec04b2029bd5e8ad0eb7502 (patch)
tree95365e802fa4f844a231f8502840a6f3ad1f9b0a /distdir.bzl
parent72075bf94cb2dc1bee8fa785767468c8bb6a240c (diff)
distfile: pack the archives needed later in the build
...and point --experimental_distdir there, so that offline builds are again possible out of the distribution archive. Related #5175. Fixes #5202. To be cherry-picked for #5056. Change-Id: I634296e9d83e4e18ed966b42f35acc63061259d9 PiperOrigin-RevId: 197866998
Diffstat (limited to 'distdir.bzl')
-rw-r--r--distdir.bzl46
1 files changed, 46 insertions, 0 deletions
diff --git a/distdir.bzl b/distdir.bzl
new file mode 100644
index 0000000000..f5a130de27
--- /dev/null
+++ b/distdir.bzl
@@ -0,0 +1,46 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Defines a repository rule that generates an archive consisting of the specified files to fetch"""
+
+_BUILD="""
+load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
+
+pkg_tar(
+ name="archives",
+ srcs = {srcs},
+ package_dir = "{dirname}",
+ visibility = ["//visibility:public"],
+)
+
+"""
+
+def _distdir_tar_impl(ctx):
+ for name in ctx.attr.archives:
+ ctx.download(ctx.attr.urls[name], name, ctx.attr.sha256[name], False)
+ ctx.file("WORKSPACE", "")
+ ctx.file("BUILD",
+ _BUILD.format(srcs=ctx.attr.archives, dirname=ctx.attr.dirname))
+
+_distdir_tar_attrs = {
+ "archives" : attr.string_list(),
+ "sha256" : attr.string_dict(),
+ "urls" : attr.string_list_dict(),
+ "dirname" : attr.string(default="distdir"),
+}
+
+
+distdir_tar = repository_rule(
+ implementation = _distdir_tar_impl,
+ attrs = _distdir_tar_attrs,
+)