Thanks for the responses.

I will try a few options and see what fit best.

For a bit of context I’m making a script to check if the entire toolchain 
needed to build a project is present on the machine. The script checks for 
node/npm, Go, GCC and a few other tools (like go-bindata eg.). The real 
challenge (atm) is minimum required versions and that this must run on Windows, 
Linux and macOS. A pragmatic solution would be to cut this effort short and 
have the team accept “if build fails, check that this list of tools is 
installed” (it is a <10 ppl team). Another option I’m toying is having the 
(up-to-date) toolchain in a container.

-- 
Michael Banzon
https://michaelbanzon.com/




> Den 10. aug. 2017 kl. 09.14 skrev Konstantin Khomoutov <kos...@bswap.ru>:
> 
> On Wed, Aug 09, 2017 at 03:11:48PM +0200, Michael Banzon wrote:
> 
>> Is there a way to have a (bash) script check if the version of the Go
>> compiler installed is a specific minimum version?
> 
> In the light of [1], I think you could combine checking of the presense
> of the `go` tool itself with build tags.
> Say, something like this (untested):
> 
> ---------------->8----------------
>  set -eu
> 
>  rc=0
>  go version >/dev/null || rc=$?
>  if [ $rc -ne 0 ]; then
>    echo "The 'go' tool is not available" >&2
>    exit 2
>  fi
> 
>  d=`mktemp -d`
>  f=`mktemp`
>  trap "rm -rf '$d' '$f'" EXIT INT TERM QUIT
>  cd "$d"
> 
>  cat >false.go <<'EOF'
>  // +build !go1.7
>  package main
> 
>  import "os"
> 
>  func main() {
>    os.Exit(1)
>  }
>  EOF
> 
>  cat >true.go <<'EOF'
>  // +build go1.7
>  package main
> 
>  import "os"
> 
>  func main() {
>    os.Exit(0)
>  }
>  EOF
> 
>  go build -o "$f" "$d/*.go"
> 
>  rc=0
>  "$f" || rc=1
> 
>  if [ $rc -ne 0 ]; then
>    echo "Insufficient Go version" >&2
>    exit 2
>  fi
> 
>  exit 0
> ---------------->8----------------
> 
> One possible caveat is that `mktemp` by default creates its filesystem
> entries under $TMPDIR or /tmp, and that directory might be mounted with
> "noexec" on certain systems.  So if your setup script (or whatever it
> is) has a luxury of using its own scratch space, you should probably do
> that (like creating a temp. directory using `mktemp -f ~/.cache/XXXXXX`
> or something like this).
> 
> 1. https://github.com/golang/go/issues/21207
> 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to