mirror of https://github.com/perkeep/perkeep.git
make.go: use first value of GOPATH
Fixes #1101 Change-Id: Ia6993d81f93b8aa64582d1b265d094fc7b232fc7
This commit is contained in:
parent
e5e29b004b
commit
b27ac3a71b
47
make.go
47
make.go
|
@ -30,6 +30,7 @@ import (
|
|||
"archive/zip"
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -378,6 +379,19 @@ func genWebUIJS() error {
|
|||
return genJS(pkg, output)
|
||||
}
|
||||
|
||||
func goPathBinDir() (string, error) {
|
||||
cmd := exec.Command("go", "env", "GOPATH")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not get GOPATH: %v, %s", err, out)
|
||||
}
|
||||
paths := filepath.SplitList(strings.TrimSpace(string(out)))
|
||||
if len(paths) < 1 {
|
||||
return "", errors.New("no GOPATH")
|
||||
}
|
||||
return filepath.Join(paths[0], "bin"), nil
|
||||
}
|
||||
|
||||
func genJS(pkg, output string) error {
|
||||
// We want to use 'gopherjs install', and not 'gopherjs build', as the former is
|
||||
// smarter and only rebuilds the output if needed. However, 'install' writes the
|
||||
|
@ -392,7 +406,11 @@ func genJS(pkg, output string) error {
|
|||
|
||||
// TODO(mpl): set GOBIN, and remove all below, once
|
||||
// https://github.com/gopherjs/gopherjs/issues/494 is fixed
|
||||
jsout := filepath.Join(os.Getenv("GOPATH"), "bin", filepath.Base(pkg)+".js")
|
||||
binDir, err := goPathBinDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsout := filepath.Join(binDir, filepath.Base(pkg)+".js")
|
||||
fi1, err1 := os.Stat(output)
|
||||
if err1 != nil && !os.IsNotExist(err1) {
|
||||
return err1
|
||||
|
@ -993,33 +1011,6 @@ func hostExeName(s string) string {
|
|||
return s
|
||||
}
|
||||
|
||||
// goPackagePath returns the path to the provided Go package's
|
||||
// source directory.
|
||||
// pkg may be a path prefix without any *.go files.
|
||||
// The error is os.ErrNotExist if GOPATH is unset or the directory
|
||||
// doesn't exist in any GOPATH component.
|
||||
func goPackagePath(pkg string) (path string, err error) {
|
||||
gp := os.Getenv("GOPATH")
|
||||
if gp == "" {
|
||||
return path, os.ErrNotExist
|
||||
}
|
||||
for _, p := range filepath.SplitList(gp) {
|
||||
dir := filepath.Join(p, "src", filepath.FromSlash(pkg))
|
||||
fi, err := os.Stat(dir)
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !fi.IsDir() {
|
||||
continue
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
return path, os.ErrNotExist
|
||||
}
|
||||
|
||||
// copied from pkg/osutil/paths.go
|
||||
func homeDir() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
|
|
Loading…
Reference in New Issue