attempt to fix when not using forge

This commit is contained in:
Jeff Carr 2025-01-18 07:29:44 -06:00
parent 1e5fac4cd8
commit d51f5b385a
10 changed files with 187 additions and 104 deletions

View File

@ -4,7 +4,7 @@ VERSION = $(shell git describe --tags)
DATE = $(shell date +%Y.%m.%d) DATE = $(shell date +%Y.%m.%d)
run: build run: build
./go-deb --repo go.wit.com/apps/autotypist ./go-deb --forge go.wit.com/apps/autotypist
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet
@ -13,10 +13,9 @@ vet:
auto-build: build auto-build: build
./go-deb --auto --repo go.wit.com/apps/autotypist ./go-deb --auto --repo go.wit.com/apps/autotypist
build: build: goimports
-rm resources/*.so -rm resources/*.so
touch resources/blank.so touch resources/blank.so
-cp -a ~/go/src/go.wit.com/toolkits/*/*.so resources/ # embed the toolkit plugins
GO111MODULE="off" go build -v \ GO111MODULE="off" go build -v \
-ldflags "-X main.VERSION=${VERSION} -X main.DATE=${DATE} -X gui.GUIVERSION=${VERSION}" -ldflags "-X main.VERSION=${VERSION} -X main.DATE=${DATE} -X gui.GUIVERSION=${VERSION}"

View File

