-
Notifications
You must be signed in to change notification settings - Fork 1
/
magefile.go
85 lines (70 loc) · 1.52 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
// +build mage
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/magefile/mage/target"
)
type BUILD mg.Namespace
func Clean() {
os.RemoveAll("build")
}
func Build() {
b := BUILD{}
mg.Deps(b.GIO, b.Fyne)
}
func (b BUILD) GIO() error {
sources := []string{
"./gio/counter",
"./gio/temperature-converter",
"./gio/timer",
}
goexe := mg.GoCmd()
for _, source := range sources {
if err := b.build(goexe, source); err != nil {
return err
}
}
return nil
}
func (b BUILD) Fyne() error {
sources := []string{
"./fyne/counter",
"./fyne/temperature-converter",
"./fyne/timer",
}
goexe := mg.GoCmd()
for _, source := range sources {
if err := b.build(goexe, source); err != nil {
return err
}
}
return nil
}
func (BUILD) build(goexe, source string) error {
dir := filepath.Join("build", filepath.Dir(source))
file := filepath.Join("build", source)
if modified, err := target.Dir(file, source); err != nil {
return fmt.Errorf("check target modified error: %w", err)
} else if !modified {
return nil
}
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return fmt.Errorf("mkdir error: %w", err)
}
if err := sh.RunV(goexe, "generate", source); err != nil {
return err
}
ldflags := "-s -w"
if runtime.GOOS == "windows" {
ldflags = ldflags + " -H windowsgui"
}
return sh.RunV(goexe, "build", "-trimpath", "-ldflags", ldflags, "-o", file, source)
}
func UPX() {
_ = sh.RunV("sh", "-c", "upx build/**/*")
}