knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/hack/generate-knative.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2019 The Knative Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 # generate-knative generates everything for a project with external types only, e.g. a project based 22 # on CustomResourceDefinitions. 23 24 if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then 25 cat <<EOF 26 Usage: $(basename $0) <generators> <client-package> <apis-package> <groups-versions> ... 27 28 <generators> the generators comma separated to run (deepcopy,defaulter,client,lister,informer) or "all". 29 <client-package> the client package dir (e.g. github.com/example/project/pkg/clientset). 30 <apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). 31 <groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative 32 to <api-package>. 33 ... arbitrary flags passed to all generator binaries. 34 35 36 Examples: 37 $(basename $0) all github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" 38 $(basename $0) injection,foo github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" 39 EOF 40 exit 0 41 fi 42 43 GENS="$1" 44 CLIENT_PKG="$2" 45 APIS_PKG="$3" 46 GROUPS_WITH_VERSIONS="$4" 47 shift 4 48 49 function codegen::join() { local IFS="$1"; shift; echo "$*"; } 50 51 # enumerate group versions 52 FQ_APIS=() # e.g. k8s.io/api/apps/v1 53 for GVs in ${GROUPS_WITH_VERSIONS}; do 54 IFS=: read G Vs <<<"${GVs}" 55 56 # enumerate versions 57 for V in ${Vs//,/ }; do 58 FQ_APIS+=(${APIS_PKG}/${G}/${V}) 59 done 60 done 61 62 63 if grep -qw "injection" <<<"${GENS}"; then 64 if [[ -z "${OUTPUT_PKG:-}" ]]; then 65 OUTPUT_PKG="${CLIENT_PKG}/injection" 66 fi 67 68 if [[ -z "${VERSIONED_CLIENTSET_PKG:-}" ]]; then 69 VERSIONED_CLIENTSET_PKG="${CLIENT_PKG}/clientset/versioned" 70 fi 71 72 if [[ -z "${EXTERNAL_INFORMER_PKG:-}" ]]; then 73 EXTERNAL_INFORMER_PKG="${CLIENT_PKG}/informers/externalversions" 74 fi 75 76 if [[ -z "${LISTERS_PKG:-}" ]]; then 77 LISTERS_PKG="${CLIENT_PKG}/listers" 78 fi 79 80 echo "Generating injection for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}" 81 82 # Clear old injection 83 rm -rf ${OUTPUT_PKG} 84 85 MODULE_NAME=$(go list -m) 86 87 go run knative.dev/pkg/codegen/cmd/injection-gen \ 88 --input-dirs $(codegen::join , "${FQ_APIS[@]}") \ 89 --versioned-clientset-package ${VERSIONED_CLIENTSET_PKG} \ 90 --external-versions-informers-package ${EXTERNAL_INFORMER_PKG} \ 91 --listers-package ${LISTERS_PKG} \ 92 --output-package ${OUTPUT_PKG} \ 93 --output-dir ${OUTPUT_PKG//${MODULE_NAME}\//} \ 94 "$@" 95 fi