From 591500e3215f2fa2bbfde2a232074e2c00862aa2 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 14 Jul 2022 13:58:59 -0700 Subject: [PATCH] Add build tags Signed-off-by: Kevin Zhang --- cmd_build.go | 2 +- cmd_exe.go | 2 +- cmd_gen.go | 2 +- cmd_pkg.go | 8 ++++---- gen.go | 9 +++++++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd_build.go b/cmd_build.go index 8fc6df2..0722629 100644 --- a/cmd_build.go +++ b/cmd_build.go @@ -73,7 +73,7 @@ func gopyRunCmdBuild(cmdr *commander.Command, args []string) error { bind.NoMake = cfg.NoMake for _, path := range args { - bpkg, err := loadPackage(path, true) // build first + bpkg, err := loadPackage(path, true, cfg.BuildTags) // build first if err != nil { return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err) } diff --git a/cmd_exe.go b/cmd_exe.go index e3b22dd..60ee3ce 100644 --- a/cmd_exe.go +++ b/cmd_exe.go @@ -133,7 +133,7 @@ func gopyRunCmdExe(cmdr *commander.Command, args []string) error { } for _, path := range args { - buildPkgRecurse(cfg.OutputDir, path, path, exmap) + buildPkgRecurse(cfg.OutputDir, path, path, exmap, cfg.BuildTags) } return runBuild(bind.ModeExe, cfg) } diff --git a/cmd_gen.go b/cmd_gen.go index 562c863..becd0f1 100644 --- a/cmd_gen.go +++ b/cmd_gen.go @@ -71,7 +71,7 @@ func gopyRunCmdGen(cmdr *commander.Command, args []string) error { bind.NoMake = cfg.NoMake for _, path := range args { - bpkg, err := loadPackage(path, true) // build first + bpkg, err := loadPackage(path, true, cfg.BuildTags) // build first if err != nil { return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err) } diff --git a/cmd_pkg.go b/cmd_pkg.go index 3e145ff..c0d6cba 100644 --- a/cmd_pkg.go +++ b/cmd_pkg.go @@ -129,14 +129,14 @@ func gopyRunCmdPkg(cmdr *commander.Command, args []string) error { } for _, path := range args { - buildPkgRecurse(cfg.OutputDir, path, path, exmap) + buildPkgRecurse(cfg.OutputDir, path, path, exmap, cfg.BuildTags) } return runBuild(bind.ModePkg, cfg) } -func buildPkgRecurse(odir, path, rootpath string, exmap map[string]struct{}) error { +func buildPkgRecurse(odir, path, rootpath string, exmap map[string]struct{}, buildTags string) error { buildFirst := path == rootpath - bpkg, err := loadPackage(path, buildFirst) + bpkg, err := loadPackage(path, buildFirst, buildTags) if err != nil { return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err) } @@ -171,7 +171,7 @@ func buildPkgRecurse(odir, path, rootpath string, exmap map[string]struct{}) err continue } sp := filepath.Join(path, dr) - buildPkgRecurse(odir, sp, rootpath, exmap) + buildPkgRecurse(odir, sp, rootpath, exmap, buildTags) } return nil } diff --git a/gen.go b/gen.go index 2f8dbc7..194de4b 100644 --- a/gen.go +++ b/gen.go @@ -85,14 +85,19 @@ func genPkg(mode bind.BuildMode, cfg *BuildCfg) error { return err } -func loadPackage(path string, buildFirst bool) (*packages.Package, error) { +func loadPackage(path string, buildFirst bool, buildTags string) (*packages.Package, error) { cwd, err := os.Getwd() if err != nil { return nil, err } if buildFirst { - cmd := exec.Command("go", "build", "-v", path) + args := []string{"build", "-v", "path"} + if buildTags != "" { + args = append(args, "-tags", buildTags) + } + fmt.Printf("go %v\n", strings.Join(args, " ")) + cmd := exec.Command("go", args...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr