Add build tags

Signed-off-by: Kevin Zhang <kzhang@tecton.ai>
This commit is contained in:
Kevin Zhang 2022-07-14 13:58:59 -07:00
parent 1018dfd79f
commit 591500e321
5 changed files with 14 additions and 9 deletions

View File

@ -73,7 +73,7 @@ func gopyRunCmdBuild(cmdr *commander.Command, args []string) error {
bind.NoMake = cfg.NoMake bind.NoMake = cfg.NoMake
for _, path := range args { for _, path := range args {
bpkg, err := loadPackage(path, true) // build first bpkg, err := loadPackage(path, true, cfg.BuildTags) // build first
if err != nil { if err != nil {
return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err) return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err)
} }

View File

@ -133,7 +133,7 @@ func gopyRunCmdExe(cmdr *commander.Command, args []string) error {
} }
for _, path := range args { for _, path := range args {
buildPkgRecurse(cfg.OutputDir, path, path, exmap) buildPkgRecurse(cfg.OutputDir, path, path, exmap, cfg.BuildTags)
} }
return runBuild(bind.ModeExe, cfg) return runBuild(bind.ModeExe, cfg)
} }

View File

@ -71,7 +71,7 @@ func gopyRunCmdGen(cmdr *commander.Command, args []string) error {
bind.NoMake = cfg.NoMake bind.NoMake = cfg.NoMake
for _, path := range args { for _, path := range args {
bpkg, err := loadPackage(path, true) // build first bpkg, err := loadPackage(path, true, cfg.BuildTags) // build first
if err != nil { if err != nil {
return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err) return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err)
} }

View File

@ -129,14 +129,14 @@ func gopyRunCmdPkg(cmdr *commander.Command, args []string) error {
} }
for _, path := range args { for _, path := range args {
buildPkgRecurse(cfg.OutputDir, path, path, exmap) buildPkgRecurse(cfg.OutputDir, path, path, exmap, cfg.BuildTags)
} }
return runBuild(bind.ModePkg, cfg) 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 buildFirst := path == rootpath
bpkg, err := loadPackage(path, buildFirst) bpkg, err := loadPackage(path, buildFirst, buildTags)
if err != nil { if err != nil {
return fmt.Errorf("gopy-gen: go build / load of package failed with path=%q: %v", path, err) 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 continue
} }
sp := filepath.Join(path, dr) sp := filepath.Join(path, dr)
buildPkgRecurse(odir, sp, rootpath, exmap) buildPkgRecurse(odir, sp, rootpath, exmap, buildTags)
} }
return nil return nil
} }

9
gen.go
View File

@ -85,14 +85,19 @@ func genPkg(mode bind.BuildMode, cfg *BuildCfg) error {
return err 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() cwd, err := os.Getwd()
if err != nil { if err != nil {
return nil, err return nil, err
} }
if buildFirst { 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.Stdin = os.Stdin
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr