Skip to content

Commit 591500e

Browse files
committed
Add build tags
Signed-off-by: Kevin Zhang <[email protected]>
1 parent 1018dfd commit 591500e

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

cmd_build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func gopyRunCmdBuild(cmdr *commander.Command, args []string) error {
7373
bind.NoMake = cfg.NoMake
7474

7575
for _, path := range args {
76-
bpkg, err := loadPackage(path, true) // build first
76+
bpkg, err := loadPackage(path, true, cfg.BuildTags) // build first
7777
if err != nil {
7878
return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err)
7979
}

cmd_exe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func gopyRunCmdExe(cmdr *commander.Command, args []string) error {
133133
}
134134

135135
for _, path := range args {
136-
buildPkgRecurse(cfg.OutputDir, path, path, exmap)
136+
buildPkgRecurse(cfg.OutputDir, path, path, exmap, cfg.BuildTags)
137137
}
138138
return runBuild(bind.ModeExe, cfg)
139139
}

cmd_gen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func gopyRunCmdGen(cmdr *commander.Command, args []string) error {
7171
bind.NoMake = cfg.NoMake
7272

7373
for _, path := range args {
74-
bpkg, err := loadPackage(path, true) // build first
74+
bpkg, err := loadPackage(path, true, cfg.BuildTags) // build first
7575
if err != nil {
7676
return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err)
7777
}

cmd_pkg.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ func gopyRunCmdPkg(cmdr *commander.Command, args []string) error {
129129
}
130130

131131
for _, path := range args {
132-
buildPkgRecurse(cfg.OutputDir, path, path, exmap)
132+
buildPkgRecurse(cfg.OutputDir, path, path, exmap, cfg.BuildTags)
133133
}
134134
return runBuild(bind.ModePkg, cfg)
135135
}
136136

137-
func buildPkgRecurse(odir, path, rootpath string, exmap map[string]struct{}) error {
137+
func buildPkgRecurse(odir, path, rootpath string, exmap map[string]struct{}, buildTags string) error {
138138
buildFirst := path == rootpath
139-
bpkg, err := loadPackage(path, buildFirst)
139+
bpkg, err := loadPackage(path, buildFirst, buildTags)
140140
if err != nil {
141141
return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err)
142142
}
@@ -171,7 +171,7 @@ func buildPkgRecurse(odir, path, rootpath string, exmap map[string]struct{}) err
171171
continue
172172
}
173173
sp := filepath.Join(path, dr)
174-
buildPkgRecurse(odir, sp, rootpath, exmap)
174+
buildPkgRecurse(odir, sp, rootpath, exmap, buildTags)
175175
}
176176
return nil
177177
}

gen.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,19 @@ func genPkg(mode bind.BuildMode, cfg *BuildCfg) error {
8585
return err
8686
}
8787

88-
func loadPackage(path string, buildFirst bool) (*packages.Package, error) {
88+
func loadPackage(path string, buildFirst bool, buildTags string) (*packages.Package, error) {
8989
cwd, err := os.Getwd()
9090
if err != nil {
9191
return nil, err
9292
}
9393

9494
if buildFirst {
95-
cmd := exec.Command("go", "build", "-v", path)
95+
args := []string{"build", "-v", "path"}
96+
if buildTags != "" {
97+
args = append(args, "-tags", buildTags)
98+
}
99+
fmt.Printf("go %v\n", strings.Join(args, " "))
100+
cmd := exec.Command("go", args...)
96101
cmd.Stdin = os.Stdin
97102
cmd.Stdout = os.Stdout
98103
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)