Skip to content

Commit e6e6920

Browse files
committed
build: add support for passing build tags
1 parent d8d7856 commit e6e6920

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

cmd/build/main.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424

2525
func main() {
2626
log.SetFlags(log.Lshortfile)
27-
buildMode := parseFlags()
27+
buildMode, tags := parseFlags()
2828
cwd, err := os.Getwd()
2929
if err != nil {
3030
log.Fatal("could not get working directory:", err)
@@ -43,7 +43,7 @@ func main() {
4343
const (
4444
goBin = "go"
4545
goBuild = "build"
46-
maxArgs = 3
46+
maxArgs = 4
4747
)
4848
goArgs := make([]string, 1, maxArgs)
4949
goArgs[0] = goBuild
@@ -58,6 +58,9 @@ func main() {
5858
)
5959
goArgs = append(goArgs, buildTrimFlag, linkerReleaseFlags)
6060
}
61+
if tags != "" {
62+
goArgs = append(goArgs, "-tags="+tags)
63+
}
6164
goArgs = append(goArgs, pkgFSPath)
6265
cmd := exec.Command(goBin, goArgs...)
6366
cmd.Stdin = os.Stdin
@@ -73,7 +76,7 @@ func main() {
7376
}
7477
}
7578

76-
func parseFlags() buildMode {
79+
func parseFlags() (buildMode, string) {
7780
const (
7881
regularUsage = "standard go build with no compiler or linker flags when building"
7982
releaseUsage = "remove extra debugging data when building"
@@ -98,11 +101,16 @@ func parseFlags() buildMode {
98101
mode, err = generic.ParseEnum(regular, debug, arg)
99102
return
100103
})
101-
flagSet.VisitAll(func(f *flag.Flag) {
102-
if f.Name == modeName {
103-
f.DefValue = mode.String()
104-
}
105-
})
104+
flagSet.Lookup(modeName).DefValue = mode.String()
105+
var tags string
106+
const (
107+
tagName = "tags"
108+
tagsUsage = "a comma-separated list of build tags" +
109+
"\nsupported in addition to Go's standard tags:" +
110+
"\nnofuse - build without FUSE host support" +
111+
"\nnoipfs - build without IPFS guest support"
112+
)
113+
flagSet.StringVar(&tags, tagName, "", tagsUsage)
106114
if err := flagSet.Parse(os.Args[1:]); err != nil {
107115
log.Fatal(err)
108116
}
@@ -115,7 +123,7 @@ func parseFlags() buildMode {
115123
output.String(),
116124
)
117125
}
118-
return mode
126+
return mode, tags
119127
}
120128

121129
func commandName() string {

0 commit comments

Comments
 (0)