-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathflags.go
More file actions
287 lines (257 loc) · 9.96 KB
/
flags.go
File metadata and controls
287 lines (257 loc) · 9.96 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package flags
import (
"flag"
"fmt"
"strconv"
"github.com/goplus/llgo/cmd/internal/compilerhash"
"github.com/goplus/llgo/internal/build"
"github.com/goplus/llgo/internal/buildenv"
)
var OutputFile string
var OutBin bool
var OutHex bool
var OutImg bool
var OutUf2 bool
var OutZip bool
func AddOutputFlags(fs *flag.FlagSet) {
fs.StringVar(&OutputFile, "o", "", "Output file")
fs.BoolVar(&OutBin, "obin", false, "Generate binary output (.bin)")
fs.BoolVar(&OutHex, "ohex", false, "Generate Intel hex output (.hex)")
fs.BoolVar(&OutImg, "oimg", false, "Generate image output (.img)")
fs.BoolVar(&OutUf2, "ouf2", false, "Generate UF2 output (.uf2)")
fs.BoolVar(&OutZip, "ozip", false, "Generate ZIP/DFU output (.zip)")
}
var Verbose bool
var BuildEnv string
var BuildMode string
var Tags string
var Target string
var Emulator bool
var Port string
var BaudRate int
var AbiMode int
var CheckLinkArgs bool
var CheckLLFiles bool
var GenLLFiles bool
var ForceEspClang bool
var SizeReport bool
var SizeFormat string
var SizeLevel string
var ForceRebuild bool
var PrintCommands bool
type optionalBool struct {
Specified bool
Value bool
}
func (o *optionalBool) String() string {
if !o.Specified {
return "auto"
}
return strconv.FormatBool(o.Value)
}
func (o *optionalBool) SetValue(v string) error {
val, err := strconv.ParseBool(v)
if err != nil {
return fmt.Errorf("invalid bool value %q", v)
}
o.Specified = true
o.Value = val
return nil
}
func (o *optionalBool) Set(v string) error {
return o.SetValue(v)
}
func (o *optionalBool) IsBoolFlag() bool {
return true
}
var LTO optionalBool
func AddLTOFlag(fs *flag.FlagSet) {
fs.Var(<O, "lto", "Enable LTO optimization (default: on for -target builds, off for non-target builds)")
}
func ResolveLTO(defaultValue bool) bool {
if LTO.Specified {
return LTO.Value
}
return defaultValue
}
const DefaultTestTimeout = "10m" // Matches Go's default test timeout
func AddCommonFlags(fs *flag.FlagSet) {
fs.BoolVar(&Verbose, "v", false, "Verbose output")
}
func AddBuildFlags(fs *flag.FlagSet) {
fs.BoolVar(&ForceRebuild, "a", false, "Force rebuilding of packages that are already up-to-date")
fs.BoolVar(&PrintCommands, "x", false, "Print the commands")
AddLTOFlag(fs)
fs.StringVar(&Tags, "tags", "", "Build tags")
fs.StringVar(&BuildEnv, "buildenv", "", "Build environment")
if buildenv.Dev {
fs.IntVar(&AbiMode, "abi", 2, "ABI mode (default 2). 0 = none, 1 = cfunc, 2 = allfunc.")
fs.BoolVar(&CheckLinkArgs, "check-linkargs", false, "check link args valid")
fs.BoolVar(&CheckLLFiles, "check-llfiles", false, "check .ll files valid")
fs.BoolVar(&GenLLFiles, "gen-llfiles", false, "generate .ll files for pkg export")
fs.BoolVar(&ForceEspClang, "force-espclang", false, "force to use esp-clang")
}
fs.BoolVar(&SizeReport, "size", false, "Print size report after build (default format=text, level=module)")
fs.StringVar(&SizeFormat, "size-format", "", "Size report format (text,json). Default text.")
fs.StringVar(&SizeLevel, "size-level", "", "Size report aggregation level (full,module,package). Default module.")
}
func AddBuildModeFlags(fs *flag.FlagSet) {
fs.StringVar(&BuildMode, "buildmode", "exe", "Build mode (exe, c-archive, c-shared)")
}
var Gen bool
var CompileOnly bool
// Test binary flags
var (
TestRun string
TestBench string
TestTimeout string
TestShort bool
TestCount int
TestCPU string
TestCover bool
TestCoverMode string
TestCoverProfile string
TestCoverPkg string
TestParallel int
TestFailfast bool
TestJSON bool
TestList string
TestSkip string
TestShuffle string
TestFullpath bool
TestBenchmem bool
TestBenchtime string
TestBlockProfileRate int
TestCPUProfile string
TestMemProfile string
TestMemProfileRate int
TestBlockProfile string
TestMutexProfile string
TestMutexProfileFrac int
TestTrace string
TestOutputDir string
TestPaniconexit0 bool
TestTestLogFile string
TestGoCoverDir string
TestFuzzWorker bool
TestFuzzCacheDir string
TestFuzz string
TestFuzzTime string
TestFuzzMinimizeTime string
)
func AddTestBinaryFlags(fs *flag.FlagSet) {
fs.StringVar(&TestRun, "run", "", "Run only tests matching the regular expression")
fs.StringVar(&TestBench, "bench", "", "Run benchmarks matching the regular expression")
fs.StringVar(&TestTimeout, "timeout", DefaultTestTimeout, "Test timeout duration (e.g., 10m, 30s)")
fs.BoolVar(&TestShort, "short", false, "Tell long-running tests to shorten their run time")
fs.IntVar(&TestCount, "count", 1, "Run each test and benchmark n times")
fs.StringVar(&TestCPU, "cpu", "", "Comma-separated list of GOMAXPROCS values for which the tests or benchmarks should be executed")
fs.BoolVar(&TestCover, "cover", false, "Enable coverage analysis")
fs.StringVar(&TestCoverMode, "covermode", "", "Coverage mode: set, count, atomic")
fs.StringVar(&TestCoverProfile, "coverprofile", "", "Write coverage profile to file")
fs.StringVar(&TestCoverPkg, "coverpkg", "", "Apply coverage analysis to packages matching the patterns")
fs.IntVar(&TestParallel, "parallel", 0, "Maximum number of tests to run simultaneously")
fs.BoolVar(&TestFailfast, "failfast", false, "Do not start new tests after the first test failure")
fs.BoolVar(&TestJSON, "json", false, "Log verbose output in JSON format")
fs.StringVar(&TestList, "list", "", "List tests, benchmarks, or examples matching the regular expression")
fs.StringVar(&TestSkip, "skip", "", "Skip tests matching the regular expression")
fs.StringVar(&TestShuffle, "shuffle", "", "Randomize the execution order of tests and benchmarks")
fs.BoolVar(&TestFullpath, "fullpath", false, "Show full file names in error messages")
fs.BoolVar(&TestBenchmem, "benchmem", false, "Print memory allocation statistics for benchmarks")
fs.StringVar(&TestBenchtime, "benchtime", "", "Run benchmarks for duration d (e.g., 1s, 100x)")
fs.IntVar(&TestBlockProfileRate, "blockprofilerate", 0, "Control the detail provided in goroutine blocking profiles by calling runtime.SetBlockProfileRate")
fs.StringVar(&TestCPUProfile, "cpuprofile", "", "Write a CPU profile to the specified file")
fs.StringVar(&TestMemProfile, "memprofile", "", "Write an allocation profile to the file")
fs.IntVar(&TestMemProfileRate, "memprofilerate", 0, "Enable more precise (and expensive) memory allocation profiles by setting runtime.MemProfileRate")
fs.StringVar(&TestBlockProfile, "blockprofile", "", "Write a goroutine blocking profile to the specified file")
fs.StringVar(&TestMutexProfile, "mutexprofile", "", "Write a mutex contention profile to the specified file")
fs.IntVar(&TestMutexProfileFrac, "mutexprofilefraction", 0, "Sample 1 in n stack traces of goroutines holding a contended mutex")
fs.StringVar(&TestTrace, "trace", "", "Write an execution trace to the specified file")
fs.StringVar(&TestOutputDir, "outputdir", "", "Write output files to the specified directory")
fs.BoolVar(&TestPaniconexit0, "paniconexit0", false, "Panic on call to os.Exit(0)")
fs.StringVar(&TestTestLogFile, "testlogfile", "", "Write test action log to file")
fs.StringVar(&TestGoCoverDir, "gocoverdir", "", "Directory where intermediate coverage files are written")
fs.BoolVar(&TestFuzzWorker, "fuzzworker", false, "Coordinate with the parent process to fuzz random values (for use only by cmd/go)")
fs.StringVar(&TestFuzzCacheDir, "fuzzcachedir", "", "Directory where interesting fuzzing inputs are stored (for use only by cmd/go)")
fs.StringVar(&TestFuzz, "fuzz", "", "Run the fuzz test matching the regular expression")
fs.StringVar(&TestFuzzTime, "fuzztime", "", "Run fuzzing for the specified duration (e.g., 10s, 1m)")
fs.StringVar(&TestFuzzMinimizeTime, "fuzzminimizetime", "", "Time to spend minimizing a value after finding a crash (default: 60s)")
}
func AddEmulatorFlags(fs *flag.FlagSet) {
fs.BoolVar(&Emulator, "emulator", false, "Run in emulator mode")
}
func AddTestFlags(fs *flag.FlagSet) {
fs.StringVar(&OutputFile, "o", "", "Compile test binary to the named file")
fs.BoolVar(&CompileOnly, "c", false, "Compile test binary but do not run it")
}
func AddEmbeddedFlags(fs *flag.FlagSet) {
fs.StringVar(&Target, "target", "", "Target platform (e.g., rp2040, wasi)")
fs.StringVar(&Port, "port", "", "Target port for flashing")
fs.IntVar(&BaudRate, "baudrate", 115200, "Baudrate for serial communication")
}
func AddCmpTestFlags(fs *flag.FlagSet) {
fs.BoolVar(&Gen, "gen", false, "Generate llgo.expect file")
}
func UpdateConfig(conf *build.Config) error {
conf.CompilerHash = compilerhash.Value()
conf.Tags = Tags
conf.Verbose = Verbose
conf.PrintCommands = PrintCommands
conf.Target = Target
conf.Port = Port
conf.BaudRate = BaudRate
conf.ForceRebuild = ForceRebuild
if LTO.Specified {
lto := LTO.Value
conf.LTO = <o
}
if SizeReport || SizeFormat != "" || SizeLevel != "" {
conf.SizeReport = true
if SizeFormat != "" {
conf.SizeFormat = SizeFormat
}
if SizeLevel != "" {
conf.SizeLevel = SizeLevel
}
}
switch conf.Mode {
case build.ModeBuild:
conf.OutFile = OutputFile
conf.OutFmts = build.OutFmts{
Bin: OutBin,
Hex: OutHex,
Img: OutImg,
Uf2: OutUf2,
Zip: OutZip,
}
case build.ModeRun:
conf.Emulator = Emulator
case build.ModeTest:
conf.OutFile = OutputFile
conf.CompileOnly = CompileOnly
conf.Emulator = Emulator
case build.ModeInstall:
case build.ModeCmpTest:
conf.Emulator = Emulator
conf.GenExpect = Gen
}
if buildenv.Dev {
conf.AbiMode = build.AbiMode(AbiMode)
conf.CheckLinkArgs = CheckLinkArgs
conf.CheckLLFiles = CheckLLFiles
conf.GenLL = GenLLFiles
conf.ForceEspClang = ForceEspClang
}
return nil
}
func UpdateBuildConfig(conf *build.Config) error {
// First apply common config
if err := UpdateConfig(conf); err != nil {
return err
}
if err := build.ValidateBuildMode(BuildMode); err != nil {
return err
}
conf.BuildMode = build.BuildMode(BuildMode)
return nil
}