kube_codegen: avoid dups in dirs with >1 file

This happens in out-of-tree consumers of this script.
This commit is contained in:
Tim Hockin 2023-10-20 16:28:25 -07:00
parent 88d9573c30
commit a789a9d44b
No known key found for this signature in database

View File

@ -118,16 +118,16 @@ function kube::codegen::gen_helpers() {
# Deepcopy
#
local input_pkgs=()
while read -r file; do
dir="$(dirname "${file}")"
while read -r dir; do
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l \
( kube::codegen::internal::git_grep -l --null \
-e '+k8s:deepcopy-gen=' \
":(glob)${root}"/'**/*.go' \
|| true \
) | LC_ALL=C sort -u
) | xargs -0 -n1 dirname \
| LC_ALL=C sort -u
)
if [ "${#input_pkgs[@]}" != 0 ]; then
@ -152,16 +152,16 @@ function kube::codegen::gen_helpers() {
# Defaults
#
local input_pkgs=()
while read -r file; do
dir="$(dirname "${file}")"
while read -r dir; do
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l \
( kube::codegen::internal::git_grep -l --null \
-e '+k8s:defaulter-gen=' \
":(glob)${root}"/'**/*.go' \
|| true \
) | LC_ALL=C sort -u
) | xargs -0 -n1 dirname \
| LC_ALL=C sort -u
)
if [ "${#input_pkgs[@]}" != 0 ]; then
@ -186,16 +186,16 @@ function kube::codegen::gen_helpers() {
# Conversions
#
local input_pkgs=()
while read -r file; do
dir="$(dirname "${file}")"
while read -r dir; do
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l \
( kube::codegen::internal::git_grep -l --null \
-e '+k8s:conversion-gen=' \
":(glob)${root}"/'**/*.go' \
|| true \
) | LC_ALL=C sort -u
) | xargs -0 -n1 dirname \
| LC_ALL=C sort -u
)
if [ "${#input_pkgs[@]}" != 0 ]; then
@ -347,16 +347,16 @@ function kube::codegen::gen_openapi() {
root="$(cd "${root}" && pwd -P)"
local input_pkgs=( "${extra_pkgs[@]:+"${extra_pkgs[@]}"}")
while read -r file; do
dir="$(dirname "${file}")"
while read -r dir; do
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l \
( kube::codegen::internal::git_grep -l --null \
-e '+k8s:openapi-gen=' \
":(glob)${root}"/'**/*.go' \
|| true \
) | LC_ALL=C sort -u
) | xargs -0 -n1 dirname \
| LC_ALL=C sort -u
)
if [ "${#input_pkgs[@]}" != 0 ]; then
@ -396,7 +396,7 @@ function kube::codegen::gen_openapi() {
#
# Args:
# --input-pkg-root <string>
# The root package under which to search for types.go files which request
# The root package under which to search for *.go files which request
# clients to be generated. This must be Go package syntax, e.g.
# "k8s.io/foo/bar".
#
@ -538,8 +538,7 @@ function kube::codegen::gen_client() {
local group_versions=()
local input_pkgs=()
while read -r file; do
dir="$(dirname "${file}")"
while read -r dir; do
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
leaf="$(basename "${dir}")"
if grep -E -q '^v[0-9]+((alpha|beta)[0-9]+)?$' <<< "${leaf}"; then
@ -550,11 +549,12 @@ function kube::codegen::gen_client() {
group_versions+=("${leaf2}/${leaf}")
fi
done < <(
( kube::codegen::internal::git_grep -l \
( kube::codegen::internal::git_grep -l --null \
-e '+genclient' \
":(glob)${in_root}"/'**/types.go' \
|| true \
) | LC_ALL=C sort -u
) | xargs -0 -n1 dirname \
| LC_ALL=C sort -u
)
if [ "${#group_versions[@]}" == 0 ]; then