print go install command by default
This commit is contained in:
parent
c964a85673
commit
20f84c6bf1
@ -35,7 +35,7 @@ func Compile(cfg *CompileConfig, ch chan<- *CompileReport, wg *sync.WaitGroup) {
|
|||||||
|
|
||||||
ch <- &CompileReport{Config: cfg, State: StateCompiling}
|
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 := exec.Command("go", args...)
|
||||||
compileCmd.Dir = ModulePath
|
compileCmd.Dir = ModulePath
|
||||||
|
17
main.go
17
main.go
@ -21,6 +21,8 @@ var (
|
|||||||
OutputFileTmpl = template.New("output-file")
|
OutputFileTmpl = template.New("output-file")
|
||||||
|
|
||||||
ModulePath string
|
ModulePath string
|
||||||
|
|
||||||
|
ProjectPath string
|
||||||
ProjectName string
|
ProjectName string
|
||||||
|
|
||||||
// meta data for executables
|
// meta data for executables
|
||||||
@ -62,6 +64,8 @@ var (
|
|||||||
IgnoreConfigFile = flag.Bool("ignoreconfig", false, "dont read any config file")
|
IgnoreConfigFile = flag.Bool("ignoreconfig", false, "dont read any config file")
|
||||||
FindConfigFile = flag.Bool("findconfig", false, "print config file path and exit")
|
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")
|
ShowVersion = flag.Bool("v", false, "show version and exit")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,6 +73,15 @@ func main() {
|
|||||||
Init()
|
Init()
|
||||||
GatherMetaData()
|
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))
|
ch := make(chan *CompileReport, len(CompileConfigs))
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
|
|
||||||
@ -105,8 +118,8 @@ func DetermineProjectName() error {
|
|||||||
|
|
||||||
for _, line := range strings.Split(string(data), "\n") {
|
for _, line := range strings.Split(string(data), "\n") {
|
||||||
if strings.HasPrefix(line, "module ") {
|
if strings.HasPrefix(line, "module ") {
|
||||||
fullName := strings.TrimPrefix(line, "module ")
|
ProjectPath = strings.TrimPrefix(line, "module ")
|
||||||
parts := strings.Split(fullName, "/")
|
parts := strings.Split(ProjectPath, "/")
|
||||||
ProjectName = parts[len(parts)-1]
|
ProjectName = parts[len(parts)-1]
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,6 @@ func GatherMetaData() {
|
|||||||
func BuildLdFlags(os, arch string) string {
|
func BuildLdFlags(os, arch string) string {
|
||||||
b := &strings.Builder{}
|
b := &strings.Builder{}
|
||||||
|
|
||||||
b.WriteString("-ldflags=")
|
|
||||||
|
|
||||||
if !*KeepDebugFlags {
|
if !*KeepDebugFlags {
|
||||||
b.WriteString("-s -w")
|
b.WriteString("-s -w")
|
||||||
}
|
}
|
||||||
@ -149,15 +147,19 @@ func BuildLdFlags(os, arch string) string {
|
|||||||
b.WriteString("=")
|
b.WriteString("=")
|
||||||
b.WriteString(BuildTime)
|
b.WriteString(BuildTime)
|
||||||
|
|
||||||
|
if os != "" {
|
||||||
b.WriteString(" -X ")
|
b.WriteString(" -X ")
|
||||||
b.WriteString("git.milar.in/milarin/buildinfo.OS")
|
b.WriteString("git.milar.in/milarin/buildinfo.OS")
|
||||||
b.WriteString("=")
|
b.WriteString("=")
|
||||||
b.WriteString(os)
|
b.WriteString(os)
|
||||||
|
}
|
||||||
|
|
||||||
|
if arch != "" {
|
||||||
b.WriteString(" -X ")
|
b.WriteString(" -X ")
|
||||||
b.WriteString("git.milar.in/milarin/buildinfo.Arch")
|
b.WriteString("git.milar.in/milarin/buildinfo.Arch")
|
||||||
b.WriteString("=")
|
b.WriteString("=")
|
||||||
b.WriteString(arch)
|
b.WriteString(arch)
|
||||||
|
}
|
||||||
|
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user