From ecba6e74571180240b0edfbab6f5415539e1b7eb Mon Sep 17 00:00:00 2001 From: Lee Avital Date: Thu, 29 Aug 2024 15:32:18 -0400 Subject: [PATCH] Avoid re-downloading and rebuilding gogo every time we run codegen Adds a `rake setup_gogo` task which will clone gogo into a new toolchains directory (which is git ignored). On every run of codegen, we'll checkout a pinned version of gogo and rebuild it. This should be pretty fast as long as gogo is already checked out. --- .github/workflows/test.yml | 2 +- .gitignore | 6 ++++- Rakefile | 53 ++++++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca997421..c3eb4fba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,7 +41,7 @@ jobs: uses: actions/setup-go@v3 with: go-version-file: "/home/runner/work/agent-payload/agent-payload/go/src/github.com/DataDog/agent-payload/go.mod" - - run: rake codegen + - run: rake codegen --trace env: GOPATH: "/home/runner/work/agent-payload/agent-payload/go" - name: Check for diffs diff --git a/.gitignore b/.gitignore index 6d888f88..a94ba100 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,8 @@ # jetbrains IDE directory /.idea/ -vendor/ \ No newline at end of file +vendor/ + +# build time dependencies that are either downloaded or +# built during codegen +toolchains/ diff --git a/Rakefile b/Rakefile index 380e1da3..15614123 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,8 @@ 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" @@ -12,8 +13,29 @@ protoc_jsonschema_version="73d5723" namespace :codegen do + task :clean do + sh "rm -rf #{gogo_dir}" + end + + task :setup_gogo => ['install_protoc'] 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 + cd #{gogo_dir}/src/github.com/gogo/protobuf + git checkout v1.3.2 + PATH=$PATH:/tmp GOBIN=#{gogo_bin} GOPATH=#{gogo_dir} make clean install +EOD + end + - task :install_protoc do + task 'install_protoc' => ['install_protoc_2', 'install_protoc_3'] + + task :install_protoc_3 => ['codegen:install_protoc_2'] do if `bash -c "protoc --version"` != "libprotoc ${protoc_version}" protoc_binary="/tmp/protoc#{protoc_version}" sh <<-EOF @@ -32,6 +54,10 @@ namespace :codegen do BASH EOF end + end + + + task :install_protoc_2 do if `bash -c "protoc --version"` != "libprotoc ${protoc_version_2}" protoc_binary_2="/tmp/protoc#{protoc_version_2}" sh <<-EOF @@ -49,40 +75,27 @@ BASH fi BASH EOF - end + end end - task :protoc => ['install_protoc'] do + task :protoc => ['install_protoc', 'setup_gogo'] do sh <<-EOF /bin/bash <