diff options
author | Dan Willemsen <dwillemsen@google.com> | 2017-02-22 22:03:04 -0800 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2017-02-22 22:03:04 -0800 |
commit | fde85346800d5a02be773b18c018c87127272ebf (patch) | |
tree | b4325970df1c47265c1f2fc8d1f9ae48814ecb45 /cmd | |
parent | fd96d2421a5057621c4bb0c1f0ea6808de555dca (diff) | |
download | build_soong-fde85346800d5a02be773b18c018c87127272ebf.tar.gz build_soong-fde85346800d5a02be773b18c018c87127272ebf.tar.bz2 build_soong-fde85346800d5a02be773b18c018c87127272ebf.zip |
Don't use runtime.Version() to find the current go version
That will be the go version at compile time. So read $GOROOT/VERSION, or
fall back to executing `$GOROOT/bin/go version` to find the go version
currently in GOROOT.
Test: Ensure everything rebuilds when switching between go1.8rc2 and go1.8
Change-Id: I8738a7aa249a088b1e0668af260fa3974844dab7
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/microfactory/microfactory.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/cmd/microfactory/microfactory.go b/cmd/microfactory/microfactory.go index 3ed5a2c3..d0febe77 100644 --- a/cmd/microfactory/microfactory.go +++ b/cmd/microfactory/microfactory.go @@ -67,8 +67,22 @@ var ( verbose = false goToolDir = filepath.Join(runtime.GOROOT(), "pkg", "tool", runtime.GOOS+"_"+runtime.GOARCH) + goVersion = findGoVersion() ) +func findGoVersion() string { + if version, err := ioutil.ReadFile(filepath.Join(runtime.GOROOT(), "VERSION")); err == nil { + return string(version) + } + + cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "version") + if version, err := cmd.Output(); err == nil { + return string(version) + } else { + panic(fmt.Sprintf("Unable to discover go version: %v", err)) + } +} + type GoPackage struct { Name string @@ -218,7 +232,7 @@ func (p *GoPackage) Compile(outDir, trimPath string) error { shaFile := p.output + ".hash" hash := sha1.New() - fmt.Fprintln(hash, runtime.GOOS, runtime.GOARCH, runtime.Version()) + fmt.Fprintln(hash, runtime.GOOS, runtime.GOARCH, goVersion) cmd := exec.Command(filepath.Join(goToolDir, "compile"), "-o", p.output, |