Skip to content

Commit

Permalink
Fix building older versions of go
Browse files Browse the repository at this point in the history
Set GOROOT_BOOTSTRAP based on GOROOT
  • Loading branch information
urso committed Jul 6, 2018
1 parent f20fe4a commit c7912f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gvm
import (
"bufio"
"io"
"os"
"os/exec"
"sync"

Expand All @@ -13,6 +14,7 @@ type command struct {
Path string
Args []string
Dir string
Env []string
Stdout func(string)
Stderr func(string)
}
Expand Down Expand Up @@ -55,6 +57,10 @@ func (c *command) Exec() error {
cmd := exec.Command(c.Path, c.Args...)
cmd.Dir = c.Dir

if len(c.Env) > 0 {
cmd.Env = append(os.Environ(), c.Env...)
}

var err error
var stdout, stderr io.ReadCloser
if c.Stdout != nil {
Expand Down
14 changes: 13 additions & 1 deletion srcrepo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gvm

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -123,9 +124,17 @@ func buildGo(log logrus.FieldLogger, buildDir, repo, version, tag string) error
return err
}

bootstrap := os.Getenv("GOROOT_BOOTSTRAP")
if bootstrap == "" {
bootstrap = os.Getenv("GOROOT")
if bootstrap == "" {
return errors.New("GOROOT or GOROOT_BOOTSTRAP must be set")
}
}

if version != "tip" {
// write VERSION file
versionFile := filepath.Join(tmp, "go", "VERSION")
versionFile := filepath.Join(tmp, "VERSION")
err := ioutil.WriteFile(versionFile, []byte(version), 0644)
if err != nil {
return err
Expand All @@ -145,6 +154,9 @@ func buildGo(log logrus.FieldLogger, buildDir, repo, version, tag string) error
} else {
cmd = makeCommand("bash", "make.bash")
}
cmd.Env = []string{
"GOROOT_BOOTSTRAP=" + bootstrap,
}
return cmd.WithDir(srcDir).WithLogger(log).Exec()
}

Expand Down

0 comments on commit c7912f5

Please sign in to comment.