aboutsummaryrefslogtreecommitdiffhomepage
path: root/target.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2018-09-24 12:25:33 +0200
committerAyke van Laethem <[email protected]>2018-09-24 12:25:33 +0200
commitfd6dda5e4ff4a7645293f6b3b0e4013471a719c7 (patch)
tree3c790cff007922051d4dd2e38376a0a9122389f0 /target.go
parent453450f40df0889a133f4b41199ab7176b3d7e9d (diff)
downloadtinygo-fd6dda5e4ff4a7645293f6b3b0e4013471a719c7.tar.gz
tinygo-fd6dda5e4ff4a7645293f6b3b0e4013471a719c7.zip
main: run the compiler from any path
Diffstat (limited to 'target.go')
-rw-r--r--target.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/target.go b/target.go
index 5f8a43b73..43a9700d5 100644
--- a/target.go
+++ b/target.go
@@ -34,7 +34,7 @@ func LoadTarget(target string) (*TargetSpec, error) {
// See whether there is a target specification for this target (e.g.
// Arduino).
- path := filepath.Join("targets", strings.ToLower(target)+".json")
+ path := filepath.Join(sourceDir(), "targets", strings.ToLower(target)+".json")
if fp, err := os.Open(path); err == nil {
defer fp.Close()
err := json.NewDecoder(fp).Decode(spec)
@@ -50,3 +50,11 @@ func LoadTarget(target string) (*TargetSpec, error) {
return spec, nil
}
+
+// Return the source directory of this package, or "." when it cannot be
+// recovered.
+func sourceDir() string {
+ // https://stackoverflow.com/a/32163888/559350
+ _, path, _, _ := runtime.Caller(0)
+ return filepath.Dir(path)
+}