From f7e6b7a817ed0dafc1226024e02bc5d266ecce0e Mon Sep 17 00:00:00 2001 From: Marcin Owsiany Date: Thu, 14 Nov 2019 11:01:01 -0800 Subject: [PATCH 1/2] Add support for GOBIN to generate-groups.sh. This still honors `$GOPATH` if it is set, but no longer requires it to be set, and also honors `$GOBIN` if it is set. Fixes https://github.com/kubernetes/code-generator/issues/87 --- staging/src/k8s.io/code-generator/generate-groups.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/staging/src/k8s.io/code-generator/generate-groups.sh b/staging/src/k8s.io/code-generator/generate-groups.sh index d82002ddafd..2bb077d0f56 100755 --- a/staging/src/k8s.io/code-generator/generate-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-groups.sh @@ -52,6 +52,8 @@ shift 4 cd "$(dirname "${0}")" go install ./cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen} ) +# We expect the above commands to get installed here: +gobin="$(go env GOBIN)" function codegen::join() { local IFS="$1"; shift; echo "$*"; } @@ -68,22 +70,22 @@ done if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then echo "Generating deepcopy funcs" - "${GOPATH}/bin/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@" + "${gobin}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@" fi if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" - "${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}" "$@" + "${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@" fi if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers" - "${GOPATH}/bin/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@" + "${gobin}/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@" fi if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers" - "${GOPATH}/bin/informer-gen" \ + "${gobin}/informer-gen" \ --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \ --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \ --listers-package "${OUTPUT_PKG}/listers" \ From d931b8434b0b923ad16ce9a033a832c4ee239f3e Mon Sep 17 00:00:00 2001 From: Marcin Owsiany Date: Mon, 18 Nov 2019 08:17:05 -0800 Subject: [PATCH 2/2] Tolerate unset $GOBIN --- staging/src/k8s.io/code-generator/generate-groups.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/code-generator/generate-groups.sh b/staging/src/k8s.io/code-generator/generate-groups.sh index 2bb077d0f56..1c2fd7a55bd 100755 --- a/staging/src/k8s.io/code-generator/generate-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-groups.sh @@ -52,8 +52,9 @@ shift 4 cd "$(dirname "${0}")" go install ./cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen} ) -# We expect the above commands to get installed here: -gobin="$(go env GOBIN)" +# Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise: +GOBIN="$(go env GOBIN)" +gobin="${GOBIN:-$(go env GOPATH)/bin}" function codegen::join() { local IFS="$1"; shift; echo "$*"; }