remove debug flags by default

This commit is contained in:
Timon Ringwald 2022-08-29 00:03:56 +02:00
parent bd0ed87f70
commit 8ec8d32a5b
3 changed files with 31 additions and 21 deletions

View File

@ -35,7 +35,12 @@ func Compile(cfg *CompileConfig, ch chan<- *CompileReport, wg *sync.WaitGroup) {
ch <- &CompileReport{Config: cfg, State: StateCompiling}
compileCmd := exec.Command("go", "build", "-o", filePath)
args := []string{"build", "-o", filePath}
if !*KeepDebugFlags {
args = append(args, "-ldflags=-s -w")
}
compileCmd := exec.Command("go", args...)
compileCmd.Dir = ModulePath
if err := compileCmd.Start(); err != nil {

View File

@ -18,9 +18,10 @@ type Config struct {
OS []string `json:"os"`
Arch []string `json:"arch"`
Silent bool `json:"silent"`
NoCompress bool `json:"no_compress"`
NumThreads int `json:"num_threads"`
Silent bool `json:"silent"`
NoCompress bool `json:"no_compress"`
NumThreads int `json:"num_threads"`
KeepDebugFlags bool `json:"debug_flags"`
}
func SetFlagIfDefault[T comparable](flag *T, newValue T, defaultValue T) {
@ -56,6 +57,7 @@ func LoadConfig() error {
SetFlagIfDefault(Silent, cfg.Silent, DefaultSilent)
SetFlagIfDefault(NoCompress, cfg.NoCompress, DefaultNoCompress)
SetFlagIfDefault(NumThreads, cfg.NumThreads, DefaultNumThreads)
SetFlagIfDefault(KeepDebugFlags, cfg.KeepDebugFlags, DefaultKeepDebugFlags)
return nil
}
@ -80,13 +82,14 @@ func SaveConfig() (string, error) {
enc.SetIndent("", "\t")
cfg := &Config{
OutputDir: *OutputDir,
OutputFile: *OutputFile,
OS: strings.Split(*OS, ","),
Arch: strings.Split(*Arch, ","),
Silent: *Silent,
NoCompress: *NoCompress,
NumThreads: *NumThreads,
OutputDir: *OutputDir,
OutputFile: *OutputFile,
OS: strings.Split(*OS, ","),
Arch: strings.Split(*Arch, ","),
Silent: *Silent,
NoCompress: *NoCompress,
NumThreads: *NumThreads,
KeepDebugFlags: *KeepDebugFlags,
}
if err := enc.Encode(cfg); err != nil {

22
main.go
View File

@ -31,13 +31,14 @@ var (
// command line arguments default values
var (
DefaultOutputDir = "output"
DefaultOutputFile = "{{.Name}}-{{.OS}}-{{.Arch}}{{.Ext}}"
DefaultOS = ""
DefaultArch = ""
DefaultSilent = false
DefaultNoCompress = false
DefaultNumThreads = runtime.NumCPU()
DefaultOutputDir = "output"
DefaultOutputFile = "{{.Name}}-{{.OS}}-{{.Arch}}{{.Ext}}"
DefaultOS = ""
DefaultArch = ""
DefaultSilent = false
DefaultNoCompress = false
DefaultNumThreads = runtime.NumCPU()
DefaultKeepDebugFlags = false
)
// command line arguments
@ -48,9 +49,10 @@ var (
OS = flag.String("os", DefaultOS, "comma-separated list of operating systems to compile for (empty for all)")
Arch = flag.String("arch", DefaultArch, "comma-separated list of architectures to compile for (empty for all)")
Silent = flag.Bool("s", DefaultSilent, "silent mode (no output)")
NoCompress = flag.Bool("c", DefaultNoCompress, "dont compress any executables")
NumThreads = flag.Int("t", DefaultNumThreads, "amount of threads (0 = infinite)")
Silent = flag.Bool("s", DefaultSilent, "silent mode (no output)")
NoCompress = flag.Bool("c", DefaultNoCompress, "dont compress any executables")
NumThreads = flag.Int("t", DefaultNumThreads, "amount of threads (0 = infinite)")
KeepDebugFlags = flag.Bool("d", DefaultKeepDebugFlags, "keep debug flags")
SaveConfigFile = flag.Bool("saveconfig", false, "save config file with current configuration and exit")
IgnoreConfigFile = flag.Bool("ignoreconfig", false, "dont read any config file")