Codegen: subprojects: nuke existing files
This commit is contained in:
		@@ -83,11 +83,24 @@ fi
 | 
				
			|||||||
GOBIN="$(go env GOBIN)"
 | 
					GOBIN="$(go env GOBIN)"
 | 
				
			||||||
gobin="${GOBIN:-$(go env GOPATH)/bin}"
 | 
					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 "$*"; }
 | 
					function codegen::join() { local IFS="$1"; shift; echo "$*"; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# enumerate group versions
 | 
					# enumerate group versions
 | 
				
			||||||
ALL_FQ_APIS=() # e.g. k8s.io/kubernetes/pkg/apis/apps k8s.io/api/apps/v1
 | 
					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
 | 
					EXT_FQ_APIS=() # e.g. k8s.io/api/apps/v1
 | 
				
			||||||
 | 
					GROUP_VERSIONS=() # e.g. apps/v1
 | 
				
			||||||
for GVs in ${GROUPS_WITH_VERSIONS}; do
 | 
					for GVs in ${GROUPS_WITH_VERSIONS}; do
 | 
				
			||||||
  IFS=: read -r G Vs <<<"${GVs}"
 | 
					  IFS=: read -r G Vs <<<"${GVs}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -99,10 +112,18 @@ for GVs in ${GROUPS_WITH_VERSIONS}; do
 | 
				
			|||||||
  for V in ${Vs//,/ }; do
 | 
					  for V in ${Vs//,/ }; do
 | 
				
			||||||
    ALL_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
 | 
					    ALL_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
 | 
				
			||||||
    EXT_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
 | 
					    EXT_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
 | 
				
			||||||
 | 
					    GROUP_VERSIONS+=("${G}/${V}")
 | 
				
			||||||
  done
 | 
					  done
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "deepcopy" <<<"${GENS}"; then
 | 
					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"
 | 
					  echo "Generating deepcopy funcs"
 | 
				
			||||||
  "${gobin}/deepcopy-gen" \
 | 
					  "${gobin}/deepcopy-gen" \
 | 
				
			||||||
      --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
 | 
					      --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
 | 
				
			||||||
@@ -111,6 +132,13 @@ if grep -qw "deepcopy" <<<"${GENS}"; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "defaulter" <<<"${GENS}"; then
 | 
					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"
 | 
					  echo "Generating defaulters"
 | 
				
			||||||
  "${gobin}/defaulter-gen"  \
 | 
					  "${gobin}/defaulter-gen"  \
 | 
				
			||||||
      --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
					      --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
				
			||||||
@@ -119,6 +147,13 @@ if grep -qw "defaulter" <<<"${GENS}"; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "conversion" <<<"${GENS}"; then
 | 
					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"
 | 
					  echo "Generating conversions"
 | 
				
			||||||
  "${gobin}/conversion-gen" \
 | 
					  "${gobin}/conversion-gen" \
 | 
				
			||||||
      --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
 | 
					      --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
 | 
				
			||||||
@@ -127,8 +162,20 @@ if grep -qw "conversion" <<<"${GENS}"; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "applyconfiguration" <<<"${GENS}"; then
 | 
					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}"
 | 
					  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" \
 | 
					  "${gobin}/applyconfiguration-gen" \
 | 
				
			||||||
      --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
					      --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
				
			||||||
      --output-package "${APPLY_CONFIGURATION_PACKAGE}" \
 | 
					      --output-package "${APPLY_CONFIGURATION_PACKAGE}" \
 | 
				
			||||||
@@ -136,17 +183,44 @@ if grep -qw "applyconfiguration" <<<"${GENS}"; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "client" <<<"${GENS}"; then
 | 
					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" \
 | 
					  "${gobin}/client-gen" \
 | 
				
			||||||
      --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" \
 | 
					      --clientset-name "${CLIENTSET_NAME}" \
 | 
				
			||||||
      --input-base "" \
 | 
					      --input-base "" \
 | 
				
			||||||
      --input "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
					      --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:-}" \
 | 
					      --apply-configuration-package "${APPLY_CONFIGURATION_PACKAGE:-}" \
 | 
				
			||||||
      "$@"
 | 
					      "$@"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "lister" <<<"${GENS}"; then
 | 
					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"
 | 
					  echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
 | 
				
			||||||
  "${gobin}/lister-gen" \
 | 
					  "${gobin}/lister-gen" \
 | 
				
			||||||
      --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
					      --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
				
			||||||
@@ -155,16 +229,34 @@ if grep -qw "lister" <<<"${GENS}"; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "informer" <<<"${GENS}"; then
 | 
					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"
 | 
					  echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
 | 
				
			||||||
  "${gobin}/informer-gen" \
 | 
					  "${gobin}/informer-gen" \
 | 
				
			||||||
      --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
 | 
					      --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" \
 | 
					      --listers-package "${OUTPUT_PKG}/listers" \
 | 
				
			||||||
      --output-package "${OUTPUT_PKG}/informers" \
 | 
					      --output-package "${OUTPUT_PKG}/informers" \
 | 
				
			||||||
      "$@"
 | 
					      "$@"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if grep -qw "openapi" <<<"${GENS}"; then
 | 
					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"
 | 
					  echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
 | 
				
			||||||
  declare -a OPENAPI_EXTRA_PACKAGES
 | 
					  declare -a OPENAPI_EXTRA_PACKAGES
 | 
				
			||||||
  "${gobin}/openapi-gen" \
 | 
					  "${gobin}/openapi-gen" \
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user