@@ -18,99 +18,26 @@ set -o nounset
18
18
set -o pipefail
19
19
20
20
KUBE_ROOT=$( dirname " ${BASH_SOURCE[0]} " ) /..
21
- source " ${KUBE_ROOT} /hack/lib/init.sh"
22
21
23
- # Ensure that we find the binaries we build before anything else.
24
- export GOBIN=" ${KUBE_OUTPUT_BINPATH} "
25
- PATH=" ${GOBIN} :${PATH} "
22
+ # delete all bazel related files
23
+ find " ${KUBE_ROOT} " \( \
24
+ -name BUILD \
25
+ -o -name BUILD.bazel \
26
+ -o -name ' *.bzl' \
27
+ \) \
28
+ -delete
29
+
30
+ # remove additional one-off bazel related files
31
+ # NOTE: most of these will be pairs of symlinked location in "${KUBE_ROOT}/"
32
+ # and the actual location in "${KUBE_ROOT}/build/root/"
33
+ rm -f \
34
+ " ${KUBE_ROOT} /build/root/BUILD.root" \
35
+ " ${KUBE_ROOT} /WORKSPACE" \
36
+ " ${KUBE_ROOT} /build/root/WORKSPACE" \
37
+ " ${KUBE_ROOT} /.bazelrc" \
38
+ " ${KUBE_ROOT} /build/root/.bazelrc" \
39
+ " ${KUBE_ROOT} /.bazelversion" \
40
+ " ${KUBE_ROOT} /build/root/.bazelversion" \
41
+ " ${KUBE_ROOT} /.kazelcfg.json" \
42
+ " ${KUBE_ROOT} /build/root/.kazelcfg.json"
26
43
27
- pushd " ${KUBE_ROOT} /hack/tools" > /dev/null
28
- GO111MODULE=on go install github.com/bazelbuild/bazel-gazelle/cmd/gazelle
29
- GO111MODULE=on go install github.com/bazelbuild/buildtools/buildozer
30
- GO111MODULE=on go install k8s.io/repo-infra/cmd/kazel
31
- popd > /dev/null
32
-
33
- # Find all of the staging repos.
34
- while IFS=' ' read -r repo; do staging_repos+=(" ${repo} " ); done < \
35
- <( cd " ${KUBE_ROOT} /staging/src" && find k8s.io -mindepth 1 -maxdepth 1 -type d | LC_ALL=C LANG=C sort)
36
-
37
- # Save the staging repos into a Starlark list that can be used by Bazel rules.
38
- (
39
- cat " ${KUBE_ROOT} /hack/boilerplate/boilerplate.generatebzl.txt"
40
- echo " # This file is autogenerated by hack/update-bazel.sh."
41
- # avoid getting caught by the boilerplate checker
42
- rev <<< " .TIDE TON OD #"
43
- echo
44
- echo " staging_repos = ["
45
- for repo in " ${staging_repos[@]} " ; do
46
- echo " \" ${repo} \" ,"
47
- done
48
- echo " ]"
49
- ) > " ${KUBE_ROOT} /staging/repos_generated.bzl"
50
-
51
- # Ensure there's a BUILD file at vendor/ so the all-srcs rule in the root
52
- # BUILD.bazel file is isolated from changes under vendor/.
53
- touch " ${KUBE_ROOT} /vendor/BUILD"
54
- # Ensure there's a BUILD file at the root of each staging repo. This prevents
55
- # the package-srcs glob in vendor/BUILD from following the symlinks
56
- # from vendor/k8s.io into staging. Following these symlinks through
57
- # vendor results in files being excluded from the kubernetes-src tarball
58
- # generated by Bazel.
59
- for repo in " ${staging_repos[@]} " ; do
60
- touch " ${KUBE_ROOT} /staging/src/${repo} /BUILD"
61
- done
62
-
63
- # Warning: Please be careful when ignoring these pkg-config errors.
64
- # As gazelle doesn't support pkg-config, if we suppress these errors here, we actually need to modify the script below to handle it manually.
65
- # For instance, in the case of `libseccomp`, we set the link option `-lseccomp` to make it work properly.
66
- KNOWN_PKG_CONFIG_ERRORS=(
67
- " vendor/github.com/seccomp/libseccomp-golang/seccomp(_internal)?.go: pkg-config not supported: #cgo pkg-config: libseccomp"
68
- " vendor/github.com/google/cadvisor/nvm/machine_libipmctl.go: pkg-config not supported: #cgo pkg-config: libipmctl"
69
- )
70
-
71
- # Run gazelle to update Go rules in BUILD files.
72
- # filter out known pkg-config error (see buildozer workaround below)
73
- # NOTE: the `|| exit "${PIPESTATUS[0]}"` is to ignore grep errors
74
- # while preserving the exit code of gazelle
75
- gazelle fix \
76
- -external=vendored \
77
- -mode=fix \
78
- -repo_root " ${KUBE_ROOT} " \
79
- " ${KUBE_ROOT} " \
80
- 2>&1 | grep -Ev " $( kube::util::join \| " ${KNOWN_PKG_CONFIG_ERRORS[@]} " ) " || (exit " ${PIPESTATUS[0]} " )
81
-
82
- # Run kazel to update the pkg-srcs and all-srcs rules as well as handle
83
- # Kubernetes code generators.
84
- kazel
85
-
86
- # make targets in vendor manual
87
- # buildozer exits 3 when no changes are made ¯\_(ツ)_/¯
88
- # https://github.com/bazelbuild/buildtools/tree/master/buildozer#error-code
89
- buildozer -quiet ' add tags manual' ' //vendor/...:%go_binary' ' //vendor/...:%go_test' && ret=$? || ret=$?
90
- if [[ $ret != 0 && $ret != 3 ]]; then
91
- exit 1
92
- fi
93
-
94
- # mark all ./test/integration/* targets as integration
95
- # see comment above re: buildozer exit codes
96
- buildozer -quiet ' add tags integration' ' //test/integration/...:%go_test' && ret=$? || ret=$?
97
- if [[ $ret != 0 && $ret != 3 ]]; then
98
- exit 1
99
- fi
100
-
101
- # restrict ./vendor/github.com/prometheus/* targets visibility
102
- # see comment above re: buildozer exit codes
103
- buildozer -quiet ' set visibility //build/visible_to:vendor_githubcom_prometheus_CONSUMERS' ' //vendor/github.com/prometheus/...:go_default_library' && ret=$? || ret=$?
104
- if [[ $ret != 0 && $ret != 3 ]]; then
105
- exit 1
106
- fi
107
-
108
- # we need to set this because gazelle doesn't support pkg-config, which would set this link option
109
- # see comment above re: buildozer exit codes
110
- buildozer -quiet ' set clinkopts select({"@io_bazel_rules_go//go/platform:linux":["-lseccomp",],"//conditions:default":[],})' //vendor/github.com/seccomp/libseccomp-golang:go_default_library && ret=$? || ret=$?
111
- if [[ $ret != 0 && $ret != 3 ]]; then
112
- exit 1
113
- fi
114
-
115
- # Avoid bazel stuff in tools/ directory
116
- rm hack/tools/BUILD
0 commit comments