formally add support for Go 1.16

This was pretty much just fixing the README and closing the issue. The
only other noteworthy user-facing change is that, if the Go version is
detected to be too old, we now suggest 1.16.x instead of 1.15.x.

While at it, refactor goversion.txt a bit. I wanted it to print a
clearer "mocking the go build" error if another command was used like
"go build", but I didn't want to learn BAT. So, instead use a simple Go
program and build it, which will work on all platforms. The added
"go build" step barely takes 100ms on my machine, given how simple the
program is.

The [short] line also doesn't seem necessary to me. The entire script
runs in under 200ms for me, so it's well within the realm of "short", at
least compared to many of the other test scripts.

Fixes #124.
pull/251/head
Daniel Martí 3 years ago
parent 081cba38d7
commit 09e244986e

@ -2,8 +2,7 @@
GO111MODULE=on go get mvdan.cc/garble
Obfuscate Go code by wrapping the Go toolchain. Requires Go 1.15.x; note that
support for Go 1.16 is [a work in progress](https://github.com/burrowers/garble/issues/124).
Obfuscate Go code by wrapping the Go toolchain. Requires Go 1.15 or later.
garble build [build flags] [packages]

@ -186,8 +186,8 @@ var errJustExit = errors.New("")
func goVersionOK() bool {
const (
minGoVersion = "v1.15.0"
supportedGoVersions = "1.15.x"
minGoVersion = "v1.15.0"
suggestedGoVersion = "1.16.x"
gitTimeFormat = "Mon Jan 2 15:04:05 2006 -0700"
)
@ -195,7 +195,8 @@ func goVersionOK() bool {
minGoVersionDate := time.Date(2020, 8, 11, 0, 0, 0, 0, time.UTC)
out, err := exec.Command("go", "version").CombinedOutput()
if err != nil {
rawVersion := strings.TrimSpace(string(out))
if err != nil || !strings.HasPrefix(rawVersion, "go version ") {
fmt.Fprintf(os.Stderr, `Can't get Go version: %v
This is likely due to go not being installed/setup correctly.
@ -205,7 +206,7 @@ How to install Go: https://golang.org/doc/install
return false
}
rawVersion := strings.TrimPrefix(strings.TrimSpace(string(out)), "go version ")
rawVersion = strings.TrimPrefix(rawVersion, "go version ")
tagIdx := strings.IndexByte(rawVersion, ' ')
tag := rawVersion[:tagIdx]
@ -230,13 +231,13 @@ How to install Go: https://golang.org/doc/install
return true
}
fmt.Fprintf(os.Stderr, "You use the old unstable %q Go version, please upgrade Go to %s\n", rawVersion, supportedGoVersions)
fmt.Fprintf(os.Stderr, "Go version %q is too old; please upgrade to Go %s or a newer devel version\n", rawVersion, suggestedGoVersion)
return false
}
version := "v" + strings.TrimPrefix(tag, "go")
if semver.Compare(version, minGoVersion) < 0 {
fmt.Fprintf(os.Stderr, "Outdated Go version %q is used, please upgrade Go to %s\n", version, supportedGoVersions)
fmt.Fprintf(os.Stderr, "Go version %q is too old; please upgrade to Go %s\n", rawVersion, suggestedGoVersion)
return false
}

@ -1,51 +1,68 @@
chmod 777 .bin/go
# We use a simple Go program to report many Go versions.
# The program also errors on any command other than "go version",
# which saves us having to rebuild main.go many times.
go build -o .bin/go$exe ./fakego
env PATH=${WORK}/.bin${:}${PATH}
# Check incorrect go install
# An empty go version.
env GO_VERSION=''
! garble build
stderr 'Can''t get Go version'
[short] stop
# Check invalid devel format
# An invalid devel string.
env GO_VERSION='go version devel someinvalidversion'
! garble build
stderr 'Can''t recognize devel build timestamp'
# Check invalid devel date
# An invalid devel date.
env GO_VERSION='go version devel +afb5fca Sun Sep 99 99:99:99 9999 +0000 linux/amd64'
! garble build
stderr 'Can''t recognize devel build timestamp: parsing time'
# Check invalid old devel version
# We should error on a devel version that's too old.
# We support Go 1.15 and later, released on August 11th, 2020.
env GO_VERSION='go version devel +afb5fca Sun Aug 07 00:00:00 2020 +0000 linux/amd64'
! garble build
stderr 'You use the old unstable'
stderr 'Go version.*Aug 07.*too old; please upgrade to Go 1.16.x or a newer devel version'
# Check invalid new devel version
# A recent enough devel timestamp should be fine.
env GO_VERSION='go version devel +afb5fca Sun Sep 13 07:54:42 2020 +0000 linux/amd64'
! garble build
! stderr 'You use the old unstable'
stderr 'mocking the real build'
# Check old version
# We should error on a stable version that's too old.
env GO_VERSION='go version go1.14 windows/amd64'
! garble build
stderr 'Outdated Go version'
stderr 'Go version.*go1.14.*too old; please upgrade to Go 1.16.x'
! stderr 'or a newer devel version'
# Check supported version
# We should accept a supported stable version.
env GO_VERSION='go version go1.15.2 windows/amd64'
! garble build
! stderr 'Outdated Go version'
stderr 'mocking the real build'
-- go.mod --
module test/main
go 1.15
-- main.go --
package main
-- .bin/go --
#!/bin/sh
func main() {}
-- fakego/main.go --
package main
[ -z "$GO_VERSION" ] && exit 1 || echo "$GO_VERSION"
import (
"fmt"
"os"
)
-- .bin/go.bat --
@echo off
IF DEFINED GO_VERSION (echo %GO_VERSION%) ELSE (exit 1)
func main() {
if len(os.Args) > 0 && os.Args[1] == "version" {
fmt.Println(os.Getenv("GO_VERSION"))
return
}
fmt.Fprintln(os.Stderr, "mocking the real build")
os.Exit(1)
}

Loading…
Cancel
Save