mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Make build scripts use Go import paths
This helps 2 things: 1) output is cleaner 2) whether a build is static or non-static depends on string matching, which is easier after this If you specify a `...` pattern, this will preserve it, which breaks the static/non-static matching but really, can we just agree that `make` is for binaries? It works for other things but so does `go build`. Example: ``` $ make WHAT="cmd/kubectl/ ./staging/src/k8s.io/api/... ./test/e2e/e2e.test ./test/e2e/e2e.test ./cmd/kubectl/ " go version go1.21.4 linux/amd64 +++ [1208 22:24:43] Building go targets for linux/amd64 k8s.io/api/... (non-static) k8s.io/kubernetes/cmd/kubectl (static) k8s.io/kubernetes/test/e2e/e2e.test (test) ```
This commit is contained in:
parent
f3c8e92def
commit
aaf6fc07d8
@ -318,7 +318,7 @@ readonly KUBE_ALL_TARGETS=(
|
|||||||
)
|
)
|
||||||
readonly KUBE_ALL_BINARIES=("${KUBE_ALL_TARGETS[@]##*/}")
|
readonly KUBE_ALL_BINARIES=("${KUBE_ALL_TARGETS[@]##*/}")
|
||||||
|
|
||||||
readonly KUBE_STATIC_LIBRARIES=(
|
readonly KUBE_STATIC_BINARIES=(
|
||||||
apiextensions-apiserver
|
apiextensions-apiserver
|
||||||
kube-aggregator
|
kube-aggregator
|
||||||
kube-apiserver
|
kube-apiserver
|
||||||
@ -344,16 +344,16 @@ readonly KUBE_COVERAGE_INSTRUMENTED_PACKAGES=(
|
|||||||
|
|
||||||
# KUBE_CGO_OVERRIDES is a space-separated list of binaries which should be built
|
# KUBE_CGO_OVERRIDES is a space-separated list of binaries which should be built
|
||||||
# with CGO enabled, assuming CGO is supported on the target platform.
|
# with CGO enabled, assuming CGO is supported on the target platform.
|
||||||
# This overrides any entry in KUBE_STATIC_LIBRARIES.
|
# This overrides any entry in KUBE_STATIC_BINARIES.
|
||||||
IFS=" " read -ra KUBE_CGO_OVERRIDES_LIST <<< "${KUBE_CGO_OVERRIDES:-}"
|
IFS=" " read -ra KUBE_CGO_OVERRIDES_LIST <<< "${KUBE_CGO_OVERRIDES:-}"
|
||||||
readonly KUBE_CGO_OVERRIDES_LIST
|
readonly KUBE_CGO_OVERRIDES_LIST
|
||||||
# KUBE_STATIC_OVERRIDES is a space-separated list of binaries which should be
|
# KUBE_STATIC_OVERRIDES is a space-separated list of binaries which should be
|
||||||
# built with CGO disabled. This is in addition to the list in
|
# built with CGO disabled. This is in addition to the list in
|
||||||
# KUBE_STATIC_LIBRARIES.
|
# KUBE_STATIC_BINARIES.
|
||||||
IFS=" " read -ra KUBE_STATIC_OVERRIDES_LIST <<< "${KUBE_STATIC_OVERRIDES:-}"
|
IFS=" " read -ra KUBE_STATIC_OVERRIDES_LIST <<< "${KUBE_STATIC_OVERRIDES:-}"
|
||||||
readonly KUBE_STATIC_OVERRIDES_LIST
|
readonly KUBE_STATIC_OVERRIDES_LIST
|
||||||
|
|
||||||
kube::golang::is_statically_linked_library() {
|
kube::golang::is_statically_linked() {
|
||||||
local e
|
local e
|
||||||
# Explicitly enable cgo when building kubectl for darwin from darwin.
|
# Explicitly enable cgo when building kubectl for darwin from darwin.
|
||||||
[[ "$(go env GOHOSTOS)" == "darwin" && "$(go env GOOS)" == "darwin" &&
|
[[ "$(go env GOHOSTOS)" == "darwin" && "$(go env GOOS)" == "darwin" &&
|
||||||
@ -361,18 +361,18 @@ kube::golang::is_statically_linked_library() {
|
|||||||
if [[ -n "${KUBE_CGO_OVERRIDES_LIST:+x}" ]]; then
|
if [[ -n "${KUBE_CGO_OVERRIDES_LIST:+x}" ]]; then
|
||||||
for e in "${KUBE_CGO_OVERRIDES_LIST[@]}"; do [[ "${1}" == *"/${e}" ]] && return 1; done;
|
for e in "${KUBE_CGO_OVERRIDES_LIST[@]}"; do [[ "${1}" == *"/${e}" ]] && return 1; done;
|
||||||
fi
|
fi
|
||||||
for e in "${KUBE_STATIC_LIBRARIES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
|
for e in "${KUBE_STATIC_BINARIES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
|
||||||
if [[ -n "${KUBE_STATIC_OVERRIDES_LIST:+x}" ]]; then
|
if [[ -n "${KUBE_STATIC_OVERRIDES_LIST:+x}" ]]; then
|
||||||
for e in "${KUBE_STATIC_OVERRIDES_LIST[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
|
for e in "${KUBE_STATIC_OVERRIDES_LIST[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
|
||||||
fi
|
fi
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# kube::golang::normalize_go_targets takes a list of build targets, which might
|
# kube::golang::best_guess_go_targets takes a list of build targets, which might
|
||||||
# be Go-style names (e.g. example.com/foo/bar or ./foo/bar) or just local paths
|
# be Go-style names (e.g. example.com/foo/bar or ./foo/bar) or just local paths
|
||||||
# (e.g. foo/bar) and produces a respective list (on stdout) of our best guess at
|
# (e.g. foo/bar) and produces a respective list (on stdout) of our best guess at
|
||||||
# Go target names.
|
# Go target names.
|
||||||
kube::golang::normalize_go_targets() {
|
kube::golang::best_guess_go_targets() {
|
||||||
local target
|
local target
|
||||||
for target; do
|
for target; do
|
||||||
if [ "${target}" = "ginkgo" ] ||
|
if [ "${target}" = "ginkgo" ] ||
|
||||||
@ -415,6 +415,39 @@ kube::golang::normalize_go_targets() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# kube::golang::normalize_go_targets takes a list of build targets, which might
|
||||||
|
# be Go-style names (e.g. example.com/foo/bar or ./foo/bar) or just local paths
|
||||||
|
# (e.g. foo/bar) and produces a respective list (on stdout) of Go package
|
||||||
|
# names.
|
||||||
|
kube::golang::normalize_go_targets() {
|
||||||
|
local targets=()
|
||||||
|
kube::util::read-array targets < <(kube::golang::best_guess_go_targets "$@")
|
||||||
|
kube::util::read-array targets < <(kube::golang::dedup "${targets[@]}")
|
||||||
|
set -- "${targets[@]}"
|
||||||
|
|
||||||
|
for target; do
|
||||||
|
if [[ "${target}" =~ ".test"$ ]]; then
|
||||||
|
local dir
|
||||||
|
dir="$(dirname "${target}")"
|
||||||
|
local tst
|
||||||
|
tst="$(basename "${target}")"
|
||||||
|
local pkg
|
||||||
|
pkg="$(go list -find "${dir}")"
|
||||||
|
echo "${pkg}/${tst}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ "${target}" =~ "/..."$ ]]; then
|
||||||
|
local dir
|
||||||
|
dir="$(dirname "${target}")"
|
||||||
|
local pkg
|
||||||
|
pkg="$(go list -find "${dir}")"
|
||||||
|
echo "${pkg}/..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
go list -find "${target}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Asks golang what it thinks the host platform is. The go tool chain does some
|
# Asks golang what it thinks the host platform is. The go tool chain does some
|
||||||
# slightly different things when the target platform matches the host platform.
|
# slightly different things when the target platform matches the host platform.
|
||||||
kube::golang::host_platform() {
|
kube::golang::host_platform() {
|
||||||
@ -833,14 +866,14 @@ kube::golang::build_binaries_for_platform() {
|
|||||||
if [[ "${binary}" =~ ".test"$ ]]; then
|
if [[ "${binary}" =~ ".test"$ ]]; then
|
||||||
tests+=("${binary}")
|
tests+=("${binary}")
|
||||||
kube::log::info " ${binary} (test)"
|
kube::log::info " ${binary} (test)"
|
||||||
elif kube::golang::is_statically_linked_library "${binary}"; then
|
elif kube::golang::is_statically_linked "${binary}"; then
|
||||||
statics+=("${binary}")
|
statics+=("${binary}")
|
||||||
kube::log::info " ${binary} (static)"
|
kube::log::info " ${binary} (static)"
|
||||||
else
|
else
|
||||||
nonstatics+=("${binary}")
|
nonstatics+=("${binary}")
|
||||||
kube::log::info " ${binary} (non-static)"
|
kube::log::info " ${binary} (non-static)"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
V=2 kube::log::info "Env for ${platform}: GOOS=${GOOS-} GOARCH=${GOARCH-} GOROOT=${GOROOT-} CGO_ENABLED=${CGO_ENABLED-} CC=${CC-}"
|
V=2 kube::log::info "Env for ${platform}: GOOS=${GOOS-} GOARCH=${GOARCH-} GOROOT=${GOROOT-} CGO_ENABLED=${CGO_ENABLED-} CC=${CC-}"
|
||||||
V=3 kube::log::info "Building binaries with GCFLAGS=${gogcflags} LDFLAGS=${goldflags}"
|
V=3 kube::log::info "Building binaries with GCFLAGS=${gogcflags} LDFLAGS=${goldflags}"
|
||||||
@ -962,19 +995,20 @@ kube::golang::build_binaries() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${#targets[@]} -eq 0 ]]; then
|
|
||||||
targets=("${KUBE_ALL_TARGETS[@]}")
|
|
||||||
fi
|
|
||||||
kube::util::read-array targets < <(kube::golang::dedup "${targets[@]}")
|
|
||||||
|
|
||||||
local -a platforms
|
local -a platforms
|
||||||
IFS=" " read -ra platforms <<< "${KUBE_BUILD_PLATFORMS:-}"
|
IFS=" " read -ra platforms <<< "${KUBE_BUILD_PLATFORMS:-}"
|
||||||
if [[ ${#platforms[@]} -eq 0 ]]; then
|
if [[ ${#platforms[@]} -eq 0 ]]; then
|
||||||
platforms=("${host_platform}")
|
platforms=("${host_platform}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ${#targets[@]} -eq 0 ]]; then
|
||||||
|
targets=("${KUBE_ALL_TARGETS[@]}")
|
||||||
|
fi
|
||||||
|
kube::util::read-array targets < <(kube::golang::dedup "${targets[@]}")
|
||||||
|
|
||||||
local -a binaries
|
local -a binaries
|
||||||
kube::util::read-array binaries < <(kube::golang::normalize_go_targets "${targets[@]}")
|
kube::util::read-array binaries < <(kube::golang::normalize_go_targets "${targets[@]}")
|
||||||
|
kube::util::read-array binaries < <(kube::golang::dedup "${binaries[@]}")
|
||||||
|
|
||||||
local parallel=false
|
local parallel=false
|
||||||
if [[ ${#platforms[@]} -gt 1 ]]; then
|
if [[ ${#platforms[@]} -gt 1 ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user