Skip to content

Commit

Permalink
Avoid re-downloading and rebuilding gogo every time we run codegen
Browse files Browse the repository at this point in the history
This is a quality of life change to make running `rake codegen` locally faster
  • Loading branch information
leeavital committed Aug 29, 2024
1 parent 22f3ea6 commit 967aa09
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
# jetbrains IDE directory
/.idea/

vendor/
vendor/

# build time dependencies that are either downloaded or
# built during codegen
toolchains/
42 changes: 24 additions & 18 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@

protoc_binary="protoc"
protoc_version="3.5.1"
gogo_dir="/tmp/gogo"
gogo_dir=Dir.pwd + "/toolchains/gogo"
gogo_bin=Dir.pwd + "/toolchains/gogo-bin-v1.3.2"
protoc_binary_2="protoc"
protoc_version_2="21.12"
protoc_gen_go_dir="/tmp/protoc-gen-go"
protoc_jsonschema_version="73d5723"


namespace :codegen do
task :clean do
sh "rm -rf #{gogo_dir}"
end

task :setup_gogo do
if ! Dir.exist?(gogo_dir) then
sh "mkdir -p #{gogo_dir}/src/github.com/gogo"
sh "git clone https://github.com/gogo/protobuf.git #{gogo_dir}/src/github.com/gogo/protobuf"
else
puts "gogo already cloned into #{gogo_dir}"
end
sh <<-EOD
# Install v1.3.2
pushd #{gogo_dir}/src/github.com/gogo/protobuf
git checkout v1.3.2
GOBIN=#{gogo_bin} GOPATH=#{gogo_dir} make clean install
EOD
end

task :install_protoc do
if `bash -c "protoc --version"` != "libprotoc ${protoc_version}"
Expand Down Expand Up @@ -52,37 +71,24 @@ BASH
end
end

task :protoc => ['install_protoc'] do
task :protoc => ['install_protoc', 'setup_gogo'] do
sh <<-EOF
/bin/bash <<BASH
set -euo pipefail
export GO111MODULE=auto
rm -rf #{gogo_dir}
rm -rf /tmp/gogo-bin-*
mkdir -p #{gogo_dir}/src/github.com/gogo
git clone https://github.com/gogo/protobuf.git #{gogo_dir}/src/github.com/gogo/protobuf
# Install v1.3.2
pushd #{gogo_dir}/src/github.com/gogo/protobuf
git checkout v1.3.2
GOBIN=/tmp/gogo-bin-v1.3.2 GOPATH=#{gogo_dir} make clean install
popd
echo "Generating logs proto"
PATH=/tmp/gogo-bin-v1.3.2 #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src --java_out=java proto/logs/agent_logs_payload.proto
PATH=#{gogo_bin} #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src --java_out=java proto/logs/agent_logs_payload.proto
echo "Generating metrics proto (go)"
PATH=/tmp/gogo-bin-v1.3.2 #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src proto/metrics/agent_payload.proto
PATH=#{gogo_bin} #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src proto/metrics/agent_payload.proto
echo "Generating metrics proto (python)"
#{protoc_binary} --proto_path=#{gogo_dir}/src:$GOPATH/src:./proto/metrics --python_out=python agent_payload.proto
echo "Generating process proto (go)"
PATH=/tmp/gogo-bin-v1.3.2 #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofaster_out=$GOPATH/src proto/process/*.proto
PATH=#{gogo_bin} #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofaster_out=$GOPATH/src proto/process/*.proto
GOPATH=#{protoc_gen_go_dir} go install github.com/leeavital/protoc-gen-gostreamer@v0.1.0
PATH=#{protoc_gen_go_dir}/bin #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gostreamer_out=$GOPATH/src proto/process/*.proto
Expand Down

0 comments on commit 967aa09

Please sign in to comment.