-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (44 loc) · 1.17 KB
/
main.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
package main
import (
"go/build"
"log"
"os"
"os/exec"
"path/filepath"
"github.com/gobuffalo/packr/v2"
)
func main() {
box := packr.New("static files", "./static")
pkg, err := build.Default.Import("cmd", "", build.FindOnly)
if err != nil {
log.Fatal(err)
}
writeFile(pkg.Dir, "/trace/trace.go", box, "trace.go")
writeFile(pkg.Dir, "/../../misc/trace/trace_viewer_full.html", box, "trace_viewer_full.html")
writeFile(pkg.Dir, "/../../misc/trace/webcomponents.min.js", box, "webcomponents.min.js")
log.Printf("running command: go install cmd/trace ...")
c, err := exec.Command("go", "install", "cmd/trace").CombinedOutput()
if err != nil {
log.Fatal(string(c), err)
}
}
func writeFile(dir, path string, box *packr.Box, name string) {
b, err := box.Find(name)
if err != nil {
log.Fatal(err)
}
filePath := dir + filepath.FromSlash(path)
file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
log.Fatal(err)
}
defer file.Close()
log.Printf("patching file %s ...\n", filePath)
n, err := file.Write(b)
if err != nil {
log.Fatal(err)
}
if n != len(b) {
log.Fatalf("write length: %d, should be: %d\n", n, len(b))
}
}