github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/cloud/hack/generate-groups.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2017 The Kubernetes 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-groups 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> <output-package> <apis-package> <groups-versions> ... 27 <generators> the generators comma separated to run (deepcopy,defaulter,client,lister,informer) or "all". 28 <output-package> the output package name (e.g. github.com/example/project/pkg/generated). 29 <apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). 30 <groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative 31 to <api-package>. 32 ... arbitrary flags passed to all generator binaries. 33 Examples: 34 $(basename "$0") all github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" 35 $(basename "$0") deepcopy,client github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" 36 EOF 37 exit 0 38 fi 39 40 GENS="$1" 41 OUTPUT_PKG="$2" 42 APIS_PKG="$3" 43 GROUPS_WITH_VERSIONS="$4" 44 shift 4 45 46 ( 47 # To support running this script from anywhere, we have to first cd into this directory 48 # so we can install the tools. 49 cd "$(dirname "${0}")" 50 GO111MODULE=on GOFLAGS=-mod=vendor go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen} 51 ) 52 53 function codegen::join() { local IFS="$1"; shift; echo "$*"; } 54 55 # enumerate group versions 56 FQ_APIS=() # e.g. k8s.io/api/apps/v1 57 for GVs in ${GROUPS_WITH_VERSIONS}; do 58 IFS=: read -r G Vs <<<"${GVs}" 59 60 # enumerate versions 61 for V in ${Vs//,/ }; do 62 FQ_APIS+=("${APIS_PKG}/${G}/${V}") 63 done 64 done 65 66 if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then 67 echo "Generating deepcopy funcs" 68 "${GOPATH}/bin/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@" 69 fi 70 71 if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then 72 echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" 73 "${GOPATH}/bin/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@" 74 fi 75 76 if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then 77 echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers" 78 "${GOPATH}/bin/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@" 79 fi 80 81 if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then 82 echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers" 83 "${GOPATH}/bin/informer-gen" \ 84 --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \ 85 --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \ 86 --listers-package "${OUTPUT_PKG}/listers" \ 87 --output-package "${OUTPUT_PKG}/informers" \ 88 "$@" 89 fi