autotypist/rebuildAutotypist.go

92 lines
2.7 KiB
Go
Raw Permalink Normal View History

2024-11-25 01:52:49 -06:00
package main
import (
"path/filepath"
"strings"
2024-11-25 01:52:49 -06:00
"github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
// attempt to rebuild this app
// This should work from a blank slate
// TODO: make sure this works in a empty directory with a go-work file
func attemptAutoRebuild() bool {
gosrc := me.goSrcPwd.String()
if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/apps/autotypist"}); !ok {
return buildDied(r)
}
if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/debian"}); !ok {
return buildDied(r)
}
if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/tree"}); !ok {
return buildDied(r)
}
if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/nocui"}); !ok {
return buildDied(r)
}
if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/gocui"}); !ok {
return buildDied(r)
}
if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/andlabs"}); !ok {
return buildDied(r)
}
2024-11-25 01:52:49 -06:00
if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/nocui/"), []string{"make"}); !ok {
return buildDied(r)
}
if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/gocui/"), []string{"make"}); !ok {
return buildDied(r)
}
if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/andlabs/"), []string{"make"}); !ok {
return buildDied(r)
}
2024-11-25 01:52:49 -06:00
// build the protobuf files
// TODO: verify the right protoc-gen-go exists
if !shell.Exists("/usr/bin/protoc-gen-go") {
log.Warn("missing /usr/bin/protc-gen-go. apt install protoc-gen-go")
return false
}
quickCmd(filepath.Join(gosrc, "go.wit.com/lib/protobuf/forgepb/"), []string{"make"})
2024-11-25 01:52:49 -06:00
quickCmd(filepath.Join(gosrc, "go.wit.com/lib/protobuf/virtbuf/"), []string{"make"})
quickCmd(filepath.Join(gosrc, "go.wit.com/lib/protobuf/zoopb/"), []string{"make"})
2024-11-25 01:52:49 -06:00
quickCmd(filepath.Join(gosrc, "go.wit.com/apps/autotypist/"), []string{"make", "build"})
return true
}
// only errors on bad errors
func quickCmd(fullpath string, cmd []string) (*cmd.Status, bool) {
if me.autoDryRun.Checked() {
log.Warn("RUN --dry-run", fullpath, cmd)
return nil, true
} else {
log.Warn("RUN:", fullpath, cmd)
}
r := shell.PathRun(fullpath, cmd)
output := strings.TrimSpace(strings.Join(r.Stdout, "\n"))
if r.Error != nil {
log.Warn("cmd =", cmd)
log.Warn("err =", r.Error)
log.Warn("b =", r.Exit)
log.Warn("output =", output)
return &r, false
} else if r.Exit != 0 {
log.Warn("b =", r.Exit)
log.Warn("output =", output)
return &r, true
}
log.Warn("output = ", output)
return &r, true
}
func buildDied(r *cmd.Status) bool {
return false
}