Use relative GOPATH for microfactory golang builds.
Bug: b/336890676 Change-Id: I15ff839986d6c4997d5abccaa2ae8a9703d6cfb6
This commit is contained in:
parent
36b6322979
commit
c10b49b5e9
1 changed files with 26 additions and 0 deletions
|
@ -68,8 +68,25 @@ var (
|
||||||
goToolDir = filepath.Join(runtime.GOROOT(), "pkg", "tool", runtime.GOOS+"_"+runtime.GOARCH)
|
goToolDir = filepath.Join(runtime.GOROOT(), "pkg", "tool", runtime.GOOS+"_"+runtime.GOARCH)
|
||||||
goVersion = findGoVersion()
|
goVersion = findGoVersion()
|
||||||
isGo18 = strings.Contains(goVersion, "go1.8")
|
isGo18 = strings.Contains(goVersion, "go1.8")
|
||||||
|
relGoRoot = runtime.GOROOT()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// make the GoRoot relative
|
||||||
|
if filepath.IsAbs(relGoRoot) {
|
||||||
|
pwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to get the current directory: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
relGoRoot, err = filepath.Rel(pwd, relGoRoot)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to get the GOROOT relative path: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func findGoVersion() string {
|
func findGoVersion() string {
|
||||||
if version, err := ioutil.ReadFile(filepath.Join(runtime.GOROOT(), "VERSION")); err == nil {
|
if version, err := ioutil.ReadFile(filepath.Join(runtime.GOROOT(), "VERSION")); err == nil {
|
||||||
return string(version)
|
return string(version)
|
||||||
|
@ -401,6 +418,9 @@ func (p *GoPackage) Compile(config *Config, outDir string) error {
|
||||||
"-o", p.output,
|
"-o", p.output,
|
||||||
"-p", p.Name,
|
"-p", p.Name,
|
||||||
"-complete", "-pack", "-nolocalimports")
|
"-complete", "-pack", "-nolocalimports")
|
||||||
|
cmd.Env = []string{
|
||||||
|
"GOROOT=" + relGoRoot,
|
||||||
|
}
|
||||||
if !isGo18 && !config.Race {
|
if !isGo18 && !config.Race {
|
||||||
cmd.Args = append(cmd.Args, "-c", fmt.Sprintf("%d", runtime.NumCPU()))
|
cmd.Args = append(cmd.Args, "-c", fmt.Sprintf("%d", runtime.NumCPU()))
|
||||||
}
|
}
|
||||||
|
@ -538,6 +558,9 @@ func (p *GoPackage) Link(config *Config, out string) error {
|
||||||
}
|
}
|
||||||
cmd.Args = append(cmd.Args, p.output)
|
cmd.Args = append(cmd.Args, p.output)
|
||||||
cmd.Stdin = nil
|
cmd.Stdin = nil
|
||||||
|
cmd.Env = []string{
|
||||||
|
"GOROOT=" + relGoRoot,
|
||||||
|
}
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if config.Verbose {
|
if config.Verbose {
|
||||||
|
@ -605,6 +628,9 @@ func rebuildMicrofactory(config *Config, mybin string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(mybin, os.Args[1:]...)
|
cmd := exec.Command(mybin, os.Args[1:]...)
|
||||||
|
cmd.Env = []string{
|
||||||
|
"GOROOT=" + relGoRoot,
|
||||||
|
}
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
Loading…
Reference in a new issue