diff options
author | Ayke van Laethem <[email protected]> | 2018-09-24 12:25:33 +0200 |
---|---|---|
committer | Ayke van Laethem <[email protected]> | 2018-09-24 12:25:33 +0200 |
commit | fd6dda5e4ff4a7645293f6b3b0e4013471a719c7 (patch) | |
tree | 3c790cff007922051d4dd2e38376a0a9122389f0 /target.go | |
parent | 453450f40df0889a133f4b41199ab7176b3d7e9d (diff) | |
download | tinygo-fd6dda5e4ff4a7645293f6b3b0e4013471a719c7.tar.gz tinygo-fd6dda5e4ff4a7645293f6b3b0e4013471a719c7.zip |
main: run the compiler from any path
Diffstat (limited to 'target.go')
-rw-r--r-- | target.go | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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) +} |