Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

cmd/gb: verify the Go install has not changed #321

Merged
merged 1 commit into from
Aug 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/gb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package main

import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/constabulary/gb"
"github.com/constabulary/gb/cmd"
Expand Down Expand Up @@ -46,6 +49,9 @@ func main() {
help(args[2:])
return
}

verifyGoVersion()

command, ok := commands[name]
if (command != nil && !command.Runnable()) || !ok {
if _, err := lookupPlugin(name); err != nil {
Expand Down Expand Up @@ -105,3 +111,19 @@ func main() {
gb.Fatalf("command %q failed: %v", name, err)
}
}

// verify that the version of Go that compiled this binary is still correct.
func verifyGoVersion() {
want := runtime.Version()
filename := filepath.Join(runtime.GOROOT(), "VERSION")
if strings.Contains(want, "devel") {
filename += ".cache"
}
got, err := ioutil.ReadFile(filename)
if err != nil {
gb.Fatalf("cannot validate Go version: %v", err)
}
if want != string(got) {
gb.Fatalf("Go version does not match: gb was compiled with %q, installed Go version from %v is %q", want, runtime.GOROOT(), got)
}
}