summaryrefslogtreecommitdiff
path: root/build.go
diff options
context:
space:
mode:
Diffstat (limited to 'build.go')
-rw-r--r--build.go80
1 files changed, 63 insertions, 17 deletions
diff --git a/build.go b/build.go
index f958e80..697f558 100644
--- a/build.go
+++ b/build.go
@@ -15,6 +15,8 @@ import (
"errors"
"fmt"
"os"
+ "path/filepath"
+ "strings"
"time"
"go.wit.com/lib/protobuf/gitpb"
@@ -22,23 +24,35 @@ import (
)
func (f *Forge) Build(repo *gitpb.Repo, userFlags []string) error {
+ return f.doBuild(repo, userFlags, "build")
+}
+
+func (f *Forge) Install(repo *gitpb.Repo, userFlags []string) error {
+ return f.doBuild(repo, userFlags, "install")
+}
+
+func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) error {
// always assume all sources have been downloaded
// todo: detect when in ~/go/src vs go.work mode
os.Setenv("GO111MODULE", "off")
+ defer os.Unsetenv("GO111MODULE")
// get the version
version := repo.GetCurrentBranchVersion()
- loop := repo.Tags.SortByRefname()
- for loop.Scan() {
- t := loop.Next()
- log.Info("Build() tag:", t.Refname)
- }
+ /*
+ loop := repo.Tags.SortByRefname()
+ for loop.Scan() {
+ t := loop.Next()
+ log.Info("Build() tag:", t.Refname)
+ }
+ */
if repo.GoDeps == nil {
repo.RedoGoMod()
}
if repo.GoDeps.Len() == 0 {
+ // eh, potentially runs it twice. don't care right now
log.Info("redo go.mod", repo.GetGoPath())
repo.RedoGoMod()
f.Repos.ConfigSave()
@@ -46,25 +60,23 @@ func (f *Forge) Build(repo *gitpb.Repo, userFlags []string) error {
loop1 := repo.GoDeps.SortByGoPath()
for loop1.Scan() {
t := loop1.Next()
- log.Info("Build() dep:", t.GetGoPath(), t.GetVersion())
+ found := f.Repos.FindByGoPath(t.GetGoPath())
+ if found.RepoType() == "protobuf" {
+ if err := f.runAutogenpb(found); err != nil {
+ return err
+ }
+ }
}
- loop2 := repo.Published.SortByGoPath()
- for loop2.Scan() {
- t := loop2.Next()
- log.Info("Build() pub:", t.GetGoPath(), t.GetVersion())
- }
- log.Info("Build() dep len:", repo.GoDeps.Len())
- os.Exit(-1)
if repo.CheckDirty() {
version = version + "-dirty"
}
- cmd := []string{"go", "build", "-v"}
+ cmd := []string{"go", goWhat, "-v"}
// set standard ldflag options
now := time.Now()
datestamp := now.UTC().Format("2006/01/02_1504_UTC")
- log.Info("datestamp =", datestamp)
+ // log.Info("datestamp =", datestamp)
// add some standard golang flags
ldflags := "-X main.VERSION=" + version + " "
ldflags += "-X main.BUILDTIME=" + datestamp + " "
@@ -78,10 +90,44 @@ func (f *Forge) Build(repo *gitpb.Repo, userFlags []string) error {
cmd = append(cmd, "-ldflags", "-X "+flag)
}
- if r := repo.Run(cmd); r.Error == nil {
- log.Warn("go build worked")
+ log.Info("running:", cmd)
+ if r := repo.RunRealtime(cmd); r.Error == nil {
+ // log.Warn("go build worked")
return nil
} else {
+ log.Warn("go build failed", cmd)
return errors.New("go build failed: " + fmt.Sprint(r.Error))
}
}
+
+func (f *Forge) runAutogenpb(repo *gitpb.Repo) error {
+ // log.Info("run autogenpb here:", repo.GetGoPath())
+ files, err := repo.GetProtoFiles()
+ if err != nil {
+ log.Info("gitpb.GetProtoFiles()", err)
+ return err
+ }
+ for _, s := range files {
+ _, filename := filepath.Split(s)
+ pbfile := strings.TrimSuffix(filename, ".proto") + ".pb.go"
+ cmd := []string{"autogenpb", "--proto", filename}
+ if repo.Exists(pbfile) {
+ // log.Info("skip running:", cmd)
+ continue
+ }
+ log.Info("running:", cmd)
+ r := repo.RunRealtime(cmd)
+ if r.Error != nil {
+ log.Warn("")
+ log.Warn("autogenpb error", r.Error)
+ log.Warn("")
+ log.Warn("You might be missing autogenpb?")
+ log.Warn("")
+ log.Warn("To install it run: go install go.wit.com/apps/autogenpb@latest")
+ log.Warn("")
+ log.Sleep(2)
+ return r.Error
+ }
+ }
+ return nil
+}