-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
42 lines (35 loc) · 851 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package libclang
// #include <clang-c/Index.h>
// #include <stdlib.h>
// #include <string.h>
import "C"
import (
"errors"
"fmt"
"log"
"os/exec"
"strings"
"unsafe"
)
func cxString(str C.CXString) string {
cString := C.strdup(C.clang_getCString(str))
defer C.free(unsafe.Pointer(cString))
C.clang_disposeString(str)
return C.GoString(cString)
}
func clangResourceDir() (string, error) {
out, err := exec.Command("clang", "-print-resource-dir").Output()
if err != nil {
log.Fatal(err)
}
resDir := strings.TrimSpace(string(out))
parts := strings.Split(resDir, "\n")
resDir = parts[0]
if resDir == "" {
return "", errors.New("no output when getting clang resource dir")
}
if !strings.HasPrefix(resDir, "/") {
return "", fmt.Errorf("expected clang resource dir to start with '/', but it %s", resDir)
}
return resDir, nil
}