summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-18 07:29:44 -0600
committerJeff Carr <[email protected]>2025-01-18 07:29:44 -0600
commitd51f5b385ab89fd9b898d8feec470289b5db6802 (patch)
treea1f2e74dc83aabd70f62d7fea47007aa89b38d22
parent1e5fac4cd85f0270d9997792fa85c11c35c0d2f2 (diff)
attempt to fix when not using forgev0.22.57
-rw-r--r--Makefile5
-rw-r--r--addRepo.go44
-rw-r--r--argv.go16
-rw-r--r--buildPackage.go9
-rw-r--r--exit.go18
-rw-r--r--forge.go43
-rw-r--r--main.go105
-rw-r--r--readControlFile.go4
-rw-r--r--stateWindow.go21
-rw-r--r--structs.go24
10 files changed, 186 insertions, 103 deletions
diff --git a/Makefile b/Makefile
index 47893e9..cd409a1 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ VERSION = $(shell git describe --tags)
DATE = $(shell date +%Y.%m.%d)
run: build
- ./go-deb --repo go.wit.com/apps/autotypist
+ ./go-deb --forge go.wit.com/apps/autotypist
vet:
@GO111MODULE=off go vet
@@ -13,10 +13,9 @@ vet:
auto-build: build
./go-deb --auto --repo go.wit.com/apps/autotypist
-build:
+build: goimports
-rm resources/*.so
touch resources/blank.so
- -cp -a ~/go/src/go.wit.com/toolkits/*/*.so resources/ # embed the toolkit plugins
GO111MODULE="off" go build -v \
-ldflags "-X main.VERSION=${VERSION} -X main.DATE=${DATE} -X gui.GUIVERSION=${VERSION}"
diff --git a/addRepo.go b/addRepo.go
index b58cd83..9c50d37 100644
--- a/addRepo.go
+++ b/addRepo.go
@@ -17,8 +17,8 @@ func RemoveFirstElement(slice []string) (string, []string) {
// homeDir, _ := os.UserHomeDir()
-func (c *controlBox) addRepo(path string) {
- path = strings.Trim(path, "/") // trim any extranous '/' chars put in the config file by the user
+func (c *controlBox) addRepo() {
+ path := strings.Trim(me.goPath, "/") // trim any extranous '/' chars put in the config file by the user
if path == "" {
log.Warn("addRepo() got empty path", path)
return
@@ -53,24 +53,41 @@ func (c *controlBox) addRepo(path string) {
c.tagDate = gadgets.NewBasicEntry(c.grid, "git tag Date")
c.grid.NextRow()
- cbname := repo.GetCurrentBranchName()
- cbversion := repo.GetCurrentBranchVersion()
- debversion := repo.DebianCurrentVersion()
+ var cbname string
+ var cbversion string
+ var debversion string
- if repo.CheckDirty() {
- c.dirtyL.SetText("true")
+ if me.repo == nil {
+ cbname = "todo"
+ cbversion = "todo version"
+ debversion = "todo deb version"
} else {
- c.dirtyL.SetText("false")
+ cbname = me.repo.GetCurrentBranchName()
+ cbversion = me.repo.GetCurrentBranchVersion()
+ debversion = me.repo.DebianCurrentVersion()
+ }
+
+ if me.repo == nil {
+ c.dirtyL.SetText("unknown")
+ } else {
+ if me.repo.CheckDirty() {
+ c.dirtyL.SetText("true")
+ } else {
+ c.dirtyL.SetText("false")
+ }
}
if c.GoPath.String() == "" {
- c.GoPath.SetText(repo.GetGoPath())
+ c.GoPath.SetText(me.goPath)
}
- lasttag := repo.GetLastTagVersion()
- if argv.Release {
- debversion = repo.DebianReleaseVersion()
- c.dirtyL.SetText("false")
+ var lasttag string = "unknown"
+ if me.repo != nil {
+ lasttag = me.repo.GetLastTagVersion()
+ if argv.Release {
+ debversion = me.repo.DebianReleaseVersion()
+ c.dirtyL.SetText("false")
+ }
}
c.Version.SetText(debversion)
@@ -80,6 +97,5 @@ func (c *controlBox) addRepo(path string) {
tagDate := c.getDateStamp(lasttag)
c.tagDate.SetText(tagDate)
-
return
}
diff --git a/argv.go b/argv.go
index 1ceb6cc..42f53af 100644
--- a/argv.go
+++ b/argv.go
@@ -8,8 +8,6 @@ package main
import (
"go.wit.com/dev/alexflint/arg"
- "go.wit.com/lib/debugger"
- "go.wit.com/log"
)
var argv args
@@ -17,7 +15,7 @@ var argv args
type args struct {
Auto bool `arg:"--auto" help:"automatically attempt to make the .deb"`
Ldflags []string `arg:"--ldflags" help:"flags to pass to go build"`
- Repo string `arg:"--repo" help:"go get path to the repo"`
+ Forge string `arg:"--forge" help:"use a git repo from forge"`
OutDir string `arg:"--dir" help:"write .deb file into this directory"`
Release bool `arg:"--release" help:"build a release from the last git tag"`
KeepFiles bool `arg:"--keep-files" help:"keep the build files/"`
@@ -27,11 +25,13 @@ type args struct {
func init() {
arg.MustParse(&argv)
- if debugger.ArgDebug() {
- log.Info("cmd line --debugger == true")
- } else {
- log.Info("cmd line --debugger == false")
- }
+ /*
+ if debugger.ArgDebug() {
+ log.Info("cmd line --debugger == true")
+ } else {
+ log.Info("cmd line --debugger == false")
+ }
+ */
}
func (args) Version() string {
diff --git a/buildPackage.go b/buildPackage.go
index aa1f1ed..0d8acbf 100644
--- a/buildPackage.go
+++ b/buildPackage.go
@@ -9,6 +9,7 @@ import (
"strings"
"time"
+ "github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
@@ -297,7 +298,13 @@ func (c *controlBox) computeControlValues() bool {
// stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
func (c *controlBox) getDateStamp(tag string) string {
- r := repo.Run([]string{"git", "log", "-1", "--format=%at", tag})
+ var r cmd.Status
+ if me.repo == nil {
+ r = shell.Run([]string{"git", "log", "-1", "--format=%at", tag})
+ } else {
+ r = me.repo.Run([]string{"git", "log", "-1", "--format=%at", tag})
+ }
+
out := strings.Join(r.Stdout, "\n")
out = strings.TrimSpace(out)
diff --git a/exit.go b/exit.go
new file mode 100644
index 0000000..5ddbcf6
--- /dev/null
+++ b/exit.go
@@ -0,0 +1,18 @@
+package main
+
+import (
+ "os"
+
+ "go.wit.com/log"
+)
+
+func okExit(thing string) {
+ log.Info(thing, "ok")
+ // log.Info("Finished go-clean on", check.GetGoPath(), "ok")
+ os.Exit(0)
+}
+
+func badExit(err error) {
+ log.Info("go-deb failed: ", err)
+ os.Exit(-1)
+}
diff --git a/forge.go b/forge.go
new file mode 100644
index 0000000..41cd242
--- /dev/null
+++ b/forge.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "os"
+
+ "go.wit.com/gui"
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/log"
+)
+
+// if there is no "build" file
+// the attempt to use forgepb to init
+// the GO repo
+func doForge() {
+ me.forge = forgepb.Init()
+ os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc())
+
+ me.repo = me.forge.Repos.FindByFullPath(argv.Forge)
+ if me.repo == nil {
+ log.Info("repo not found", argv.Forge)
+ me.repo = me.forge.FindByGoPath(argv.Forge)
+ }
+ if me.repo == nil {
+ log.Info("I could not determine which go repo you have", argv.Forge)
+ log.Info("you must create a build & control file", argv.Forge)
+ os.Exit(-1)
+ }
+ log.Info("found repo", me.repo.GetGoPath())
+ // build()
+}
+
+func doGui() {
+ me.myGui = gui.New()
+ if !argv.Auto {
+ me.myGui.InitEmbed(resources)
+ }
+ me.myGui.Default()
+
+ me.basicWindow.Show()
+ // go will sit here until the window exits
+ gui.Watchdog()
+ os.Exit(0)
+}
diff --git a/main.go b/main.go
index dd5109c..9f62d3f 100644
--- a/main.go
+++ b/main.go
@@ -6,10 +6,8 @@ import (
"path/filepath"
"go.wit.com/gui"
- "go.wit.com/lib/debugger"
- "go.wit.com/lib/gadgets"
+ "go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
- "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
)
@@ -18,91 +16,76 @@ import (
var VERSION string
var DATE string
-// This is the beginning of the binary tree of GUI widgets
-var myGui *gui.Node
-
-// this scans in the repos
-var forge *forgepb.Forge
-var repo *gitpb.Repo
-
-var cBox *controlBox
-
-// this is a basic window. the user can open and close it
-var basicWindow *gadgets.BasicWindow
-
//go:embed resources/*
var resources embed.FS
func main() {
- if argv.Repo == "" {
- log.Info("You need to tell me what repo you want to work on")
- println("")
- println("go-deb --repo go.wit.com/apps/helloworld")
- os.Exit(0)
+ me = new(mainType)
+
+ goSrc, hasWork, err := fhelp.DetermineGoPath()
+ if err != nil {
+ badExit(err)
}
- forge = forgepb.Init()
- os.Setenv("REPO_WORK_PATH", forge.GetGoSrc())
+ log.Info("GO src path", goSrc, "go.work is", hasWork)
+ me.goSrc = goSrc
+ me.hasWork = hasWork
+
+ // set the go src path
+ os.Setenv("REPO_WORK_PATH", goSrc)
+
+ if argv.Forge != "" {
+ me.forge = forgepb.Init()
- repo = forge.FindByGoPath(argv.Repo)
- if repo == nil {
- log.Info("repo not found. you need to clone", argv.Repo)
- os.Exit(-1)
+ me.repo = me.forge.Repos.FindByFullPath(argv.Forge)
+ if me.repo == nil {
+ log.Info("repo not found", argv.Forge)
+ me.repo = me.forge.FindByGoPath(argv.Forge)
+ }
+ if me.repo == nil {
+ log.Info("forge failure. repo not found", argv.Forge)
+ os.Exit(-1)
+ }
+ log.Info("found repo", me.repo.GetGoPath())
}
- log.Info("found repo", argv.Repo)
// build()
- myGui = gui.New()
+ me.myGui = gui.New()
if !argv.Auto {
- myGui.InitEmbed(resources)
+ me.myGui.InitEmbed(resources)
}
- myGui.Default()
+ me.myGui.Default()
- basicWindow = makebasicWindow()
+ me.basicWindow = makebasicWindow()
- // todo: add the go.work file logic here
- homeDir, _ := os.UserHomeDir()
+ // figure out where we are working from
+ // os.Chdir to that directory
var debpath string
- if argv.Repo == "." {
+ if me.repo == nil {
os.Setenv("GO_DEB_CUSTOM", "true")
debpath, _ = os.Getwd()
} else {
- debpath = filepath.Join(homeDir, "go/src", argv.Repo)
+ debpath = me.repo.GetFullPath()
}
+ _, basename := filepath.Split(debpath)
+ me.goPath = basename
os.Chdir(debpath)
// scan the repo
- cBox.addRepo(argv.Repo)
+ me.cBox.addRepo()
// look for a 'config' file in the repo
- if cBox.readControlFile() == nil {
+ if me.cBox.readControlFile() == nil {
log.Warn("scan worked")
} else {
log.Warn("scan failed")
}
- cBox.computeControlValues()
+ me.cBox.computeControlValues()
// verify the values for the package
- if repo == nil {
- if argv.Repo == "." {
- // this means try the local directory for a custom 'control' file
- } else {
- log.Info("argv.Repo =", argv.Repo)
- log.Info("repo not found. Try:")
- log.Info("")
- log.Info(" go-clone", argv.Repo)
- log.Info("")
- os.Exit(-1)
- }
- }
-
- // set the working directory to argv.Repo
- log.Info("cd", repo.FullPath)
- os.Chdir(repo.FullPath)
-
if argv.Auto {
shell.TestTerminalColor()
// basicWindow.Show() // broken gui package. convert to protobuf
- if ok, err := cBox.buildPackage(); ok {
+ if ok, err := me.cBox.buildPackage(); ok {
log.Info("build worked")
} else {
log.Warn("build failed:", err)
@@ -111,15 +94,7 @@ func main() {
os.Exit(0)
}
- // run the debugger if triggered from the commandline
- if debugger.ArgDebug() {
- go func() {
- log.Sleep(2)
- debugger.DebugWindow()
- }()
- }
-
- basicWindow.Show()
+ me.basicWindow.Show()
// go will sit here until the window exits
gui.Watchdog()
os.Exit(0)
diff --git a/readControlFile.go b/readControlFile.go
index ea32da9..32db33f 100644
--- a/readControlFile.go
+++ b/readControlFile.go
@@ -22,10 +22,10 @@ func (c *controlBox) readControlFile() error {
pairs["Architecture"] = "amd64" // TODO: figure this out
pairs["Recommends"] = ""
pairs["Source"] = "notsure"
- if argv.Repo == "" {
+ if me.repo == nil {
pairs["Description"] = "put something here"
} else {
- pairs["Description"] = argv.Repo
+ pairs["Description"] = me.repo.GetGoPath()
}
}
defer file.Close()
diff --git a/stateWindow.go b/stateWindow.go
index 194f220..bc5616d 100644
--- a/stateWindow.go
+++ b/stateWindow.go
@@ -9,17 +9,18 @@ import (
)
// This initializes the first window, a group and a button
+// this is terribly old code. redo this all after widgets are switched to protobuf
func makebasicWindow() *gadgets.BasicWindow {
log.Warn("init basicWindow state")
- basicWindow = gadgets.NewBasicWindow(myGui, "Create .deb files for GO applications")
- basicWindow.Make()
- basicWindow.Custom = func() {
+ win := gadgets.NewBasicWindow(me.myGui, "Create .deb files for GO applications")
+ win.Make()
+ win.Custom = func() {
log.Info("got to close")
os.Exit(0)
}
- box1 := basicWindow.Box()
- cBox = newControl(box1)
+ box1 := win.Box()
+ me.cBox = newControl(box1)
vbox := box1.Box().Horizontal()
group1 := vbox.NewGroup("controls").Horizontal() // Vertical()
@@ -29,19 +30,19 @@ func makebasicWindow() *gadgets.BasicWindow {
})
group1.NewButton("read control file", func() {
- cBox.readControlFile()
+ me.cBox.readControlFile()
})
group1.NewButton("Make .deb", func() {
- basicWindow.Disable()
- if ok, err := cBox.buildPackage(); ok {
+ win.Disable()
+ if ok, err := me.cBox.buildPackage(); ok {
log.Info("build worked")
os.Exit(0)
} else {
log.Warn("build failed", err)
}
- basicWindow.Enable()
+ win.Enable()
})
- return basicWindow
+ return win
}
diff --git a/structs.go b/structs.go
new file mode 100644
index 0000000..c0b0c7d
--- /dev/null
+++ b/structs.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "go.wit.com/dev/alexflint/arg"
+ "go.wit.com/gui"
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/lib/protobuf/gitpb"
+)
+
+var me *mainType
+
+// this app's variables
+type mainType struct {
+ pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
+ goSrc string // path to ~/go/src or go.work file
+ goPath string // the goPath to use for the package
+ hasWork bool // true if using go.work file
+ forge *forgepb.Forge // the interface to the 'forge' protobuf information
+ repo *gitpb.Repo // this is the repo we are in
+ myGui *gui.Node // the gui toolkit handle
+ cBox *controlBox // the GUI box in the main window
+ basicWindow *gadgets.BasicWindow // this is a basic window. the user can open and close it
+}