Skip to content

Commit 9cbd1c2

Browse files
authored
refactor: support args and config using mage in v1.8.4-patch branch. (#686)
1 parent d94c8e4 commit 9cbd1c2

3 files changed

Lines changed: 73 additions & 12 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
require (
2727
github.com/livekit/protocol v1.10.1
2828
github.com/mitchellh/mapstructure v1.5.0
29-
github.com/openimsdk/gomake v0.0.14-alpha.5
29+
github.com/openimsdk/gomake v0.0.15-alpha.11
3030
github.com/openimsdk/protocol v0.0.72
3131
github.com/openimsdk/tools v0.0.50-alpha.65
3232
github.com/redis/go-redis/v9 v9.5.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA
213213
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
214214
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
215215
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
216-
github.com/openimsdk/gomake v0.0.14-alpha.5 h1:VY9c5x515lTfmdhhPjMvR3BBRrRquAUCFsz7t7vbv7Y=
217-
github.com/openimsdk/gomake v0.0.14-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
216+
github.com/openimsdk/gomake v0.0.15-alpha.11 h1:PQudYDRESYeYlUYrrLLJhYIlUPO5x7FAx+o5El9U/Bw=
217+
github.com/openimsdk/gomake v0.0.15-alpha.11/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
218218
github.com/openimsdk/protocol v0.0.72 h1:K+vslwaR7lDXyBzb07UuEQITaqsgighz7NyXVIWsu6A=
219219
github.com/openimsdk/protocol v0.0.72/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
220220
github.com/openimsdk/tools v0.0.50-alpha.65 h1:BRtxkyWxDWPHuHphSwEyHZj7kJSR98am/fHOH84naK8=

magefile.go

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,55 @@
44
package main
55

66
import (
7-
"github.com/openimsdk/gomake/mageutil"
7+
"flag"
88
"os"
9-
"strings"
9+
10+
"github.com/openimsdk/gomake/mageutil"
1011
)
1112

1213
var Default = Build
1314

15+
var Aliases = map[string]any{
16+
"buildcc": BuildWithCustomConfig,
17+
"startcc": StartWithCustomConfig,
18+
}
19+
20+
var (
21+
customRootDir = "." // workDir in mage, default is "./"(project root directory)
22+
customSrcDir = "cmd" // source code directory, default is "cmd"
23+
customOutputDir = "_output" // output directory, default is "_output"
24+
customConfigDir = "config" // configuration directory, default is "config"
25+
customToolsDir = "tools" // tools source code directory, default is "tools"
26+
)
27+
28+
// Build support specifical binary build.
29+
//
30+
// Example: `mage build chat-api chat-rpc check-component`
1431
func Build() {
15-
platforms := os.Getenv("PLATFORMS")
16-
if platforms == "" {
17-
platforms = mageutil.DetectPlatform()
32+
flag.Parse()
33+
bin := flag.Args()
34+
if len(bin) != 0 {
35+
bin = bin[1:]
1836
}
1937

20-
for _, platform := range strings.Split(platforms, " ") {
21-
mageutil.CompileForPlatform(platform)
38+
mageutil.Build(bin, nil)
39+
}
40+
41+
func BuildWithCustomConfig() {
42+
flag.Parse()
43+
bin := flag.Args()
44+
if len(bin) != 0 {
45+
bin = bin[1:]
46+
}
47+
48+
config := &mageutil.PathOptions{
49+
RootDir: &customRootDir,
50+
OutputDir: &customOutputDir,
51+
SrcDir: &customSrcDir,
52+
ToolsDir: &customToolsDir,
2253
}
2354

24-
mageutil.PrintGreen("All binaries under cmd and tools were successfully compiled.")
55+
mageutil.Build(bin, config)
2556
}
2657

2758
func Start() {
@@ -31,7 +62,37 @@ func Start() {
3162
mageutil.PrintRed("setMaxOpenFiles failed " + err.Error())
3263
os.Exit(1)
3364
}
34-
mageutil.StartToolsAndServices()
65+
66+
flag.Parse()
67+
bin := flag.Args()
68+
if len(bin) != 0 {
69+
bin = bin[1:]
70+
}
71+
72+
mageutil.StartToolsAndServices(bin, nil)
73+
}
74+
75+
func StartWithCustomConfig() {
76+
mageutil.InitForSSC()
77+
err := setMaxOpenFiles()
78+
if err != nil {
79+
mageutil.PrintRed("setMaxOpenFiles failed " + err.Error())
80+
os.Exit(1)
81+
}
82+
83+
flag.Parse()
84+
bin := flag.Args()
85+
if len(bin) != 0 {
86+
bin = bin[1:]
87+
}
88+
89+
config := &mageutil.PathOptions{
90+
RootDir: &customRootDir,
91+
OutputDir: &customOutputDir,
92+
ConfigDir: &customConfigDir,
93+
}
94+
95+
mageutil.StartToolsAndServices(bin, config)
3596
}
3697

3798
func Stop() {

0 commit comments

Comments
 (0)