mirror of
https://github.com/restic/restic.git
synced 2025-01-03 05:35:43 +00:00
Support build tags for build.go
This commit is contained in:
parent
069e724d91
commit
7738709f7a
1 changed files with 25 additions and 2 deletions
27
build.go
27
build.go
|
@ -198,12 +198,24 @@ func gitVersion() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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 {
|
switch arg {
|
||||||
case "-v", "--verbose":
|
case "-v", "--verbose":
|
||||||
verbose = true
|
verbose = true
|
||||||
case "-k", "--keep-gopath":
|
case "-k", "--keep-gopath":
|
||||||
keepGopath = true
|
keepGopath = true
|
||||||
|
case "-t", "-tags", "--tags":
|
||||||
|
skipNext = true
|
||||||
|
buildTags = strings.Split(params[i+1], " ")
|
||||||
case "-h":
|
case "-h":
|
||||||
showUsage(os.Stdout)
|
showUsage(os.Stdout)
|
||||||
default:
|
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()
|
root, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
die("Getwd(): %v\n", err)
|
die("Getwd(): %v\n", err)
|
||||||
|
@ -236,7 +259,7 @@ func main() {
|
||||||
version := getVersion()
|
version := getVersion()
|
||||||
compileTime := time.Now().Format(timeFormat)
|
compileTime := time.Now().Format(timeFormat)
|
||||||
args := []string{
|
args := []string{
|
||||||
"-tags", "release",
|
"-tags", strings.Join(buildTags, " "),
|
||||||
"-ldflags", fmt.Sprintf(`-s -X main.version %q -X main.compiledAt %q`, version, compileTime),
|
"-ldflags", fmt.Sprintf(`-s -X main.version %q -X main.compiledAt %q`, version, compileTime),
|
||||||
"-o", "restic", "github.com/restic/restic/cmd/restic",
|
"-o", "restic", "github.com/restic/restic/cmd/restic",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue