2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

Support build tags for build.go

This commit is contained in:
Alexander Neumann 2015-06-24 19:57:08 +02:00
parent 069e724d91
commit 7738709f7a

View File

@ -198,12 +198,24 @@ func gitVersion() string {
}
func main() {
for _, arg := range os.Args[1:] {
buildTags := []string{}
skipNext := false
params := os.Args[1:]
for i, arg := range params {
if skipNext {
skipNext = false
continue
}
switch arg {
case "-v", "--verbose":
verbose = true
case "-k", "--keep-gopath":
keepGopath = true
case "-t", "-tags", "--tags":
skipNext = true
buildTags = strings.Split(params[i+1], " ")
case "-h":
showUsage(os.Stdout)
default:
@ -213,6 +225,17 @@ func main() {
}
}
if len(buildTags) == 0 {
verbosePrintf("adding build-tag release\n")
buildTags = []string{"release"}
}
for i := range buildTags {
buildTags[i] = strings.TrimSpace(buildTags[i])
}
verbosePrintf("build tags: %s\n", buildTags)
root, err := os.Getwd()
if err != nil {
die("Getwd(): %v\n", err)
@ -236,7 +259,7 @@ func main() {
version := getVersion()
compileTime := time.Now().Format(timeFormat)
args := []string{
"-tags", "release",
"-tags", strings.Join(buildTags, " "),
"-ldflags", fmt.Sprintf(`-s -X main.version %q -X main.compiledAt %q`, version, compileTime),
"-o", "restic", "github.com/restic/restic/cmd/restic",
}