Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix codegeneration that was wrong since the change of module name #363

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions hack/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,33 @@ set -e -x
# Note if you are not seeing generated code, most likely it's being placed into a different folder
# (e.g. Do you have GOPATH directory structure correctly named for this project?)

# Return a GOPATH to a temp directory. Works around the out-of-GOPATH issues
# for k8s client gen mixed with go mod.
# Intended to be used like:
# export GOPATH=$(go_mod_gopath_hack)
function go_mod_gopath_hack() {
local tmp_dir=$(mktemp -d)
local module="$(go list -m)"

local tmp_repo="${tmp_dir}/src/${module}"
mkdir -p "$(dirname ${tmp_repo})"
ln -s "$PWD" "${tmp_repo}"

echo "${tmp_dir}"
}
export GOPATH=$(go_mod_gopath_hack)
trap "rm -rf ${GOPATH}; git checkout vendor" EXIT

VENDIR_PKG=carvel.dev/vendir
# Based on vendor/k8s.io/code-generator/generate-groups.sh
#go run vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go \
echo "Generating deepcopy"
rm -f $(find pkg/vendir|grep zz_generated.deepcopy)
go run vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go \
--input-dirs carvel.dev/vendir/pkg/vendir/versions/v1alpha1 \
-O zz_generated.deepcopy \
--bounding-dirs carvel.dev/vendir/pkg/vendir \
--go-header-file ./hack/gen-boilerplate.txt
--input-dirs "${VENDIR_PKG}/pkg/vendir/versions/v1alpha1" \
--input-dirs "${KC_PKG}/pkg/vendir/versions" \
-O zz_generated.deepcopy \
--go-header-file hack/gen-boilerplate.txt

# Install protoc binary as directed by https://github.com/gogo/protobuf#installation
# (Chosen: https://github.com/protocolbuffers/protobuf/releases/download/v3.0.2/protoc-3.0.2-osx-x86_64.zip)
Expand All @@ -19,17 +40,18 @@ export PATH=$PWD/tmp/protoc-dl/bin/:$PATH
protoc --version

# Generate binaries called out by protoc binary
rm -rf tmp/gen-apiserver-bin/
mkdir -p tmp/gen-apiserver-bin/
go build -o tmp/gen-apiserver-bin/protoc-gen-gogo vendor/github.com/gogo/protobuf/protoc-gen-gogo/main.go
go build -o tmp/gen-apiserver-bin/protoc-gen-gofast vendor/github.com/gogo/protobuf/protoc-gen-gofast/main.go
go build -o tmp/gen-apiserver-bin/goimports vendor/golang.org/x/tools/cmd/goimports/{goimports,goimports_not_gc}.go
export PATH=$PWD/tmp/gen-apiserver-bin/:$PATH

go run vendor/k8s.io/code-generator/cmd/go-to-protobuf/main.go \
--proto-import vendor \
--packages "carvel.dev/vendir/pkg/vendir/versions/v1alpha1" \
--go-header-file ./hack/gen-boilerplate.txt

# TODO It seems that above command messes around with protos in vendor directory
git checkout vendor/
export GOBIN=$PWD/tmp/gen-apiserver-bin
rm -rf $GOBIN
go install \
github.com/gogo/protobuf/protoc-gen-gogo \
github.com/gogo/protobuf/protoc-gen-gofast \
golang.org/x/tools/cmd/goimports \
k8s.io/code-generator/cmd/go-to-protobuf
export PATH=$GOBIN:$PATH

rm -f $(find pkg/vendir|grep '\.proto')
go-to-protobuf \
--proto-import "${GOPATH}/src/${VENDIR_PKG}/vendor" \
--packages "${VENDIR_PKG}/pkg/vendir/versions/v1alpha1" \
--vendor-output-base="${GOPATH}/src/${VENDIR_PKG}/vendor" \
--go-header-file hack/gen-boilerplate.txt
141 changes: 52 additions & 89 deletions pkg/vendir/versions/v1alpha1/generated.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/vendir/versions/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading