forked from zyedidia/micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
163 lines (142 loc) · 4.51 KB
/
magefile.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"github.com/magefile/mage/sh"
)
var (
GOOS, _ = sh.Output("go", "env", "GOHOSTOS")
GOARCH, _ = sh.Output("go", "env", "GOHOSTARCH")
VERSION, _ = sh.Output("go", "run", "tools/build-version.go")
HASH, _ = sh.Output("git", "rev-parse", "--short", "HEAD")
DATE, _ = sh.Output("go", "run", "tools/build-date.go")
GOBIN, _ = sh.Output("go", "env", "GOPATH)/bin")
DEBUGVAR = "-X github.com/zyedidia/micro/v2/internal/util.Debug=ON"
VSCODE_TESTS_BASE_URL = "'https://raw.githubusercontent.com/microsoft/vscode/e6a45f4242ebddb7aa9a229f85555e8a3bd987e2/src/vs/editor/test/common/model/'"
GOHOSTOS, _ = sh.Output("go", "env", "GOHOSTOS")
GOHOSTARCH, _ = sh.Output("go", "env", "GOHOSTARCH")
GOVARS = fmt.Sprintf("-X github.com/zyedidia/micro/v2/internal/util.Version=%s -X github.com/zyedidia/micro/v2/internal/util.CommitHash=%s -X 'github.com/zyedidia/micro/v2/internal/util.CompileDate=%s'", VERSION, HASH, DATE)
CGO_ENABLED, _ = sh.Output("go", "env", "CGO_ENABLED")
ADDITIONAL_GO_LINKER_FLAGS = ""
)
func init() {
if GOHOSTOS == "Darwin" {
DARWIN_FLAGS, _ := sh.Output(GOOS, GOARCH, "go", "run", "tools/info-plist.go", `"`+GOOS+`"`, `"`+VERSION+`"`)
ADDITIONAL_GO_LINKER_FLAGS += DARWIN_FLAGS
CGO_ENABLED = "1"
}
os.Setenv("GOOS", GOOS)
os.Setenv("GOARCH", GOARCH)
os.Setenv("CGO_ENABLED", CGO_ENABLED)
}
var Default = Build
func Build() {
Generate()
Build_quick()
}
func Build_quick() error {
flagld := fmt.Sprintf("-s -w %s %s", GOVARS, ADDITIONAL_GO_LINKER_FLAGS)
if err := sh.Run("go", "build", "-trimpath", "-ldflags="+flagld, "./cmd/micro"); err != nil {
return err
}
return nil
}
func Build_dbg() error {
flagld := fmt.Sprintf(`"%s"`, "%s %s", ADDITIONAL_GO_LINKER_FLAGS, DEBUGVAR)
if err := sh.Run("go", "build", "-trimpath", "-ldflags="+flagld, "./cmd/micro"); err != nil {
return err
}
return nil
}
func Build_tags() {
Fetch_tags()
Build()
}
func Build_all() {
Build()
}
func Install() error {
Generate()
flagld := fmt.Sprintf(`"%s"`, "-s -w %s %s", GOVARS, ADDITIONAL_GO_LINKER_FLAGS)
if err := sh.Run("go", "install", "-ldflags="+flagld, "./cmd/micro"); err != nil {
return err
}
return nil
}
func Install_all() {
Install()
}
func Fetch_tags() error {
if err := sh.Run("git", "fetch", "--tags", "--force"); err != nil {
return err
}
return nil
}
func Generate() error {
if err := sh.Run("go", "generate", "./runtime"); err != nil {
return err
}
return nil
}
func Testgen() error {
if err := sh.Run("mkdir", "-p", "tools/vscode-tests"); err != nil {
return err
}
if err := sh.Run("cd", "tools/vscode-tests", "&&", "curl", "--remote-name-all", VSCODE_TESTS_BASE_URL+"{editableTextModelAuto,editableTextModel,model.line}.test.ts"); err != nil {
return err
}
if err := sh.Run("tsc", "tools/vscode-tests/*.ts", ">", "/dev/null;", "true"); err != nil {
return err
}
if err := sh.Run("go", "run", "tools/testgen.go", "tools/vscode-tests/*.js", ">", "buffer_generated_test.go"); err != nil {
return err
}
if err := sh.Run("mv", "buffer_generated_test.go", "internal/buffer"); err != nil {
return err
}
if err := sh.Run("gofmt", "-w", "internal/buffer/buffer_generated_test.go"); err != nil {
return err
}
return nil
}
func Test() error {
if err := sh.Run("go", "test", "./internal/..."); err != nil {
return err
}
if err := sh.Run("go", "test", "./cmd/..."); err != nil {
return err
}
return nil
}
func Bench() error {
if err := sh.Run("for", "i", "in", "1", "2", "3;", "do", "go", "test", "-bench=.", "./internal/...;", "done", ">", "benchmark_results"); err != nil {
return err
}
if err := sh.Run("benchstat", "benchmark_results"); err != nil {
return err
}
return nil
}
func Bench_baseline() error {
if err := sh.Run("for", "i", "in", "1", "2", "3;", "do", "go", "test", "-bench=.", "./internal/...;", "done", ">", "benchmark_results_baseline"); err != nil {
return err
}
return nil
}
func Bench_compare() error {
if err := sh.Run("for", "i", "in", "1", "2", "3;", "do", "go", "test", "-bench=.", "./internal/...;", "done", ">", "benchmark_results"); err != nil {
return err
}
if err := sh.Run("benchstat", "-alpha", "0.15", "benchmark_results_baseline", "benchmark_results"); err != nil {
return err
}
return nil
}
func Clean() error {
if err := sh.Run("rm", "-f", "micro"); err != nil {
return err
}
return nil
}