main: run the compiler from any path

This commit is contained in:
Ayke van Laethem
2018-09-24 12:25:33 +02:00
parent 453450f40d
commit fd6dda5e4f
3 changed files with 15 additions and 5 deletions
+9 -1
View File
@@ -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)
}