print go install command by default

This commit is contained in:
Timon Ringwald 2022-08-30 00:42:47 +02:00
parent c964a85673
commit 20f84c6bf1
3 changed files with 29 additions and 14 deletions

View File

@ -35,7 +35,7 @@ func Compile(cfg *CompileConfig, ch chan<- *CompileReport, wg *sync.WaitGroup) {
ch <- &CompileReport{Config: cfg, State: StateCompiling}
args := []string{"build", "-o", filePath, BuildLdFlags(cfg.OS, cfg.Arch)}
args := []string{"build", "-o", filePath, "-ldflags=" + BuildLdFlags(cfg.OS, cfg.Arch)}
compileCmd := exec.Command("go", args...)
compileCmd.Dir = ModulePath

19
main.go
View File

@ -20,7 +20,9 @@ import (
var (
OutputFileTmpl = template.New("output-file")
ModulePath string
ModulePath string
ProjectPath string
ProjectName string
// meta data for executables
@ -62,6 +64,8 @@ var (
IgnoreConfigFile = flag.Bool("ignoreconfig", false, "dont read any config file")
FindConfigFile = flag.Bool("findconfig", false, "print config file path and exit")
DontPrintInstallCmd = flag.Bool("p", false, "print 'go install' command")
ShowVersion = flag.Bool("v", false, "show version and exit")
)
@ -69,6 +73,15 @@ func main() {
Init()
GatherMetaData()
if !*Silent && !*DontPrintInstallCmd {
tag := VersionTag
if tag == "" || strings.HasPrefix(tag, "(devel") {
tag = "latest"
}
Println(ColorDone.Sprintf("go install -ldflags=\"%s\" %s@%s", BuildLdFlags("", ""), ProjectPath, tag))
Println()
}
ch := make(chan *CompileReport, len(CompileConfigs))
wg := new(sync.WaitGroup)
@ -105,8 +118,8 @@ func DetermineProjectName() error {
for _, line := range strings.Split(string(data), "\n") {
if strings.HasPrefix(line, "module ") {
fullName := strings.TrimPrefix(line, "module ")
parts := strings.Split(fullName, "/")
ProjectPath = strings.TrimPrefix(line, "module ")
parts := strings.Split(ProjectPath, "/")
ProjectName = parts[len(parts)-1]
return nil
}

View File

@ -119,8 +119,6 @@ func GatherMetaData() {
func BuildLdFlags(os, arch string) string {
b := &strings.Builder{}
b.WriteString("-ldflags=")
if !*KeepDebugFlags {
b.WriteString("-s -w")
}
@ -149,15 +147,19 @@ func BuildLdFlags(os, arch string) string {
b.WriteString("=")
b.WriteString(BuildTime)
b.WriteString(" -X ")
b.WriteString("git.milar.in/milarin/buildinfo.OS")
b.WriteString("=")
b.WriteString(os)
if os != "" {
b.WriteString(" -X ")
b.WriteString("git.milar.in/milarin/buildinfo.OS")
b.WriteString("=")
b.WriteString(os)
}
b.WriteString(" -X ")
b.WriteString("git.milar.in/milarin/buildinfo.Arch")
b.WriteString("=")
b.WriteString(arch)
if arch != "" {
b.WriteString(" -X ")
b.WriteString("git.milar.in/milarin/buildinfo.Arch")
b.WriteString("=")
b.WriteString(arch)
}
return b.String()
}