mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Simplify find in codegen
The `find` tool has hard to comprehend syntax and does not consider things excluded by .gitignore. I keep tripping over this in my own repos, where I have __stuff which gets found. This converts update-codegen to use `git ls-files` in a seemingly equivalent way (`-cmo --exclude-standard`). I verified it finds the same set of files as before. This also drops some obsolete filtering. Also hide grep errors for not-found files, which can happen if a file is removed but git ls-files still knows it. Re-running update-codegen shows no diffs. This will make subsequent changes easier.
This commit is contained in:
parent
04c80d0a23
commit
b201c08cea
@ -42,65 +42,40 @@ if [[ "${DBG_CODEGEN}" == 1 ]]; then
|
|||||||
kube::log::status "DBG: starting generated_files"
|
kube::log::status "DBG: starting generated_files"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# This is a partial 'find' command. The caller is expected to pass the
|
function git_find() {
|
||||||
# remaining arguments.
|
# Similar to find but faster and easier to understand. We want to include
|
||||||
#
|
# modified and untracked files because this might be running against code
|
||||||
# Example:
|
# which is not tracked by git yet.
|
||||||
# kfind -type f -name foobar.go
|
git ls-files -cmo --exclude-standard "$@"
|
||||||
function kfind() {
|
|
||||||
# We want to include the "special" vendor directories which are actually
|
|
||||||
# part of the Kubernetes source tree (./staging/*) but we need them to be
|
|
||||||
# named as their ./vendor/* equivalents. Also, we do not want all of
|
|
||||||
# ./vendor nor ./hack/tools/vendor nor even all of ./vendor/k8s.io.
|
|
||||||
find -H . \
|
|
||||||
\( \
|
|
||||||
-not \( \
|
|
||||||
\( \
|
|
||||||
-name '_*' -o \
|
|
||||||
-name '.[^.]*' -o \
|
|
||||||
\( \
|
|
||||||
-name 'vendor' \
|
|
||||||
-type d \
|
|
||||||
\) -o \
|
|
||||||
\( \
|
|
||||||
-name 'testdata' \
|
|
||||||
-type d \
|
|
||||||
\) \
|
|
||||||
\) -prune \
|
|
||||||
\) \
|
|
||||||
\) \
|
|
||||||
"$@" \
|
|
||||||
| sed 's|^./staging/src|vendor|'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function find_all_go_dirs() {
|
function git_grep() {
|
||||||
kfind -type f -name \*.go \
|
# We want to include modified and untracked files because this might be
|
||||||
| sed 's|/[^/]*$||' \
|
# running against code which is not tracked by git yet.
|
||||||
| sed 's|^./||' \
|
git grep --untracked "$@"
|
||||||
| LC_ALL=C sort -u
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# This variable holds a list of every directory that contains Go files in this
|
|
||||||
# project. Other rules and variables can use this as a starting point to
|
|
||||||
# reduce filesystem accesses.
|
|
||||||
if [[ "${DBG_CODEGEN}" == 1 ]]; then
|
|
||||||
kube::log::status "DBG: finding all *.go dirs"
|
|
||||||
fi
|
|
||||||
ALL_GO_DIRS=()
|
|
||||||
kube::util::read-array ALL_GO_DIRS < <(find_all_go_dirs)
|
|
||||||
if [[ "${DBG_CODEGEN}" == 1 ]]; then
|
|
||||||
kube::log::status "DBG: found ${#ALL_GO_DIRS[@]} *.go dirs"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate a list of all files that have a `+k8s:` comment-tag. This will be
|
# Generate a list of all files that have a `+k8s:` comment-tag. This will be
|
||||||
# used to derive lists of files/dirs for generation tools.
|
# used to derive lists of files/dirs for generation tools.
|
||||||
|
#
|
||||||
|
# We want to include the "special" vendor directories which are actually part
|
||||||
|
# of the Kubernetes source tree (staging/*) but we need them to be named as
|
||||||
|
# their vendor/* equivalents. We do not want all of vendor nor
|
||||||
|
# hack/tools/vendor nor even all of vendor/k8s.io - just the subset that lives
|
||||||
|
# in staging.
|
||||||
if [[ "${DBG_CODEGEN}" == 1 ]]; then
|
if [[ "${DBG_CODEGEN}" == 1 ]]; then
|
||||||
kube::log::status "DBG: finding all +k8s: tags"
|
kube::log::status "DBG: finding all +k8s: tags"
|
||||||
fi
|
fi
|
||||||
ALL_K8S_TAG_FILES=()
|
ALL_K8S_TAG_FILES=()
|
||||||
kube::util::read-array ALL_K8S_TAG_FILES < <(
|
kube::util::read-array ALL_K8S_TAG_FILES < <(
|
||||||
find "${ALL_GO_DIRS[@]}" -maxdepth 1 -type f -name \*.go -print0 \
|
git_grep -l \
|
||||||
| xargs -0 grep --color=never -l '^// *+k8s:')
|
-e '^// *+k8s:' `# match +k8s: tags` \
|
||||||
|
-- \
|
||||||
|
':!:vendor/*' `# not under vendor` \
|
||||||
|
':!:*/testdata/*' `# not under any testdata` \
|
||||||
|
':(glob)**/*.go' `# in any *.go file` \
|
||||||
|
| sed 's|^staging/src|vendor|' `# see comments above` \
|
||||||
|
)
|
||||||
if [[ "${DBG_CODEGEN}" == 1 ]]; then
|
if [[ "${DBG_CODEGEN}" == 1 ]]; then
|
||||||
kube::log::status "DBG: found ${#ALL_K8S_TAG_FILES[@]} +k8s: tagged files"
|
kube::log::status "DBG: found ${#ALL_K8S_TAG_FILES[@]} +k8s: tagged files"
|
||||||
fi
|
fi
|
||||||
@ -593,13 +568,11 @@ function codegen::applyconfigs() {
|
|||||||
local applyconfigurationgen
|
local applyconfigurationgen
|
||||||
applyconfigurationgen=$(kube::util::find-binary "applyconfiguration-gen")
|
applyconfigurationgen=$(kube::util::find-binary "applyconfiguration-gen")
|
||||||
|
|
||||||
# because client-gen doesn't do policy/v1alpha1, we have to skip it too
|
|
||||||
local ext_apis=()
|
local ext_apis=()
|
||||||
kube::util::read-array ext_apis < <(
|
kube::util::read-array ext_apis < <(
|
||||||
cd "${KUBE_ROOT}/staging/src"
|
cd "${KUBE_ROOT}/staging/src"
|
||||||
find k8s.io/api -name types.go -print0 \
|
git_find -z ':(glob)k8s.io/api/**/types.go' \
|
||||||
| xargs -0 -n1 dirname \
|
| xargs -0 -n1 dirname \
|
||||||
| grep -v pkg.apis.policy.v1alpha1 \
|
|
||||||
| LC_ALL=C sort -u)
|
| LC_ALL=C sort -u)
|
||||||
ext_apis+=("k8s.io/apimachinery/pkg/apis/meta/v1")
|
ext_apis+=("k8s.io/apimachinery/pkg/apis/meta/v1")
|
||||||
|
|
||||||
@ -681,7 +654,7 @@ function codegen::listers() {
|
|||||||
local ext_apis=()
|
local ext_apis=()
|
||||||
kube::util::read-array ext_apis < <(
|
kube::util::read-array ext_apis < <(
|
||||||
cd "${KUBE_ROOT}/staging/src"
|
cd "${KUBE_ROOT}/staging/src"
|
||||||
find k8s.io/api -name types.go -print0 \
|
git_find -z ':(glob)k8s.io/api/**/types.go' \
|
||||||
| xargs -0 -n1 dirname \
|
| xargs -0 -n1 dirname \
|
||||||
| LC_ALL=C sort -u)
|
| LC_ALL=C sort -u)
|
||||||
|
|
||||||
@ -712,13 +685,11 @@ function codegen::informers() {
|
|||||||
local informergen
|
local informergen
|
||||||
informergen=$(kube::util::find-binary "informer-gen")
|
informergen=$(kube::util::find-binary "informer-gen")
|
||||||
|
|
||||||
# because client-gen doesn't do policy/v1alpha1, we have to skip it too
|
|
||||||
local ext_apis=()
|
local ext_apis=()
|
||||||
kube::util::read-array ext_apis < <(
|
kube::util::read-array ext_apis < <(
|
||||||
cd "${KUBE_ROOT}/staging/src"
|
cd "${KUBE_ROOT}/staging/src"
|
||||||
find k8s.io/api -name types.go -print0 \
|
git_find -z ':(glob)k8s.io/api/**/types.go' \
|
||||||
| xargs -0 -n1 dirname \
|
| xargs -0 -n1 dirname \
|
||||||
| grep -v pkg.apis.policy.v1alpha1 \
|
|
||||||
| LC_ALL=C sort -u)
|
| LC_ALL=C sort -u)
|
||||||
|
|
||||||
kube::log::status "Generating informer code for ${#ext_apis[@]} targets"
|
kube::log::status "Generating informer code for ${#ext_apis[@]} targets"
|
||||||
|
Loading…
Reference in New Issue
Block a user