From 339f5ff27e96da6eb02e158aa0b33de8104618ca Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 14 Feb 2025 17:27:00 -0600 Subject: [PATCH] complete restructure --- Makefile | 14 +++++ argv.go | 1 + doDebian.go | 68 +++++++++++++++-------- doInstall.go | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ doListRepos.go | 93 +++++++++++++++++++++++++++++++ doWITCOM.go | 1 - main.go | 17 +++++- 7 files changed, 311 insertions(+), 28 deletions(-) create mode 100644 doInstall.go create mode 100644 doListRepos.go diff --git a/Makefile b/Makefile index 5aa6415..36fbdce 100644 --- a/Makefile +++ b/Makefile @@ -32,3 +32,17 @@ gpl: check-git-clean: @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) + +debian-release: install + wit-test debian --dry-run --verbose --release + +debian-release-force: install + rm -f ~/incoming/*.deb + forge --install go.wit.com/apps/go-deb + go-deb -h # check to make sure go-deb builds + -wit-test debian --force --verbose --release + ls -hl ~/incoming/ + dpkg-deb -c ~/incoming/go-gui-toolkits*.deb + +debian-force: install + wit-test debian --force --verbose diff --git a/argv.go b/argv.go index 464f755..d3d1449 100644 --- a/argv.go +++ b/argv.go @@ -27,6 +27,7 @@ type args struct { Release bool `arg:"--release" help:"use go-deb --release"` 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"` Recursive bool `arg:"--recursive" help:"go-clone --recursive"` Test bool `arg:"--test" help:"test build after everything else"` WITCOM bool `arg:"--witcom" help:"add the GPL header"` diff --git a/doDebian.go b/doDebian.go index 7681bec..d844090 100644 --- a/doDebian.go +++ b/doDebian.go @@ -6,56 +6,76 @@ package main import ( "fmt" "os" - "path/filepath" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func buildDeb() { - if argv.DryRun { - return - } log.DaemonMode(true) defer log.DaemonMode(false) + if err := doInstall(); err != nil { + log.Info("doInstall() failed", err) + badExit(err) + } + all := me.forge.Repos.SortByFullPath() for all.Scan() { var cmd []string check := all.Next() - if state[check] != "need to build" { - // log.Info("skipping build for", check.GetGoPath(), state[check]) - continue - } - outdir := getOutdir(check) os.MkdirAll(outdir, 0755) - _, 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 + if me.forge.Config.IsReadOnly(check.GetGoPath()) { + continue + } + + if !check.IsBinary() { continue } if argv.Release { - cmd = []string{"go-deb", "--release", "--auto", "--forge", check.GetGoPath(), "--dir", outdir} + cmd = []string{"go-deb", "--release", "--no-gui", "--auto", "--forge", check.GetGoPath(), "--dir", outdir} } else { cmd = []string{"go-deb", "--auto", "--no-gui", "--forge", check.GetGoPath(), "--dir", outdir} } if me.forge.Config.IsPrivate(check.GetGoPath()) { - cmd = []string{"go-deb", "--auto", "--forge", check.GetGoPath(), "--dir", outdir} + cmd = []string{"go-deb", "--auto", "--no-gui", "--forge", check.GetGoPath(), "--dir", outdir} + continue } - log.Info("build cmd:", cmd) - if r := check.RunRealtime(cmd); r.Error != nil { - log.Info("go-deb failed error:", r.Error, check.GetGoPath()) - failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error) - } else if r.Exit != 0 { - log.Info("go-deb failed exit =", r.Exit, check.GetGoPath()) - failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error) + + if argv.Verbose { + log.Info("build cmd:", cmd) + } + 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 + } + } + + /* + _, 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 { + failed[check] = fmt.Sprint("godeb failed", cmd, "with", err) + badExit(err) } else { log.Info("build worked") } diff --git a/doInstall.go b/doInstall.go new file mode 100644 index 0000000..bfa77e4 --- /dev/null +++ b/doInstall.go @@ -0,0 +1,145 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "errors" + "fmt" + "os" + "path/filepath" + + "go.wit.com/log" +) + +func doInstall() error { + 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.forge.Machine.FindInstalledByName(name); installedPackage != nil { + realver = installedPackage.Version + } + if actualp := me.forge.Machine.FindVersion(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.forge.Machine.IsInstalled(name) { + if actualp := me.forge.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()) + } + + if argv.DryRun { + continue + } + if argv.TestBuild != nil { + if argv.DryRun { + continue + } + if argv.Verbose { + verbose := []string{"-v", "-x"} + if err := me.forge.Build(check, verbose); err != nil { + log.Warn("BUILD FAILED", check.GetGoPath(), err) + failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err) + } + } else { + if err := me.forge.Build(check, nil); err != nil { + log.Warn("BUILD FAILED", check.GetGoPath(), err) + failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err) + } + } + continue + } + + log.Info("STARTING 'make install' in", check.GetGoPath()) + if argv.DryRun { + continue + } + if argv.Verbose { + 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) + } + } 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) + } + } + } + if len(failed) != 0 { + log.Info("") + log.Info("something failed on:") + for repo, cmd := range failed { + log.Info("failed cmd :", cmd, repo.GetGoPath()) + } + // me.forge.CheckoutUser() + // shell.Run([]string{"forge", "--find-private"}) + badExit(errors.New("some repos failed")) + return errors.New("some repos failed") + } + return nil +} diff --git a/doListRepos.go b/doListRepos.go new file mode 100644 index 0000000..e5f34c6 --- /dev/null +++ b/doListRepos.go @@ -0,0 +1,93 @@ +// 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/log" +) + +func doListRepos() { + 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.forge.Machine.FindInstalledByName(name); installedPackage != nil { + realver = installedPackage.Version + } + if actualp := me.forge.Machine.FindVersion(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.forge.Machine.IsInstalled(name) { + if actualp := me.forge.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()) + } + } +} diff --git a/doWITCOM.go b/doWITCOM.go index 085a332..c5e8ddc 100644 --- a/doWITCOM.go +++ b/doWITCOM.go @@ -1,7 +1,6 @@ // Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 - package main import ( diff --git a/main.go b/main.go index 91a3a50..d39b174 100644 --- a/main.go +++ b/main.go @@ -102,6 +102,20 @@ func main() { okExit("") } + doListRepos() + if argv.DebBuild != nil { + buildDeb() + okExit("") + } + if argv.MakeInstall != nil { + if err := doInstall(); err != nil { + log.Info("doInstall() failed", err) + badExit(err) + } else { + okExit("EVERYTHING BUILT!") + } + } + all := me.forge.Repos.SortByFullPath() for all.Scan() { check := all.Next() @@ -222,9 +236,6 @@ func main() { continue } } - if argv.DebBuild != nil { - buildDeb() - } if len(failed) != 0 { log.Info("") log.Info("something failed on:")