diff options
author | Ayke van Laethem <[email protected]> | 2018-09-29 22:30:45 +0200 |
---|---|---|
committer | Ayke van Laethem <[email protected]> | 2018-09-29 22:30:45 +0200 |
commit | b6db84e916925b76251ad4aacef39f01a3baa57a (patch) | |
tree | 1ee792bbeaeb044b9635b5ed93e8cc1fb17f3fec /target.go | |
parent | 5bf058a0a61df64f6b150443926fd1456dafb432 (diff) | |
download | tinygo-b6db84e916925b76251ad4aacef39f01a3baa57a.tar.gz tinygo-b6db84e916925b76251ad4aacef39f01a3baa57a.zip |
main: use GOPATH from the environment
Be more compatible with the Go toolchain by setting GOPATH in the same
way. This makes it possible to flash and run examples from the standard
GOPATH instead of only from the source tree.
Diffstat (limited to 'target.go')
-rw-r--r-- | target.go | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -58,3 +58,24 @@ func sourceDir() string { _, path, _, _ := runtime.Caller(0) return filepath.Dir(path) } + +func getGopath() string { + gopath := os.Getenv("GOPATH") + if gopath != "" { + return gopath + } + + // fallback + var home string + if runtime.GOOS == "windows" { + home = os.Getenv("USERPROFILE") + } else { + home = os.Getenv("HOME") + } + if home == "" { + // This is very unlikely, so panic here. + // Not the nicest solution, however. + panic("no $HOME or %USERPROFILE% found") + } + return filepath.Join(home, "go") +} |