From e4b679003ce0847dd65254a5e0a0b3239fd0d566 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 3 Oct 2025 13:47:01 -0500 Subject: mv and merge --- debian.go | 90 ---------------------------- doBuild.go | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doDebian.go | 78 +++++++++++++++++++++++++ doInstall.go | 188 ----------------------------------------------------------- 4 files changed, 266 insertions(+), 278 deletions(-) delete mode 100644 debian.go create mode 100644 doBuild.go delete mode 100644 doInstall.go diff --git a/debian.go b/debian.go deleted file mode 100644 index 9a888c2..0000000 --- a/debian.go +++ /dev/null @@ -1,90 +0,0 @@ -// 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(check *gitpb.Repo) error { - var cmd []string - - outdir := getOutdir(check) - os.MkdirAll(outdir, 0755) - - if me.forge.Config.IsReadOnly(check.GetGoPath()) { - return nil - } - - if !check.IsBinary() { - return nil - } - - if check.IsGoPlugin() { - return nil - } - - 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} - return nil - } - - if argv.Verbose || argv.Force { - // log.Info("build cmd:", cmd) - cmd = append(cmd, "--verbose") - } - if argv.DryRun { - return nil - } - - if argv.Force { - // build everything no matter what - } else { - if state[check] != "need to build" { - // log.Info("skipping build for", check.GetGoPath(), state[check]) - return nil - } - } - - var err error - if _, err = check.RunVerboseOnError(cmd); err != nil { - log.Info(check.FullPath, cmd) - failed[check] = fmt.Sprint("godeb failed", cmd, "with", err) - return err - } - - log.Info("build worked", cmd, check.FullPath) - return nil -} - -func getOutdir(repo *gitpb.Repo) string { - if me.forge.Config.IsPrivate(repo.GetGoPath()) { - return "/home/jcarr/incoming-private" - } - if argv.Force { - return "/home/jcarr/incoming" - } - 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" - } - - return "/home/jcarr/incoming" -} diff --git a/doBuild.go b/doBuild.go new file mode 100644 index 0000000..28e1189 --- /dev/null +++ b/doBuild.go @@ -0,0 +1,188 @@ +// 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" + "path/filepath" + + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func doBuild() error { + if argv.Build.Install != nil { + if err := doInstall(); err != nil { + log.Info("doInstall() failed", err) + badExit(err) + } + okExit("EVERYTHING BUILT!") + } + + if argv.Build.MacBuild != nil { + log.Info("todo: add mac builds") + return nil + } + + if argv.Build.Debian != nil { + doDebian() + okExit("") + } + + return nil +} + +func doInstallRepo(check *gitpb.Repo) error { + repotype := check.GetRepoType() + if repotype == "binary" || repotype == "plugin" { + // we only want to process things that can be compiled with 'go build' + } else { + // log.Info("skipping repo", check.GetGoPath(), repotype) + return nil + } + + if me.forge.Config.IsReadOnly(check.GetGoPath()) { + // ignore read only stuff + return nil + } + + if argv.Verbose || argv.Force { + verbose := []string{"-v", "-x"} + if err := me.forge.Install(check, verbose); err != nil { + log.Warn("INSTALL FAILED", check.GetGoPath(), err) + failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err) + return err + } + } else { + if err := me.forge.Install(check, nil); err != nil { + log.Warn("INSTALL FAILED", check.GetGoPath(), err) + failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err) + return err + } + } + return nil +} + +func doInstallScan() { + initForge() // make sure forge is init'd here + + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + check := all.Next() + + repotype := check.GetRepoType() + if repotype == "binary" || repotype == "plugin" { + // we only want to process things that can be compiled with 'go build' + } else { + // log.Info("skipping repo", check.GetGoPath(), repotype) + continue + } + + if me.forge.Config.IsReadOnly(check.GetGoPath()) { + // ignore read only stuff + continue + } + + // var cmd []string + var start string + var end string + + // add te repotype + end += check.GetRepoType() + + manufactured := check.GetCurrentVersion() + ver := trimNonNumericFromStart(manufactured) + name := me.forge.Config.DebName(check.GetGoPath()) + var realver string + if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil { + realver = installedPackage.Version + } + if actualp := me.machine.FindByVersion(name, ver); actualp != nil { + end += " (version match) " + actualp.Version + " " + ver + " " + state[check] = "on mirrors" + } else { + if realver != "" { + end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver) + } + // end += "" + ver + " " + } + if me.machine.IsInstalled(name) { + if actualp := me.machine.FindInstalledByName(name); actualp != nil { + if ver != actualp.Version { + end += "(installed " + actualp.Version + ") " + } else { + end += "(installed ok) " + } + } else { + end += "(installed) " + } + } + + debname := name + "_" + ver + "_amd64.deb" + debnames[check] = debname + outdir := getOutdir(check) + _, err := os.Stat(filepath.Join(outdir, debname)) + if err == nil { + // log.Info("exists", filepath.Join(outdir, debname)) + state[check] = "in incoming" + } else { + // log.Info(debname, "does not exist") + } + + if state[check] == "" { + state[check] = "need to build" + } + start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname) + + if state[check] == "need to build" { + end += " (will build) " + } + + log.Info(start, end) + if name == "" { + // err := fmt.Sprintf("name is blank error %+v", repo) + log.Warn("name is blank error", check.GetGoPath()) + } + } +} + +func doInstall() error { + initForge() + + found := gitpb.NewRepos() + for check := range me.forge.Repos.IterAll() { + if me.forge.Config.IsReadOnly(check.GetGoPath()) { + continue + } + + if !check.IsBinary() { + continue + } + + if check.IsGoPlugin() { + continue + } + found.Append(check) + } + me.forge.PrintForgedTable(found) + + if argv.DryRun { + doInstallScan() + okExit("") + } + + me.forge.ConfigRill(16, 16) + stats := me.forge.RunOnRepos(found, doInstallRepo) + for s, stat := range stats { + if stat.Err == nil { + continue + } + dur := stat.End.Sub(stat.Start) + log.Info("CRAP. INSTALL FAILED", shell.FormatDuration(dur), s, stat.Err) + badExit(stat.Err) + } + return nil +} diff --git a/doDebian.go b/doDebian.go index 8d6aa3e..acd2eae 100644 --- a/doDebian.go +++ b/doDebian.go @@ -71,3 +71,81 @@ func doDebian() { exitOnErrorRealtime([]string{"do-aptly"}) } + +func buildDeb(check *gitpb.Repo) error { + var cmd []string + + outdir := getOutdir(check) + os.MkdirAll(outdir, 0755) + + if me.forge.Config.IsReadOnly(check.GetGoPath()) { + return nil + } + + if !check.IsBinary() { + return nil + } + + if check.IsGoPlugin() { + return nil + } + + 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} + return nil + } + + if argv.Verbose || argv.Force { + // log.Info("build cmd:", cmd) + cmd = append(cmd, "--verbose") + } + if argv.DryRun { + return nil + } + + if argv.Force { + // build everything no matter what + } else { + if state[check] != "need to build" { + // log.Info("skipping build for", check.GetGoPath(), state[check]) + return nil + } + } + + var err error + if _, err = check.RunVerboseOnError(cmd); err != nil { + log.Info(check.FullPath, cmd) + failed[check] = fmt.Sprint("godeb failed", cmd, "with", err) + return err + } + + log.Info("build worked", cmd, check.FullPath) + return nil +} + +func getOutdir(repo *gitpb.Repo) string { + if me.forge.Config.IsPrivate(repo.GetGoPath()) { + return "/home/jcarr/incoming-private" + } + if argv.Force { + return "/home/jcarr/incoming" + } + 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" + } + + return "/home/jcarr/incoming" +} diff --git a/doInstall.go b/doInstall.go deleted file mode 100644 index 28e1189..0000000 --- a/doInstall.go +++ /dev/null @@ -1,188 +0,0 @@ -// 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" - "path/filepath" - - "go.wit.com/lib/gui/shell" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func doBuild() error { - if argv.Build.Install != nil { - if err := doInstall(); err != nil { - log.Info("doInstall() failed", err) - badExit(err) - } - okExit("EVERYTHING BUILT!") - } - - if argv.Build.MacBuild != nil { - log.Info("todo: add mac builds") - return nil - } - - if argv.Build.Debian != nil { - doDebian() - okExit("") - } - - return nil -} - -func doInstallRepo(check *gitpb.Repo) error { - repotype := check.GetRepoType() - if repotype == "binary" || repotype == "plugin" { - // we only want to process things that can be compiled with 'go build' - } else { - // log.Info("skipping repo", check.GetGoPath(), repotype) - return nil - } - - if me.forge.Config.IsReadOnly(check.GetGoPath()) { - // ignore read only stuff - return nil - } - - if argv.Verbose || argv.Force { - verbose := []string{"-v", "-x"} - if err := me.forge.Install(check, verbose); err != nil { - log.Warn("INSTALL FAILED", check.GetGoPath(), err) - failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err) - return err - } - } else { - if err := me.forge.Install(check, nil); err != nil { - log.Warn("INSTALL FAILED", check.GetGoPath(), err) - failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err) - return err - } - } - return nil -} - -func doInstallScan() { - initForge() // make sure forge is init'd here - - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - check := all.Next() - - repotype := check.GetRepoType() - if repotype == "binary" || repotype == "plugin" { - // we only want to process things that can be compiled with 'go build' - } else { - // log.Info("skipping repo", check.GetGoPath(), repotype) - continue - } - - if me.forge.Config.IsReadOnly(check.GetGoPath()) { - // ignore read only stuff - continue - } - - // var cmd []string - var start string - var end string - - // add te repotype - end += check.GetRepoType() - - manufactured := check.GetCurrentVersion() - ver := trimNonNumericFromStart(manufactured) - name := me.forge.Config.DebName(check.GetGoPath()) - var realver string - if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil { - realver = installedPackage.Version - } - if actualp := me.machine.FindByVersion(name, ver); actualp != nil { - end += " (version match) " + actualp.Version + " " + ver + " " - state[check] = "on mirrors" - } else { - if realver != "" { - end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver) - } - // end += "" + ver + " " - } - if me.machine.IsInstalled(name) { - if actualp := me.machine.FindInstalledByName(name); actualp != nil { - if ver != actualp.Version { - end += "(installed " + actualp.Version + ") " - } else { - end += "(installed ok) " - } - } else { - end += "(installed) " - } - } - - debname := name + "_" + ver + "_amd64.deb" - debnames[check] = debname - outdir := getOutdir(check) - _, err := os.Stat(filepath.Join(outdir, debname)) - if err == nil { - // log.Info("exists", filepath.Join(outdir, debname)) - state[check] = "in incoming" - } else { - // log.Info(debname, "does not exist") - } - - if state[check] == "" { - state[check] = "need to build" - } - start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname) - - if state[check] == "need to build" { - end += " (will build) " - } - - log.Info(start, end) - if name == "" { - // err := fmt.Sprintf("name is blank error %+v", repo) - log.Warn("name is blank error", check.GetGoPath()) - } - } -} - -func doInstall() error { - initForge() - - found := gitpb.NewRepos() - for check := range me.forge.Repos.IterAll() { - if me.forge.Config.IsReadOnly(check.GetGoPath()) { - continue - } - - if !check.IsBinary() { - continue - } - - if check.IsGoPlugin() { - continue - } - found.Append(check) - } - me.forge.PrintForgedTable(found) - - if argv.DryRun { - doInstallScan() - okExit("") - } - - me.forge.ConfigRill(16, 16) - stats := me.forge.RunOnRepos(found, doInstallRepo) - for s, stat := range stats { - if stat.Err == nil { - continue - } - dur := stat.End.Sub(stat.Start) - log.Info("CRAP. INSTALL FAILED", shell.FormatDuration(dur), s, stat.Err) - badExit(stat.Err) - } - return nil -} -- cgit v1.2.3