Codegen: subprojects: nuke existing files

This commit is contained in:
Tim Hockin 2023-03-12 22:10:47 -07:00
parent 5463fcd7dd
commit a7a8cd6e5d
No known key found for this signature in database

View File

@ -83,11 +83,24 @@ fi
GOBIN="$(go env GOBIN)"
gobin="${GOBIN:-$(go env GOPATH)/bin}"
function git_find() {
# Similar to find but faster and easier to understand. We want to include
# modified and untracked files because this might be running against code
# which is not tracked by git yet.
git ls-files -cmo --exclude-standard "$@"
}
function git_grep() {
# We want to include modified and untracked files because this might be
# running against code which is not tracked by git yet.
git grep --untracked "$@"
}
function codegen::join() { local IFS="$1"; shift; echo "$*"; }
# enumerate group versions
ALL_FQ_APIS=() # e.g. k8s.io/kubernetes/pkg/apis/apps k8s.io/api/apps/v1
EXT_FQ_APIS=() # e.g. k8s.io/api/apps/v1
GROUP_VERSIONS=() # e.g. apps/v1
for GVs in ${GROUPS_WITH_VERSIONS}; do
IFS=: read -r G Vs <<<"${GVs}"
@ -99,10 +112,18 @@ for GVs in ${GROUPS_WITH_VERSIONS}; do
for V in ${Vs//,/ }; do
ALL_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
EXT_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
GROUP_VERSIONS+=("${G}/${V}")
done
done
if grep -qw "deepcopy" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.deepcopy.go | xargs -0 rm -f
popd >/dev/null
done
echo "Generating deepcopy funcs"
"${gobin}/deepcopy-gen" \
--input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
@ -111,6 +132,13 @@ if grep -qw "deepcopy" <<<"${GENS}"; then
fi
if grep -qw "defaulter" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.defaults.go | xargs -0 rm -f
popd >/dev/null
done
echo "Generating defaulters"
"${gobin}/defaulter-gen" \
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
@ -119,6 +147,13 @@ if grep -qw "defaulter" <<<"${GENS}"; then
fi
if grep -qw "conversion" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.conversion.go | xargs -0 rm -f
popd >/dev/null
done
echo "Generating conversions"
"${gobin}/conversion-gen" \
--input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
@ -127,8 +162,20 @@ if grep -qw "conversion" <<<"${GENS}"; then
fi
if grep -qw "applyconfiguration" <<<"${GENS}"; then
echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
APPLY_CONFIGURATION_PACKAGE="${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${APPLY_CONFIGURATION_PACKAGE}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by applyconfiguration-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${APPLY_CONFIGURATION_PACKAGE}"
"${gobin}/applyconfiguration-gen" \
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
--output-package "${APPLY_CONFIGURATION_PACKAGE}" \
@ -136,17 +183,44 @@ if grep -qw "applyconfiguration" <<<"${GENS}"; then
fi
if grep -qw "client" <<<"${GENS}"; then
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
CLIENTSET_PKG="${CLIENTSET_PKG_NAME:-clientset}"
CLIENTSET_NAME="${CLIENTSET_NAME_VERSIONED:-versioned}"
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by client-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG}"
"${gobin}/client-gen" \
--clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" \
--clientset-name "${CLIENTSET_NAME}" \
--input-base "" \
--input "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
--output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" \
--output-package "${OUTPUT_PKG}/${CLIENTSET_PKG}" \
--apply-configuration-package "${APPLY_CONFIGURATION_PACKAGE:-}" \
"$@"
fi
if grep -qw "lister" <<<"${GENS}"; then
# Nuke existing files
for gv in "${GROUP_VERSIONS[@]}"; do
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/listers/${gv}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by lister-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
done
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${gobin}/lister-gen" \
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
@ -155,16 +229,34 @@ if grep -qw "lister" <<<"${GENS}"; then
fi
if grep -qw "informer" <<<"${GENS}"; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/informers/externalversions" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by informer-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
"${gobin}/informer-gen" \
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" \
--listers-package "${OUTPUT_PKG}/listers" \
--output-package "${OUTPUT_PKG}/informers" \
"$@"
fi
if grep -qw "openapi" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.openapi.go | xargs -0 rm -f
popd >/dev/null
done
echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
declare -a OPENAPI_EXTRA_PACKAGES
"${gobin}/openapi-gen" \