-
Notifications
You must be signed in to change notification settings - Fork 3
/
gen.go
63 lines (56 loc) · 1.46 KB
/
gen.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"os"
"path/filepath"
"strings"
"text/template"
"github.com/jwijenbergh/puregotk/internal/gir/pass"
"github.com/jwijenbergh/puregotk/internal/gir/util"
)
//go:generate go run gen.go
func main() {
dir := "v4"
os.RemoveAll(dir)
var girs []string
filepath.Walk("internal/gir/spec", func(path string, f os.FileInfo, err error) error {
if !strings.HasSuffix(path, ".gir") {
return nil
}
girs = append(girs, path)
return nil
})
p, err := pass.New(girs)
if err != nil {
panic(err)
}
// collect basic type info
p.First()
// Create the template
gotemp, err := template.New("go").Funcs(template.FuncMap{"conv": util.ConvertArgs, "convc": util.ConvertArgsComma}).ParseFiles("templates/go")
if err != nil {
panic(err)
}
// Write go files by making the second pass
p.Second(dir, gotemp)
// Finally copy some extra code that we want in the API
data, err := os.ReadFile("templates/gobject")
if err == nil {
os.WriteFile("v4/gobject/more.go", data, 0o644)
}
data, err = os.ReadFile("templates/glib")
if err == nil {
os.WriteFile("v4/glib/more.go", data, 0o644)
}
data, err = os.ReadFile("templates/glib_sysv")
if err == nil {
os.WriteFile("v4/glib/more_sysv.go", data, 0o644)
}
data, err = os.ReadFile("templates/glib_windows")
if err == nil {
os.WriteFile("v4/glib/more_windows.go", data, 0o644)
}
data, err = os.ReadFile("templates/glib_other")
if err == nil {
os.WriteFile("v4/glib/more_other.go", data, 0o644)
}
}