Skip to content

Commit 9f7560d

Browse files
authored
Merge pull request kubernetes#74153 from ixdy/bazel-kubernetes-src-tarball-new
bazel: make kubernetes-src.tar.gz actually include all srcs
2 parents 28c2a53 + 392ad71 commit 9f7560d

File tree

20 files changed

+530
-248
lines changed

20 files changed

+530
-248
lines changed

build/release-tars/BUILD

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ load(
1111
)
1212
load("@io_k8s_repo_infra//defs:build.bzl", "release_filegroup")
1313
load("@io_k8s_repo_infra//defs:pkg.bzl", "pkg_tar")
14+
load("//staging:repos_generated.bzl", "staging_repos")
1415

1516
# Bazel doesn't make the output filename
1617
# (such as kubernetes-server-{OS}-{ARCH}.tar.gz) configurable, so we instead
@@ -55,38 +56,16 @@ filegroup(
5556
tags = ["automanaged"],
5657
)
5758

58-
config_setting(
59-
name = "package_src",
60-
values = {
61-
"define": "PACKAGE_SRC=true",
62-
},
63-
visibility = ["//visibility:private"],
64-
)
65-
66-
genrule(
67-
name = "kubernetes-src-readme",
68-
outs = ["README-src.txt"],
69-
cmd = """
70-
echo For build efficiency, the src was not included in this release.>$@
71-
echo The full source code can be viewed at >>$@
72-
echo -n https://github.com/kubernetes/kubernetes/tree/ >>$@
73-
grep ^STABLE_BUILD_GIT_COMMIT bazel-out/stable-status.txt | cut -d' ' -f2 >>$@
74-
""",
75-
stamp = 1,
76-
)
77-
7859
pkg_tar(
7960
name = "kubernetes-src",
80-
srcs = select({
81-
":package_src": ["//:all-srcs"],
82-
"//conditions:default": ["README-src.txt"],
83-
}),
61+
srcs = ["//:all-srcs"],
8462
extension = "tar.gz",
8563
package_dir = "kubernetes",
86-
strip_prefix = select({
87-
":package_src": "//",
88-
"//conditions:default": ".",
89-
}),
64+
strip_prefix = "//",
65+
symlinks = {
66+
"kubernetes/vendor/%s" % repo: "../../staging/src/%s" % repo
67+
for repo in staging_repos
68+
},
9069
tags = [
9170
"manual",
9271
"no-cache",

hack/update-bazel.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ set -o nounset
1818
set -o pipefail
1919

2020
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
21-
export KUBE_ROOT
2221
source "${KUBE_ROOT}/hack/lib/init.sh"
2322

2423
# Ensure that we find the binaries we build before anything else.
@@ -30,20 +29,45 @@ go install k8s.io/kubernetes/vendor/github.com/bazelbuild/bazel-gazelle/cmd/gaze
3029
go install k8s.io/kubernetes/vendor/github.com/bazelbuild/buildtools/buildozer
3130
go install k8s.io/kubernetes/vendor/k8s.io/repo-infra/kazel
3231

32+
# Find all of the staging repos.
33+
while IFS='' read -r repo; do staging_repos+=("${repo}"); done <\
34+
<(cd "${KUBE_ROOT}/staging/src" && find k8s.io/ -mindepth 1 -maxdepth 1 -type d | LANG=C sort)
35+
36+
# Save the staging repos into a Starlark list that can be used by Bazel rules.
37+
(
38+
cat "${KUBE_ROOT}/hack/boilerplate/boilerplate.generatebzl.txt"
39+
echo "# This file is autogenerated by hack/update-bazel.sh."
40+
# avoid getting caught by the boilerplate checker
41+
rev <<<".TIDE TON OD #"
42+
echo
43+
echo "staging_repos = ["
44+
for repo in "${staging_repos[@]}"; do
45+
echo " \"${repo}\","
46+
done
47+
echo "]"
48+
) >"${KUBE_ROOT}/staging/repos_generated.bzl"
49+
50+
# Ensure there's a BUILD file at vendor/ so the all-srcs rule in the root
51+
# BUILD.bazel file is isolated from changes under vendor/.
3352
touch "${KUBE_ROOT}/vendor/BUILD"
34-
# Ensure that we use the correct importmap for all vendored dependencies.
35-
# Probably not necessary in gazelle 0.13+
36-
# (https://github.com/bazelbuild/bazel-gazelle/pull/207).
37-
if ! grep -q "# gazelle:importmap_prefix" "${KUBE_ROOT}/vendor/BUILD"; then
38-
echo "# gazelle:importmap_prefix k8s.io/kubernetes/vendor" >> "${KUBE_ROOT}/vendor/BUILD"
39-
fi
53+
# Ensure there's a BUILD file at the root of each staging repo. This prevents
54+
# the package-srcs glob in vendor/BUILD from following the symlinks
55+
# from vendor/k8s.io into staging. Following these symlinks through
56+
# vendor results in files being excluded from the kubernetes-src tarball
57+
# generated by Bazel.
58+
for repo in "${staging_repos[@]}"; do
59+
touch "${KUBE_ROOT}/staging/src/${repo}/BUILD"
60+
done
4061

62+
# Run gazelle to update Go rules in BUILD files.
4163
gazelle fix \
4264
-external=vendored \
4365
-mode=fix \
4466
-repo_root "${KUBE_ROOT}" \
4567
"${KUBE_ROOT}"
4668

69+
# Run kazel to update the pkg-srcs and all-srcs rules as well as handle
70+
# Kubernetes code generators.
4771
kazel
4872

4973
# make targets in vendor manual

staging/repos_generated.bzl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright The Kubernetes Authors.
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+
15+
# This file is autogenerated by hack/update-bazel.sh.
16+
# DO NOT EDIT.
17+
18+
staging_repos = [
19+
"k8s.io/api",
20+
"k8s.io/apiextensions-apiserver",
21+
"k8s.io/apimachinery",
22+
"k8s.io/apiserver",
23+
"k8s.io/cli-runtime",
24+
"k8s.io/client-go",
25+
"k8s.io/cloud-provider",
26+
"k8s.io/cluster-bootstrap",
27+
"k8s.io/code-generator",
28+
"k8s.io/component-base",
29+
"k8s.io/csi-api",
30+
"k8s.io/csi-translation-lib",
31+
"k8s.io/kube-aggregator",
32+
"k8s.io/kube-controller-manager",
33+
"k8s.io/kube-proxy",
34+
"k8s.io/kube-scheduler",
35+
"k8s.io/kubelet",
36+
"k8s.io/metrics",
37+
"k8s.io/node-api",
38+
"k8s.io/sample-apiserver",
39+
"k8s.io/sample-cli-plugin",
40+
"k8s.io/sample-controller",
41+
]

0 commit comments

Comments
 (0)