From 4d7546703a0df7d2b9133b319ae62369f98458e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 9 Apr 2023 21:44:48 +0100 Subject: [PATCH] update gotip in CI and fix -tiny on the latest tip printOneCgoTraceback now returns a boolean rather than an int. Since we need to have different logic based on the Go version, and toolchainVersionSemver was only set for the main process, move the string to the shared cache global. This is a nice thing to do anyway, to reduce the number of globals. While here, update actions/setup-go to v4, which starts caching GOMODCACHE and GOCACHE by default now. Disable it, because it still doesn't help in our case, and GitHub's Actions caching is still really inefficient. And update staticcheck too. --- .github/workflows/test.yml | 14 +++++++++----- main.go | 15 +++++---------- runtime_patch.go | 8 +++++++- shared.go | 7 +++++++ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fd41b97..bd45581 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,11 +11,14 @@ on: # as it runs many builds under the hood. # The default -timeout=10m can be hit by the hosted runners. # -# Also note that we don't use actions/cache for Go on purpose. +# Also note that we don't use Actions caching for Go on purpose. # Caching GOMODCACHE wouldn't help much, as we have few deps. # Caching GOCACHE would do more harm than good, # as the tests redo most of their work if the garble version changes, # and the majority of commits or PRs will do so. +# Moreover, GitHub saves and restores caches via compressed archives over the +# network, which means it can easily add one minute of overhead on its own for +# just a few hundred megabytes worth of files. name: Test jobs: @@ -27,10 +30,11 @@ jobs: os: [ubuntu-latest, macos-11, windows-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/setup-go@v3 + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v3 + cache: false - name: Test run: go test -timeout=15m ./... - uses: actions/upload-artifact@v3 @@ -60,7 +64,7 @@ jobs: - if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.20.x' uses: dominikh/staticcheck-action@v1 with: - version: "2023.1.2" + version: "2023.1.3" install-go: false # We don't care about GOARCH=386 particularly, @@ -84,7 +88,7 @@ jobs: steps: - name: Install Go env: - GO_COMMIT: 70f98a251efdbfd619c4ff466a43da299ad04752 # 2023-03-11 + GO_COMMIT: 231f290e51e130a1699d5c29d28133d68f43d2e9 # 2023-04-08 run: | cd $HOME mkdir $HOME/gotip diff --git a/main.go b/main.go index 24baa1a..44520e3 100644 --- a/main.go +++ b/main.go @@ -260,11 +260,6 @@ type errJustExit int func (e errJustExit) Error() string { return fmt.Sprintf("exit: %d", e) } -// toolchainVersionSemver is a semver-compatible version of the Go toolchain currently -// being used, as reported by "go env GOVERSION". -// Note that the version of Go that built the garble binary might be newer. -var toolchainVersionSemver string - func goVersionOK() bool { const ( minGoVersionSemver = "v1.20.0" @@ -275,7 +270,7 @@ func goVersionOK() bool { rxVersion := regexp.MustCompile(`go\d+\.\d+(?:\.\d+)?`) toolchainVersionFull := cache.GoEnv.GOVERSION - toolchainVersion := rxVersion.FindString(cache.GoEnv.GOVERSION) + toolchainVersion := rxVersion.FindString(toolchainVersionFull) if toolchainVersion == "" { // Go 1.15.x and older do not have GOVERSION yet. // We could go the extra mile and fetch it via 'go toolchainVersion', @@ -284,14 +279,14 @@ func goVersionOK() bool { return false } - toolchainVersionSemver = "v" + strings.TrimPrefix(toolchainVersion, "go") - if semver.Compare(toolchainVersionSemver, minGoVersionSemver) < 0 { + cache.GoVersionSemver = "v" + strings.TrimPrefix(toolchainVersion, "go") + if semver.Compare(cache.GoVersionSemver, minGoVersionSemver) < 0 { fmt.Fprintf(os.Stderr, "Go version %q is too old; please upgrade to Go %s or newer\n", toolchainVersionFull, suggestedGoVersion) return false } // Ensure that the version of Go that built the garble binary is equal or - // newer than toolchainVersionSemver. + // newer than cache.GoVersionSemver. builtVersionFull := os.Getenv("GARBLE_TEST_GOVERSION") if builtVersionFull == "" { builtVersionFull = runtime.Version() @@ -303,7 +298,7 @@ func goVersionOK() bool { return true } builtVersionSemver := "v" + strings.TrimPrefix(builtVersion, "go") - if semver.Compare(builtVersionSemver, toolchainVersionSemver) < 0 { + if semver.Compare(builtVersionSemver, cache.GoVersionSemver) < 0 { fmt.Fprintf(os.Stderr, "garble was built with %q and is being used with %q; please rebuild garble with the newer version\n", builtVersionFull, toolchainVersionFull) return false diff --git a/runtime_patch.go b/runtime_patch.go index a7a77a5..d53539f 100644 --- a/runtime_patch.go +++ b/runtime_patch.go @@ -9,6 +9,8 @@ import ( "strconv" "strings" + "golang.org/x/mod/semver" + ah "mvdan.cc/garble/internal/asthelper" ) @@ -236,7 +238,11 @@ func stripRuntime(basename string, file *ast.File) { "printAncestorTracebackFuncInfo", "goroutineheader", "tracebackothers", "tracebackHexdump", "printCgoTraceback": funcDecl.Body.List = nil case "printOneCgoTraceback": - funcDecl.Body = ah.BlockStmt(ah.ReturnStmt(ah.IntLit(0))) + if semver.Compare(cache.GoVersionSemver, "v1.21") >= 0 { + funcDecl.Body = ah.BlockStmt(ah.ReturnStmt(ast.NewIdent("false"))) + } else { + funcDecl.Body = ah.BlockStmt(ah.ReturnStmt(ah.IntLit(0))) + } default: if strings.HasPrefix(funcDecl.Name.Name, "print") { funcDecl.Body.List = nil diff --git a/shared.go b/shared.go index 2571a0d..c7f1e46 100644 --- a/shared.go +++ b/shared.go @@ -46,6 +46,13 @@ type sharedCache struct { GOGARBLE string + // GoVersionSemver is a semver-compatible version of the Go toolchain + // currently being used, as reported by "go env GOVERSION". + // Note that the version of Go that built the garble binary might be newer. + // Also note that a devel version like "go1.21-231f290e51" is + // currently represented as "v1.21". + GoVersionSemver string + // Filled directly from "go env". // Keep in sync with fetchGoEnv. GoEnv struct {