Codegen: use plain grep instead of git grep

Some consumers want to operate across repositories, so git just gets in
the way.
This commit is contained in:
Tim Hockin 2024-02-19 13:22:29 -08:00
parent 8a0147c882
commit 527d2ea9d0
No known key found for this signature in database

View File

@ -34,10 +34,13 @@ function kube::codegen::internal::git_find() {
git ls-files -cmo --exclude-standard "$@"
}
function kube::codegen::internal::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 "$@" ":(exclude)vendor/"
function kube::codegen::internal::grep() {
# We use `grep` rather than `git grep` because sometimes external projects
# use this across repos.
grep "$@" \
--exclude-dir .git \
--exclude-dir _output \
--exclude-dir vendor
}
# Generate tagged helper code: conversions, deepcopy, and defaults
@ -127,9 +130,10 @@ function kube::codegen::gen_helpers() {
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '+k8s:deepcopy-gen=' \
":(glob)${root}"/'**/*.go' \
-r "${root}" \
--include '*.go' \
|| true \
) | while read -r -d $'\0' F; do dirname "${F}"; done \
| LC_ALL=C sort -u
@ -161,9 +165,10 @@ function kube::codegen::gen_helpers() {
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '+k8s:defaulter-gen=' \
":(glob)${root}"/'**/*.go' \
-r "${root}" \
--include '*.go' \
|| true \
) | while read -r -d $'\0' F; do dirname "${F}"; done \
| LC_ALL=C sort -u
@ -195,9 +200,10 @@ function kube::codegen::gen_helpers() {
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '+k8s:conversion-gen=' \
":(glob)${root}"/'**/*.go' \
-r "${root}" \
--include '*.go' \
|| true \
) | while read -r -d $'\0' F; do dirname "${F}"; done \
| LC_ALL=C sort -u
@ -357,9 +363,10 @@ function kube::codegen::gen_openapi() {
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '+k8s:openapi-gen=' \
":(glob)${root}"/'**/*.go' \
-r "${root}" \
--include '*.go' \
|| true \
) | while read -r -d $'\0' F; do dirname "${F}"; done \
| LC_ALL=C sort -u
@ -566,9 +573,10 @@ function kube::codegen::gen_client() {
group_versions+=("${leaf2}/${leaf}")
fi
done < <(
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '+genclient' \
":(glob)${in_root}${one_input_api}"/'**/*.go' \
-r "${in_root}${one_input_api}" \
--include '*.go' \
|| true \
) | while read -r -d $'\0' F; do dirname "${F}"; done \
| LC_ALL=C sort -u
@ -584,9 +592,10 @@ function kube::codegen::gen_client() {
echo "Generating applyconfig code for ${#input_pkgs[@]} targets"
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '^// Code generated by applyconfiguration-gen. DO NOT EDIT.$' \
":(glob)${out_root}/${applyconfig_subdir}"/'**/*.go' \
-r "${out_root}/${applyconfig_subdir}" \
--include '*.go' \
|| true \
) | xargs -0 rm -f
@ -604,9 +613,10 @@ function kube::codegen::gen_client() {
echo "Generating client code for ${#group_versions[@]} targets"
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '^// Code generated by client-gen. DO NOT EDIT.$' \
":(glob)${out_root}/${clientset_subdir}"/'**/*.go' \
-r "${out_root}/${clientset_subdir}" \
--include '*.go' \
|| true \
) | xargs -0 rm -f
@ -627,9 +637,10 @@ function kube::codegen::gen_client() {
if [ "${watchable}" == "true" ]; then
echo "Generating lister code for ${#input_pkgs[@]} targets"
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '^// Code generated by lister-gen. DO NOT EDIT.$' \
":(glob)${out_root}/${listers_subdir}"/'**/*.go' \
-r "${out_root}/${listers_subdir}" \
--include '*.go' \
|| true \
) | xargs -0 rm -f
@ -646,9 +657,10 @@ function kube::codegen::gen_client() {
echo "Generating informer code for ${#input_pkgs[@]} targets"
( kube::codegen::internal::git_grep -l --null \
( kube::codegen::internal::grep -l --null \
-e '^// Code generated by informer-gen. DO NOT EDIT.$' \
":(glob)${out_root}/${informers_subdir}"/'**/*.go' \
-r "${out_root}/${informers_subdir}" \
--include '*.go' \
|| true \
) | xargs -0 rm -f