github.com/openebs/api@v1.12.0/hack/update-codegen.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 # This file has been taken from https://github.com/kubernetes/code-generator/blob/master/generate-groups.sh 18 # A small modification is made in this file at line number 56. 19 20 set -o errexit 21 set -o nounset 22 set -o pipefail 23 24 # generate-groups generates everything for a project with external types only, e.g. a project based 25 # on CustomResourceDefinitions. 26 27 #Usage: $(basename $0) <generators> <output-package> <apis-package> <groups-versions> ... 28 # 29 # <generators> the generators comma separated to run (deepcopy,defaulter,client,lister,informer) or "all". 30 # <output-package> the output package name (e.g. github.com/example/project/pkg/generated). 31 # <apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). 32 # <groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative 33 # to <api-package>. 34 # ... arbitrary flags passed to all generator binaries. 35 # 36 # 37 #Examples: 38 # $(basename $0) all github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" 39 # $(basename $0) deepcopy,client github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" 40 41 ( 42 # To support running this script from anywhere, we have to first cd into this directory 43 # so we can install the tools. 44 #cd $(dirname "${0}") 45 cd vendor/k8s.io/code-generator/ 46 go install ./cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,conversion-gen,defaulter-gen} 47 ) 48 49 function codegen::join() { local IFS="$1"; shift; echo "$*"; } 50 51 module_name="github.com/openebs/api" 52 53 # Generate deepcopy functions for all internalapis and external APIs 54 deepcopy_inputs=( 55 pkg/apis/cstor/v1 \ 56 pkg/apis/openebs.io/v1alpha1 \ 57 pkg/internalapis/apis/cstor \ 58 pkg/internalapis/apis/openebs.io \ 59 ) 60 61 client_subpackage="pkg/client" 62 client_package="${module_name}/${client_subpackage}" 63 # Generate clientsets, listers and informers for user-facing API types 64 client_inputs=( 65 pkg/apis/cstor/v1 \ 66 pkg/apis/openebs.io/v1alpha1 \ 67 ) 68 69 # Generate defaulting functions to be used by the mutating webhook 70 defaulter_inputs=( 71 pkg/internalapis/apis/cstor/v1 \ 72 pkg/internalapis/apis/openebs.io/v1alpha1 \ 73 ) 74 75 # Generate conversion functions to be used by the conversion webhook 76 conversion_inputs=( 77 pkg/internalapis/apis/cstor/v1 \ 78 pkg/internalapis/apis/openebs.io/v1alpha1 \ 79 ) 80 81 82 gen-deepcopy() { 83 # clean pkg/apis 'zz_generated.deepcopy.go' 84 echo "Generating deepcopy methods..." >&2 85 prefixed_inputs=( "${deepcopy_inputs[@]/#/$module_name/}" ) 86 joined=$( IFS=$','; echo "${prefixed_inputs[*]}" ) 87 "${GOPATH}/bin/deepcopy-gen" \ 88 --go-header-file hack/custom-boilerplate.go.txt \ 89 --input-dirs "$joined" \ 90 --output-file-base zz_generated.deepcopy \ 91 --bounding-dirs "${module_name}" 92 # for dir in "${deepcopy_inputs[@]}"; do 93 # copyfiles "$dir" "zz_generated.deepcopy.go" 94 # done 95 } 96 97 gen-clientsets() { 98 # clean "${client_subpackage}"/clientset '*.go' 99 echo "Generating clientset..." >&2 100 prefixed_inputs=( "${client_inputs[@]/#/$module_name/}" ) 101 joined=$( IFS=$','; echo "${prefixed_inputs[*]}" ) 102 "${GOPATH}/bin/client-gen" \ 103 --go-header-file hack/custom-boilerplate.go.txt \ 104 --clientset-name versioned \ 105 --input-base "" \ 106 --input "$joined" \ 107 --output-package "${client_package}"/clientset 108 # copyfiles "${client_subpackage}/clientset" "*.go" 109 } 110 111 gen-listers() { 112 # clean "${client_subpackage}/listers" '*.go' 113 echo "Generating listers..." >&2 114 prefixed_inputs=( "${client_inputs[@]/#/$module_name/}" ) 115 joined=$( IFS=$','; echo "${prefixed_inputs[*]}" ) 116 "${GOPATH}/bin/lister-gen" \ 117 --go-header-file hack/custom-boilerplate.go.txt \ 118 --input-dirs "$joined" \ 119 --output-package "${client_package}"/listers 120 # copyfiles "${client_subpackage}/listers" "*.go" 121 } 122 123 gen-informers() { 124 # clean "${client_subpackage}"/informers '*.go' 125 echo "Generating informers..." >&2 126 prefixed_inputs=( "${client_inputs[@]/#/$module_name/}" ) 127 joined=$( IFS=$','; echo "${prefixed_inputs[*]}" ) 128 "${GOPATH}/bin/informer-gen" \ 129 --go-header-file hack/custom-boilerplate.go.txt \ 130 --input-dirs "$joined" \ 131 --versioned-clientset-package "${client_package}"/clientset/versioned \ 132 --listers-package "${client_package}"/listers \ 133 --output-package "${client_package}"/informers 134 # copyfiles "${client_subpackage}/informers" "*.go" 135 } 136 137 gen-defaulters() { 138 # clean pkg/internalapis/apis 'zz_generated.defaults.go' 139 echo "Generating defaulting functions..." >&2 140 prefixed_inputs=( "${defaulter_inputs[@]/#/$module_name/}" ) 141 joined=$( IFS=$','; echo "${prefixed_inputs[*]}" ) 142 "${GOPATH}/bin/defaulter-gen" \ 143 --go-header-file hack/custom-boilerplate.go.txt \ 144 --input-dirs "$joined" \ 145 -O zz_generated.defaults 146 # for dir in "${defaulter_inputs[@]}"; do 147 # copyfiles "$dir" "zz_generated.defaults.go" 148 # done 149 } 150 151 gen-conversions() { 152 # clean pkg/internalapis/apis 'zz_generated.conversion.go' 153 echo "Generating conversion functions..." >&2 154 prefixed_inputs=( "${conversion_inputs[@]/#/$module_name/}" ) 155 joined=$( IFS=$','; echo "${prefixed_inputs[*]}" ) 156 "${GOPATH}/bin/conversion-gen" \ 157 --go-header-file hack/custom-boilerplate.go.txt \ 158 --input-dirs "$joined" \ 159 -O zz_generated.conversion 160 # for dir in "${conversion_inputs[@]}"; do 161 # copyfiles "$dir" "zz_generated.conversion.go" 162 # done 163 } 164 165 gen-deepcopy 166 gen-clientsets 167 gen-listers 168 gen-informers 169 gen-defaulters 170 gen-conversions