forked from TrueCloudLab/restic
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() {
|
||||
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",
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue