// getGoPath returns first item in the GOPATH list // If there is no GOPATH set function sets GOPATH to ~/.srclib-gopath and returns ~/.srclib-gopath func getGoPath() string { list := os.Getenv("GOPATH") if list == "" { goPath := path.Join(util.CurrentUserHomeDir(), ".srclib-gopath") os.Setenv("GOPATH", goPath) return goPath } return filepath.SplitList(list)[0] }
func init() { if Path == "" { homeDir := util.CurrentUserHomeDir() if homeDir == "" { log.Fatalf("Fatal: No SRCLIBPATH and current user has no home directory.") } Path = filepath.Join(homeDir, ".srclib") if err := os.Setenv("SRCLIBPATH", Path); err != nil { log.Fatalf("Fatal: Could not set SRCLIBPATH environment variable to %q.", Path) } } if CacheDir == "" { dirs := filepath.SplitList(Path) CacheDir = filepath.Join(dirs[0], ".cache") } }
func installGoToolchain() error { const toolchain = "sourcegraph.com/sourcegraph/srclib-go" // Identify if Go is installed already or not. if _, err := exec.LookPath("go"); isExecErrNotFound(err) { return errors.New(` Refusing to install Go toolchain because Go is not installed or is not on the system path. -> Please install the latest version of Go (https://golang.org/doc/install) and run this command again.`) } else if err != nil { return err } if os.Getenv("GOPATH") == "" { os.Setenv("GOPATH", path.Join(util.CurrentUserHomeDir(), ".srclib-gopath")) } // Add symlink to GOPATH so install succeeds (necessary as long as there's a Go dependency in this toolchain) if err := symlinkToGopath(toolchain); err != nil { return err } srclibpathDir := filepath.Join(filepath.SplitList(srclib.Path)[0], toolchain) // toolchain dir under SRCLIBPATH if err := os.MkdirAll(filepath.Dir(srclibpathDir), 0700); err != nil { return err } log.Println("Downloading Go toolchain") if err := cloneToolchain(srclibpathDir, toolchain); err != nil { return err } log.Println("Building Go toolchain program") if err := execCmdInDir(srclibpathDir, "make"); err != nil { return err } return nil }