1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-03 13:11:48 +02:00

61 lines
1.3 KiB
Go
Raw Normal View History

2017-01-14 15:08:10 -02:00
package build
import (
"bytes"
"log"
"strings"
2017-01-14 15:08:10 -02:00
"text/template"
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/context"
2017-01-14 15:08:10 -02:00
)
type nameData struct {
2017-03-22 21:06:37 -03:00
Os string
Arch string
Version string
Binary string
2017-01-14 15:08:10 -02:00
}
func nameFor(ctx *context.Context, goos, goarch string) (string, error) {
var data = nameData{
2017-03-22 21:06:37 -03:00
Os: replace(ctx.Config.Archive.Replacements, goos),
Arch: replace(ctx.Config.Archive.Replacements, goarch),
Version: ctx.Git.CurrentTag,
Binary: ctx.Config.Build.Binary,
2017-01-14 15:08:10 -02:00
}
// TODO: remove this block in next release cycle
if strings.Contains(ctx.Config.Archive.NameTemplate, ".BinaryName") {
log.Println("The `.BinaryName` in `archive.name_template` is deprecated and will soon be removed. Please check the README for more info.")
ctx.Config.Archive.NameTemplate = strings.Replace(
ctx.Config.Archive.NameTemplate,
".BinaryName",
".Binary",
-1,
)
}
2017-01-14 15:08:10 -02:00
var out bytes.Buffer
2017-03-22 21:06:37 -03:00
t, err := template.New(data.Binary).Parse(ctx.Config.Archive.NameTemplate)
2017-01-14 15:08:10 -02:00
if err != nil {
return "", err
}
err = t.Execute(&out, data)
return out.String(), err
}
func replace(replacements map[string]string, original string) string {
result := replacements[original]
if result == "" {
return original
}
return result
}
func extFor(goos string) string {
if goos == "windows" {
return ".exe"
}
return ""
}