Skip to content

Commit 4eeb69c

Browse files
vadorovskyistio-testing
authored andcommitted
bazel: Allow to distdir all dependencies (istio#702)
To use --distdir option of Bazel (which allows to use previously fetched tarballs instead of downloading dependencies during build), all dependencies should use http instead of git and need to have sha256 sums specified. Signed-off-by: Michal Rostecki <mrostecki@suse.de>
1 parent 93b99d4 commit 4eeb69c

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

WORKSPACE

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ workspace(name = "io_istio_api")
33
load("//:check_bazel_version.bzl", "check_version")
44
check_version()
55

6-
git_repository(
6+
# Oct 12, 2017 (Add `build_external` option to `go_repository`)
7+
RULES_GO_SHA = "9cf23e2aab101f86e4f51d8c5e0f14c012c2161c"
8+
RULES_GO_SHA256 = "76133849005134eceba9080ee28cef03316fd29f64a0a8a3ae09cd8862531d15"
9+
10+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
11+
http_archive(
712
name = "io_bazel_rules_go",
8-
commit = "9cf23e2aab101f86e4f51d8c5e0f14c012c2161c", # Oct 12, 2017 (Add `build_external` option to `go_repository`)
9-
remote = "https://github.com/bazelbuild/rules_go.git",
13+
strip_prefix = "rules_go-" + RULES_GO_SHA,
14+
url = "https://github.com/bazelbuild/rules_go/archive/" + RULES_GO_SHA + ".tar.gz",
15+
sha256 = RULES_GO_SHA256,
1016
)
1117

1218
load("//:api_dependencies.bzl", "mixer_api_dependencies")
1319
mixer_api_dependencies()
14-
15-

scripts/check-repositories

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2018 Istio Authors. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
################################################################################
18+
19+
set -eu
20+
21+
# Check whether any git repositories are defined.
22+
# Git repository definition contains `commit` and `remote` fields.
23+
if git --no-pager grep -E "commit =|remote =" -- 'WORKSPACE' '*.bzl'; then
24+
echo "Using git repositories is not allowed."
25+
echo "To ensure that all dependencies can be stored offline in distdir, only HTTP repositories are allowed."
26+
exit 1
27+
fi
28+
29+
# Check whether number of defined `url =` and `sha256 =` kwargs in repository
30+
# definitions is equal.
31+
urls_count=$(git --no-pager grep -E "url =" -- 'WORKSPACE' '*.bzl' | wc -l)
32+
sha256sums_count=$(git --no-pager grep -E "sha256 =" -- 'WORKSPACE' '*.bzl' | wc -l)
33+
34+
if [[ $urls_count != $sha256sums_count ]]; then
35+
echo "Found more defined repository URLs than SHA256 sums, which means that there are some repositories without sums."
36+
echo "Dependencies without SHA256 sums cannot be stored in distdir."
37+
echo "Please ensure that every repository has a SHA256 sum."
38+
echo "Repositories are defined in the WORKSPACE file."
39+
exit 1
40+
fi

scripts/pre-commit

+3
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ if [ $BRANCH_NAME != '(no branch)' ]; then
3838

3939
echo "Checking lint"
4040
make lint
41+
42+
echo "Checking repositories definitions"
43+
scripts/check-repositories
4144
fi

0 commit comments

Comments
 (0)