aboutsummaryrefslogtreecommitdiffhomepage
path: root/target.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2018-09-29 22:30:45 +0200
committerAyke van Laethem <[email protected]>2018-09-29 22:30:45 +0200
commitb6db84e916925b76251ad4aacef39f01a3baa57a (patch)
tree1ee792bbeaeb044b9635b5ed93e8cc1fb17f3fec /target.go
parent5bf058a0a61df64f6b150443926fd1456dafb432 (diff)
downloadtinygo-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.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/target.go b/target.go
index 43a9700d5..8f7a44cc2 100644
--- a/target.go
+++ b/target.go
@@ -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")
+}