diff --git a/scripts/check-go-version.sh b/scripts/check-go-version.sh new file mode 100755 index 0000000000..ffeed7f2a6 --- /dev/null +++ b/scripts/check-go-version.sh @@ -0,0 +1,13 @@ +#!/bin/bash -e +# Ensure we use Go installed +if ! (hash go 2>/dev/null) ; then + echo "Could not find a Go installation, please install Go and try again." + exit 1; +fi + +# Ensure we use Go version 1.11+ +read major minor patch <<< $(go version | sed 's/go version go\([0-9]*\)\.\([0-9]*\)\.\(.*\) .*/\1 \2 \3/') +if [[ ${major} -ne 1 || ${minor} -lt 11 ]]; then + echo "Go 1.11+ is required (v$major.$minor.$patch is installed at `which go`)" + exit 1; +fi diff --git a/scripts/win/check-go-version.ps1 b/scripts/win/check-go-version.ps1 new file mode 100644 index 0000000000..e8674f4013 --- /dev/null +++ b/scripts/win/check-go-version.ps1 @@ -0,0 +1,17 @@ +if(-not (Get-Command "go" -errorAction SilentlyContinue)) +{ + $host.ui.WriteErrorLine("Could not find a Go installation, please install Go and try again.") + exit 1 +} + +$null = ((go version) -match "go version go(\d+)\.(\d+)\.([^ ]+)") +$major = $Matches[1] +$minor = $Matches[2] +$patch = $Matches[3] +$loc = (gcm go).Path + +if($major -ne 1 -or $minor -lt 11) +{ + $host.ui.WriteErrorLine("Go 1.11+ is required (v$major.$minor.$patch is installed at $loc)") + exit 1 +} diff --git a/setup_env.bat b/setup_env.bat index 39854a6388..c6dea97ae5 100644 --- a/setup_env.bat +++ b/setup_env.bat @@ -1,4 +1,7 @@ @echo off +PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& './scripts/win/check-go-version.ps1'" +if %ERRORLEVEL% GTR 0 exit /B 1 + call ./scripts/win/install-protobuf.bat go get github.com/golang/protobuf/protoc-gen-go diff --git a/setup_env.sh b/setup_env.sh index 877d2f6563..c11e24cf11 100755 --- a/setup_env.sh +++ b/setup_env.sh @@ -1,6 +1,8 @@ #!/bin/bash -e +./scripts/check-go-version.sh ./scripts/install-protobuf.sh +go mod download protobuf_path=$(go list -m -f '{{.Dir}}' github.com/golang/protobuf) echo "installing protoc-gen-go..." go install $protobuf_path/protoc-gen-go