@ -17,8 +17,8 @@ func RemoveFirstElement(slice []string) (string, []string) {
// homeDir, _ := os.UserHomeDir() // homeDir, _ := os.UserHomeDir()
func (c *controlBox) addRepo(path string) { func (c *controlBox) addRepo() {
path = strings.Trim(path, "/") // trim any extranous '/' chars put in the config file by the user path := strings.Trim(me.goPath, "/") // trim any extranous '/' chars put in the config file by the user
if path == "" { if path == "" {
log.Warn("addRepo() got empty path", path) log.Warn("addRepo() got empty path", path)
return return
@ -53,24 +53,41 @@ func (c *controlBox) addRepo(path string) {
c.tagDate = gadgets.NewBasicEntry(c.grid, "git tag Date") c.tagDate = gadgets.NewBasicEntry(c.grid, "git tag Date")
c.grid.NextRow() c.grid.NextRow()
cbname := repo.GetCurrentBranchName() var cbname string
cbversion := repo.GetCurrentBranchVersion() var cbversion string
debversion := repo.DebianCurrentVersion() var debversion string
if repo.CheckDirty() { if me.repo == nil {
c.dirtyL.SetText("true") cbname = "todo"
cbversion = "todo version"
debversion = "todo deb version"
} else { } 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() == "" { if c.GoPath.String() == "" {
c.GoPath.SetText(repo.GetGoPath()) c.GoPath.SetText(me.goPath)
} }
lasttag := repo.GetLastTagVersion() var lasttag string = "unknown"
if argv.Release { if me.repo != nil {
debversion = repo.DebianReleaseVersion() lasttag = me.repo.GetLastTagVersion()
c.dirtyL.SetText("false") if argv.Release {
debversion = me.repo.DebianReleaseVersion()
c.dirtyL.SetText("false")
}
} }
c.Version.SetText(debversion) c.Version.SetText(debversion)
@ -80,6 +97,5 @@ func (c *controlBox) addRepo(path string) {
tagDate := c.getDateStamp(lasttag) tagDate := c.getDateStamp(lasttag)
c.tagDate.SetText(tagDate) c.tagDate.SetText(tagDate)
return return
} }

16
argv.go
View File

@ -8,8 +8,6 @@ package main
import ( import (
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/debugger"
"go.wit.com/log"
) )
var argv args var argv args
@ -17,7 +15,7 @@ var argv args
type args struct { type args struct {
Auto bool `arg:"--auto" help:"automatically attempt to make the .deb"` Auto bool `arg:"--auto" help:"automatically attempt to make the .deb"`
Ldflags []string `arg:"--ldflags" help:"flags to pass to go build"` 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"` OutDir string `arg:"--dir" help:"write .deb file into this directory"`
Release bool `arg:"--release" help:"build a release from the last git tag"` Release bool `arg:"--release" help:"build a release from the last git tag"`
KeepFiles bool `arg:"--keep-files" help:"keep the build files/"` KeepFiles bool `arg:"--keep-files" help:"keep the build files/"`
@ -27,11 +25,13 @@ type args struct {
func init() { func init() {
arg.MustParse(&argv) arg.MustParse(&argv)
if debugger.ArgDebug() { /*
log.Info("cmd line --debugger == true") if debugger.ArgDebug() {
} else { log.Info("cmd line --debugger == true")
log.Info("cmd line --debugger == false") } else {
} log.Info("cmd line --debugger == false")
}
*/
} }
func (args) Version() string { func (args) Version() string {

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/log" "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") // stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
func (c *controlBox) getDateStamp(tag string) string { 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.Join(r.Stdout, "\n")
out = strings.TrimSpace(out) out = strings.TrimSpace(out)

18
exit.go Normal file
View File

@ -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)
}

43
forge.go Normal file
View File

@ -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)
}

107
main.go
View File

@ -6,10 +6,8 @@ import (
"path/filepath" "path/filepath"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/debugger" "go.wit.com/lib/fhelp"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -18,91 +16,76 @@ import (
var VERSION string var VERSION string
var DATE 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/* //go:embed resources/*
var resources embed.FS var resources embed.FS
func main() { func main() {
if argv.Repo == "" { me = new(mainType)
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)
}
forge = forgepb.Init()
os.Setenv("REPO_WORK_PATH", forge.GetGoSrc())
repo = forge.FindByGoPath(argv.Repo) goSrc, hasWork, err := fhelp.DetermineGoPath()
if repo == nil { if err != nil {
log.Info("repo not found. you need to clone", argv.Repo) badExit(err)
os.Exit(-1) }
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()
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() // build()
myGui = gui.New() me.myGui = gui.New()
if !argv.Auto { 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 // figure out where we are working from
homeDir, _ := os.UserHomeDir() // os.Chdir to that directory
var debpath string var debpath string
if argv.Repo == "." { if me.repo == nil {
os.Setenv("GO_DEB_CUSTOM", "true") os.Setenv("GO_DEB_CUSTOM", "true")
debpath, _ = os.Getwd() debpath, _ = os.Getwd()
} else { } else {
debpath = filepath.Join(homeDir, "go/src", argv.Repo) debpath = me.repo.GetFullPath()
} }
_, basename := filepath.Split(debpath)
me.goPath = basename
os.Chdir(debpath) os.Chdir(debpath)
// scan the repo // scan the repo
cBox.addRepo(argv.Repo) me.cBox.addRepo()
// look for a 'config' file in the repo // look for a 'config' file in the repo
if cBox.readControlFile() == nil { if me.cBox.readControlFile() == nil {
log.Warn("scan worked") log.Warn("scan worked")
} else { } else {
log.Warn("scan failed") log.Warn("scan failed")
} }
cBox.computeControlValues() me.cBox.computeControlValues()
// verify the values for the package // 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 { if argv.Auto {
shell.TestTerminalColor() shell.TestTerminalColor()
// basicWindow.Show() // broken gui package. convert to protobuf // 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") log.Info("build worked")
} else { } else {
log.Warn("build failed:", err) log.Warn("build failed:", err)
@ -111,15 +94,7 @@ func main() {
os.Exit(0) os.Exit(0)
} }
// run the debugger if triggered from the commandline me.basicWindow.Show()
if debugger.ArgDebug() {
go func() {
log.Sleep(2)
debugger.DebugWindow()
}()
}
basicWindow.Show()
// go will sit here until the window exits // go will sit here until the window exits
gui.Watchdog() gui.Watchdog()
os.Exit(0) os.Exit(0)

View File

@ -22,10 +22,10 @@ func (c *controlBox) readControlFile() error {
pairs["Architecture"] = "amd64" // TODO: figure this out pairs["Architecture"] = "amd64" // TODO: figure this out
pairs["Recommends"] = "" pairs["Recommends"] = ""
pairs["Source"] = "notsure" pairs["Source"] = "notsure"
if argv.Repo == "" { if me.repo == nil {
pairs["Description"] = "put something here" pairs["Description"] = "put something here"
} else { } else {
pairs["Description"] = argv.Repo pairs["Description"] = me.repo.GetGoPath()
} }
} }
defer file.Close() defer file.Close()

View File

@ -9,17 +9,18 @@ import (
) )
// This initializes the first window, a group and a button // 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 { func makebasicWindow() *gadgets.BasicWindow {
log.Warn("init basicWindow state") log.Warn("init basicWindow state")
basicWindow = gadgets.NewBasicWindow(myGui, "Create .deb files for GO applications") win := gadgets.NewBasicWindow(me.myGui, "Create .deb files for GO applications")
basicWindow.Make() win.Make()
basicWindow.Custom = func() { win.Custom = func() {
log.Info("got to close") log.Info("got to close")
os.Exit(0) os.Exit(0)
} }
box1 := basicWindow.Box() box1 := win.Box()
cBox = newControl(box1) me.cBox = newControl(box1)
vbox := box1.Box().Horizontal() vbox := box1.Box().Horizontal()
group1 := vbox.NewGroup("controls").Horizontal() // Vertical() group1 := vbox.NewGroup("controls").Horizontal() // Vertical()
@ -29,19 +30,19 @@ func makebasicWindow() *gadgets.BasicWindow {
}) })
group1.NewButton("read control file", func() { group1.NewButton("read control file", func() {
cBox.readControlFile() me.cBox.readControlFile()
}) })
group1.NewButton("Make .deb", func() { group1.NewButton("Make .deb", func() {
basicWindow.Disable() win.Disable()
if ok, err := cBox.buildPackage(); ok { if ok, err := me.cBox.buildPackage(); ok {
log.Info("build worked") log.Info("build worked")
os.Exit(0) os.Exit(0)
} else { } else {
log.Warn("build failed", err) log.Warn("build failed", err)
} }
basicWindow.Enable() win.Enable()
}) })
return basicWindow return win
} }

24
structs.go Normal file
View File

@ -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
}