diff options
| author | Jeff Carr <[email protected]> | 2025-10-03 01:05:11 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-03 01:05:11 -0500 |
| commit | 4acdb3bce3d7afb5f9218ac958b235358493563c (patch) | |
| tree | 7b7c16bdf5efac5413f0003356208864e348d43e | |
| parent | 01fa86c6f69dc7f34b92f98c0d45ff93c324da9f (diff) | |
more autocomplete work
| -rw-r--r-- | argv.go | 12 | ||||
| -rw-r--r-- | debian.go | 106 | ||||
| -rw-r--r-- | doDebian.go | 123 | ||||
| -rw-r--r-- | doInstall.go | 2 | ||||
| -rw-r--r-- | main.go | 33 | ||||
| -rw-r--r-- | structs.go | 38 |
6 files changed, 164 insertions, 150 deletions
@@ -22,7 +22,7 @@ var argv args type args struct { Git *GitCmd `arg:"subcommand:git" help:"git stuff"` TestBuild *DefaultCmd `arg:"subcommand:build" help:"try appropriate 'go build'"` - DebBuild *DebianCmd `arg:"subcommand:debian" help:"build missing .deb packages"` + Debian *DebianCmd `arg:"subcommand:debian" help:"build missing .deb packages"` MacBuild *EmptyCmd `arg:"subcommand:macos" help:"build macos packages"` MakeInstall *DefaultCmd `arg:"subcommand:install" help:"run make install in each repo"` ListPkgs *EmptyCmd `arg:"subcommand:list" help:"list all the packages on mirrors.wit.com"` @@ -32,6 +32,7 @@ type args struct { RepoMap string `arg:"--repomap" help:"location of the repomap"` Release bool `arg:"--release" help:"use go-deb --release"` DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` + Install bool `arg:"--install" help:"go install the binaries first"` Verbose bool `arg:"--verbose" help:"be loud about it"` Force bool `arg:"--force" help:"rebuild everything"` Recursive bool `arg:"--recursive" help:"go-clone --recursive"` @@ -40,9 +41,10 @@ type args struct { } type DebianCmd struct { - DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` - Verbose bool `arg:"--verbose" help:"be loud about it"` - Force bool `arg:"--force" help:"rebuild everything"` + DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` + Verbose bool `arg:"--verbose" help:"be loud about it"` + Force bool `arg:"--force" help:"rebuild everything"` + SkipInstall bool `arg:"--skip-install" help:"rebuild everything"` } type DefaultCmd struct { @@ -96,7 +98,7 @@ func (args) Appname() string { func (a args) DoAutoComplete(pb *prep.Auto) { if pb.Cmd == "" { - pb.Autocomplete3([]string{"push", "build", "debian", "install", "upgrade", "macos", "git", "--witcom --version"}) + pb.Autocomplete3([]string{"push", "build", "debian", "--install", "upgrade", "macos", "git", "--witcom --version --dry-run"}) } else { pb.SubCommand(pb.Argv...) } diff --git a/debian.go b/debian.go new file mode 100644 index 0000000..3b21991 --- /dev/null +++ b/debian.go @@ -0,0 +1,106 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "os" + + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func buildDeb() { + var counter int + if int(argv.Max) == 0 { + argv.Max = 50 + } + + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + var cmd []string + check := all.Next() + + outdir := getOutdir(check) + os.MkdirAll(outdir, 0755) + + if me.forge.Config.IsReadOnly(check.GetGoPath()) { + continue + } + + if !check.IsBinary() { + continue + } + + if check.IsGoPlugin() { + continue + } + + if argv.Release { + cmd = []string{"go-deb", "--release", "--dir", outdir} + } else { + cmd = []string{"go-deb", "--dir", outdir} + } + if me.forge.Config.IsPrivate(check.GetGoPath()) { + cmd = []string{"go-deb", "--dir", outdir} + continue + } + + if argv.Verbose { + log.Info("build cmd:", cmd) + cmd = append(cmd, "--verbose") + } + if argv.DryRun { + continue + } + + if argv.Force { + // build everything no matter what + } else { + if state[check] != "need to build" { + // log.Info("skipping build for", check.GetGoPath(), state[check]) + continue + } + } + + counter += 1 + + if counter > int(argv.Max) { + log.Info("did --max builds", argv.Max) + okExit("") + } + + if argv.MacBuild != nil { + log.Info("todo: add mac builds") + continue + } + + if err := check.RunVerbose(cmd); err != nil { + log.Info(check.FullPath, cmd) + failed[check] = fmt.Sprint("godeb failed", cmd, "with", err) + badExit(err) + } else { + log.Info("build worked") + } + } +} + +func getOutdir(repo *gitpb.Repo) string { + if repo.GetLastTag() != repo.GetMasterVersion() { + return "/home/jcarr/incoming-devel" + } + + if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() { + return "/home/jcarr/incoming-devel" + } + + if repo.CheckDirty() { + return "/home/jcarr/incoming-devel" + } + + if me.forge.Config.IsPrivate(repo.GetGoPath()) { + return "/home/jcarr/incoming-private" + } + return "/home/jcarr/incoming" +} diff --git a/doDebian.go b/doDebian.go index 9fb76e2..00a1390 100644 --- a/doDebian.go +++ b/doDebian.go @@ -4,133 +4,22 @@ package main import ( - "fmt" - "os" - - "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) -func buildDeb() { - log.DaemonMode(true) - defer log.DaemonMode(false) - - if argv.Test != nil { +func doDebian() { + if !argv.Debian.SkipInstall { if err := doInstall(); err != nil { log.Info("doInstall() failed", err) badExit(err) } } - var counter int - if int(argv.Max) == 0 { - argv.Max = 50 - } - - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - var cmd []string - check := all.Next() - - outdir := getOutdir(check) - os.MkdirAll(outdir, 0755) - - if me.forge.Config.IsReadOnly(check.GetGoPath()) { - continue - } - - if !check.IsBinary() { - continue - } - - if check.IsGoPlugin() { - continue - } - - if argv.Release { - cmd = []string{"go-deb", "--release", "--dir", outdir} - } else { - cmd = []string{"go-deb", "--dir", outdir} - } - if me.forge.Config.IsPrivate(check.GetGoPath()) { - cmd = []string{"go-deb", "--dir", outdir} - continue - } - - if argv.Verbose { - log.Info("build cmd:", cmd) - cmd = append(cmd, "--verbose") - } - if argv.DryRun { - continue - } - - if argv.Force { - // build everything no matter what - } else { - if state[check] != "need to build" { - // log.Info("skipping build for", check.GetGoPath(), state[check]) - continue - } - } - - counter += 1 - - if counter > int(argv.Max) { - log.Info("did --max builds", argv.Max) - okExit("") - } - - /* - build-darwin: - GOOS=darwin GOARCH=amd64 GO111MODULE=off go build -v -o go-clone-darwin.x86 \ - -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" - - build-darwin-arm64: - GOOS=darwin GOARCH=arm64 GO111MODULE=off go build -v -o go-clone-darwin.arm \ - -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" - */ - if argv.MacBuild != nil { - log.Info("todo: add mac builds") - continue - } - - /* - _, err := os.Stat(filepath.Join(outdir, debnames[check])) - if err == nil { - if debnames[check] == "" { - log.Info("something went wrong. .deb blank", check.GetGoPath()) - } - // already built - continue - } - */ - - if err := check.RunVerbose(cmd); err != nil { - log.Info(check.FullPath, cmd) - failed[check] = fmt.Sprint("godeb failed", cmd, "with", err) - badExit(err) - } else { - log.Info("build worked") - } - } -} - -func getOutdir(repo *gitpb.Repo) string { - if repo.GetLastTag() != repo.GetMasterVersion() { - return "/home/jcarr/incoming-devel" - } - - if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() { - return "/home/jcarr/incoming-devel" - } + buildDeb() - if repo.CheckDirty() { - return "/home/jcarr/incoming-devel" + if argv.DryRun { + okExit("") } - if me.forge.Config.IsPrivate(repo.GetGoPath()) { - return "/home/jcarr/incoming-private" - } - return "/home/jcarr/incoming" + exitOnError([]string{"do-aptly"}) } diff --git a/doInstall.go b/doInstall.go index 9230243..5b593f0 100644 --- a/doInstall.go +++ b/doInstall.go @@ -13,6 +13,8 @@ import ( ) func doInstall() error { + initForge() // make sure forge is init'd here + all := me.forge.Repos.SortByFullPath() for all.Scan() { check := all.Next() @@ -10,10 +10,6 @@ import ( "path/filepath" "unicode" - "go.wit.com/lib/gui/prep" - "go.wit.com/lib/protobuf/forgepb" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) @@ -24,35 +20,25 @@ var BUILDTIME string // used for shell auto completion var ARGNAME string = "wit" // todo: get this from $0 ? -var failed map[*gitpb.Repo]string -var state map[*gitpb.Repo]string -var debnames map[*gitpb.Repo]string - func main() { - me = new(autoType) - me.auto = prep.Bash3(&argv) // add support for bash autocomplete with go-arg - - dumpDebug() + me = new(mainType) + me.once.Do(initMain) if argv.Upgrade != nil { doUpgrade() okExit("") } + if argv.Debian != nil { + doDebian() + okExit("") + } + if argv.Git != nil { doGit() okExit("") } - failed = make(map[*gitpb.Repo]string) - state = make(map[*gitpb.Repo]string) - debnames = make(map[*gitpb.Repo]string) - - me.forge = forgepb.Init() - me.forge.Config.DumpENV() - - me.machine, _ = zoopb.InitMachine() - if argv.Clone != nil { if argv.RepoMap != "" { repomap(argv.RepoMap) @@ -107,11 +93,6 @@ func main() { doListRepos() - if argv.DebBuild != nil { - buildDeb() - okExit("") - } - if argv.MakeInstall != nil { if err := doInstall(); err != nil { log.Info("doInstall() failed", err) @@ -4,16 +4,50 @@ package main import ( + "sync" + "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/zoopb" ) -var me *autoType +var me *mainType // this app's variables -type autoType struct { +type mainType struct { + once sync.Once // one-time initialized data auto *prep.Auto // more experiments for bash handling forge *forgepb.Forge // your customized repo preferences and settings machine *zoopb.Machine // your customized repo preferences and settings } + +// move these to mainType +var failed map[*gitpb.Repo]string +var state map[*gitpb.Repo]string +var debnames map[*gitpb.Repo]string + +func initForge() { + if me.forge == nil { + me.forge = forgepb.Init() + me.forge.Config.DumpENV() + } + initMachine() +} + +func initMachine() { + if me.machine == nil { + me.machine, _ = zoopb.InitMachine() + } +} + +func initMain() { + // autocomplete must be processed before there is anything sent to STDOUT or STDERR + me.auto = prep.Bash3(&argv) // add support for bash autocomplete with go-arg + + failed = make(map[*gitpb.Repo]string) + state = make(map[*gitpb.Repo]string) + debnames = make(map[*gitpb.Repo]string) + + dumpDebug() +} |
