2022-08-17 18:16:21 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-08-17 19:37:46 +02:00
|
|
|
"fmt"
|
2022-08-17 18:16:21 +02:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
2022-08-17 19:37:46 +02:00
|
|
|
"git.milar.in/milarin/gmath"
|
2022-08-17 18:16:21 +02:00
|
|
|
"golang.org/x/exp/slices"
|
|
|
|
)
|
|
|
|
|
|
|
|
var CompileConfigs = []*CompileConfig{}
|
|
|
|
|
|
|
|
type CompileConfig struct {
|
|
|
|
OS string
|
|
|
|
Arch string
|
|
|
|
FileExt string
|
|
|
|
Compress bool
|
|
|
|
}
|
|
|
|
|
2022-08-17 19:37:46 +02:00
|
|
|
func (cfg CompileConfig) String() string {
|
|
|
|
return fmt.Sprintf("%s/%s:", cfg.OS, cfg.Arch)
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:16:21 +02:00
|
|
|
func FillCompileConfigs() error {
|
|
|
|
cmd := exec.Command("go", "tool", "dist", "list")
|
|
|
|
|
|
|
|
systems := strings.Split(*OS, ",")
|
|
|
|
arches := strings.Split(*Arch, ",")
|
|
|
|
|
|
|
|
out, err := cmd.Output()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
|
|
|
|
|
for _, line := range lines {
|
|
|
|
splits := strings.Split(line, "/")
|
|
|
|
os, arch := splits[0], splits[1]
|
|
|
|
|
|
|
|
if (*OS != "" && !slices.Contains(systems, os)) || (*Arch != "" && !slices.Contains(arches, arch)) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
ext := ""
|
|
|
|
if os == "windows" {
|
|
|
|
ext = ".exe"
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := &CompileConfig{
|
|
|
|
OS: os,
|
|
|
|
Arch: arch,
|
|
|
|
Compress: true,
|
|
|
|
FileExt: ext,
|
|
|
|
}
|
|
|
|
|
2022-08-17 19:37:46 +02:00
|
|
|
MaxConfigStringLength = gmath.Max(MaxConfigStringLength, len(cfg.String()))
|
2022-08-17 18:16:21 +02:00
|
|
|
CompileConfigs = append(CompileConfigs, cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|