1
2
3
4
5 package specgen
6
7 import (
8 "fmt"
9 "os"
10 "os/exec"
11 "path/filepath"
12 "strings"
13 )
14
15
16
17 func FindSpecDir() (string, error) {
18 goroot, err := goEnvGoroot()
19 if err != nil {
20 return "", fmt.Errorf("could not find GOROOT: %w", err)
21 }
22 path := filepath.Join(goroot, "src/simd/internal/spec")
23 if _, err := os.Stat(path); err != nil {
24 return "", fmt.Errorf("could not find spec package: %w (this tool requires a complete Go checkout)", err)
25 }
26 return path, nil
27 }
28
29 func MustFindSpecDir() string {
30 path, err := FindSpecDir()
31 if err != nil {
32 fmt.Fprintln(os.Stderr, err.Error())
33 os.Exit(1)
34 }
35 return path
36 }
37
38 func goEnvGoroot() (string, error) {
39 out, err := exec.Command("go", "env", "GOROOT").Output()
40 if err != nil {
41 return "", err
42 }
43 return strings.TrimSpace(string(out)), nil
44 }
45
View as plain text