refactor to store info

This commit is contained in:
Jeff Carr 2025-09-11 15:03:44 -05:00
parent b05b706d8b
commit 127f36ca1f
8 changed files with 114 additions and 116 deletions

View File

@ -4,6 +4,8 @@ VERSION = $(shell git describe --tags)
DATE = $(shell date +%Y.%m.%d)
run: clean goimports vet install
junk:
#go-deb --release go.wit.com/apps/go-mod-clean --dir /tmp/
#go-deb go.wit.com/apps/autotypist
#ls -lth /tmp/*deb

View File

@ -95,7 +95,7 @@ func (c *controlBox) addRepo() {
c.lastTag.SetText(lasttag)
c.currentL.SetText(cbname + " " + cbversion)
tagDate := c.getDateStamp(lasttag)
tagDate := getDateStamp(lasttag)
c.tagDate.SetText(tagDate)
return
}

View File

@ -49,10 +49,12 @@ func (a args) DoAutoComplete(argv []string) {
fmt.Println("riscv64")
case "build":
fmt.Println("user devel release")
case "--gui":
fmt.Println("nocui andlabs")
default:
if argv[0] == ARGNAME {
// list the subcommands here
fmt.Println("arch build gui show")
fmt.Println("arch build gui show --gui")
}
}
os.Exit(0)

View File

@ -11,10 +11,11 @@ import (
"github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func buildPackage(c *controlBox) (bool, error) {
func buildPackage(repo *gitpb.Repo) (bool, error) {
// TODO: if dirty, set GO111MODULE
// also, if last tag != version
/*
@ -26,7 +27,7 @@ func buildPackage(c *controlBox) (bool, error) {
*/
// ldflags := "main.GOTAG=" + repo.LastTag()
filename := c.Package.String()
filename := repo.Control["Package"] // c.Package.String()
if filename == "" {
return false, errors.New("filename is blank")
}
@ -36,8 +37,8 @@ func buildPackage(c *controlBox) (bool, error) {
return false, err
}
arch := c.Architecture.String()
version := c.Version.String()
arch := repo.Control["Architecture"] // c.Architecture.String()
version := repo.Control["Version"]
log.Info("version is:", version)
debname := filename + "_" + version + "_" + arch + ".deb"
var fulldebname string
@ -120,7 +121,7 @@ func buildPackage(c *controlBox) (bool, error) {
log.Warn("go build worked")
}
filebase := filepath.Base(c.pathL.String())
filebase := filepath.Base(repo.Control["pathL"]) // c.pathL.String())
if fullfilename != filebase {
// this exception is for when you want to override a package name
// sometimes that's the best option. This way you can keep your
@ -189,7 +190,7 @@ func buildPackage(c *controlBox) (bool, error) {
}
}
if !c.writeDebianControlFile() {
if !writeDebianControlFile(repo) {
return false, errors.New("write control file")
}
if shell.Exists("postinst") {
@ -229,85 +230,78 @@ func buildPackage(c *controlBox) (bool, error) {
return true, nil
}
func (c *controlBox) writeDebianControlFile() bool {
func writeDebianControlFile(repo *gitpb.Repo) bool {
cf, err := os.OpenFile("files/DEBIAN/control", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Info("open control file failed", err)
return false
}
fmt.Fprintln(cf, "Package:", c.Package.String())
fmt.Fprintln(cf, "Source:", c.Source.String())
fmt.Fprintln(cf, "Version:", c.Version.String())
fmt.Fprintln(cf, "Architecture:", c.Architecture.String())
if c.Depends.String() != "" {
fmt.Fprintln(cf, "Depends:", c.Depends.String())
}
if c.BuildDepends.String() != "" {
fmt.Fprintln(cf, "Build-Depends:", c.BuildDepends.String())
}
fmt.Fprintln(cf, "Package:", repo.Control["Package"]) // c.Package.String())
fmt.Fprintln(cf, "Source:", repo.Control["Source"]) // c.Source.String())
fmt.Fprintln(cf, "Version:", repo.Control["Version"]) // c.Version.String())
fmt.Fprintln(cf, "Architecture:", repo.Control["Architecture"]) // c.Architecture.String())
writeControlVar(cf, repo, "Depends")
writeControlVar(cf, repo, "Build-Depends")
stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
// update to now now despite what the GUI is showing
fmt.Fprintln(cf, "Package-Build-Date:", stamp)
if c.tagDate.String() == "" {
// todo: allow this to be set somehow
} else {
fmt.Fprintln(cf, "Git-Tag-Date:", c.tagDate.String())
}
fmt.Fprintln(cf, "Maintainer:", c.Maintainer.String())
fmt.Fprintln(cf, "Packager:", c.Packager.String())
if c.GoPath.String() != "" {
fmt.Fprintln(cf, "GoPath:", c.URL.String())
}
if c.URL.String() != "" {
fmt.Fprintln(cf, "URL:", c.URL.String())
}
if c.Conflicts.String() != "" {
fmt.Fprintln(cf, "Conflicts:", c.Conflicts.String())
}
fmt.Fprintln(cf, "Git-Tag-Date:", "todo: get from repo")
desc := c.Description.String()
writeControlVar(cf, repo, "Maintainer")
writeControlVar(cf, repo, "Packager")
writeControlVar(cf, repo, "GoPath")
writeControlVar(cf, repo, "URL")
writeControlVar(cf, repo, "Conflicts")
desc, _ := repo.Control["Description"] // c.Description.String()
parts := strings.Split(desc, "\n")
fmt.Fprintln(cf, "Description:", strings.Join(parts, "\n "))
return true
}
func writeControlVar(f *os.File, repo *gitpb.Repo, varname string) {
val, _ := repo.Control[varname]
if val == "" {
return
}
fmt.Fprintln(f, val+":", val)
}
// try to guess or figure out the config file values
// if there is not a control file
func (c *controlBox) computeControlValues() bool {
if c.Package.String() == "" {
func computeControlValues(repo *gitpb.Repo) bool {
if repo.Control["Package"] == "" {
// get the package name from the repo name
path := c.pathL.String()
path := repo.Control["pathL"] // c.pathL.String()
parts := strings.Split(path, "/")
name := parts[len(parts)-1]
c.Package.SetText(name)
repo.Control["Package"] = name
}
if c.Source.String() == "" {
c.Source.SetText(c.Package.String())
if repo.Control["Source"] == "" {
repo.Control["Source"] = repo.Control["Package"]
}
if c.BuildDepends.String() == "" {
c.BuildDepends.SetText("golang")
if repo.Control["Build-Depends"] == "" {
repo.Control["Build-Depends"] = repo.Control["golang"]
}
if c.Recommends.String() == "" {
c.Recommends.SetText("go-gui-toolkits")
if repo.Control["Recommends"] == "" {
repo.Control["Recommends"] = repo.Control["go-gui-toolkits"]
}
// TODO: get this from the git log
if c.Maintainer.String() == "" {
c.Maintainer.SetText("made by go-deb")
if repo.Control["Maintainer"] == "" {
repo.Control["Maintainer"] = "todo: get from ENV"
}
// TODO: get this from gitea (or gitlab or github, etc)
// or from the README.md ?
if c.Description.String() == "" {
path := c.pathL.String()
c.Description.SetText("GO binary of " + path)
if repo.Control["Description"] == "" {
repo.Control["Description"] = "todo: put URL here"
}
return true
}
// stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
func (c *controlBox) getDateStamp(tag string) string {
func getDateStamp(tag string) string {
var r cmd.Status
if me.repo == nil {
r = shell.Run([]string{"git", "log", "-1", "--format=%at", tag})

17
main.go
View File

@ -43,10 +43,7 @@ func main() {
log.Info("todo: show", me.repo.GetGoPath())
okExit("")
}
log.Info("todo: show", me.repo.GetNamespace(), me.repo.GetFullPath())
okExit("")
me.basicWindow = makebasicWindow()
log.Info("Namespace:", me.repo.GetNamespace(), "Fullpath:", me.repo.GetFullPath())
// figure out where we are working from
// os.Chdir to that directory
@ -61,27 +58,25 @@ func main() {
me.goPath = basename
os.Chdir(debpath)
// scan the repo
me.cBox.addRepo()
// look for a 'config' file in the repo
if me.cBox.readControlFile() == nil {
if readControlFile(me.repo) == nil {
log.Warn("scan worked")
} else {
log.Warn("scan failed")
}
me.cBox.computeControlValues()
computeControlValues(me.repo)
if argv.Gui != nil {
// only load teh toolkit if you get this far
me.myGui.Start() // loads the GUI toolkit
doGui()
me.basicWindow.Show()
win := makebasicWindow()
win.Show()
debug()
}
log.Info("go-deb: attempting to build package")
if ok, err := buildPackage(me.cBox); ok {
if ok, err := buildPackage(me.repo); ok {
log.Info("build worked")
} else {
log.Warn("build failed:", err)

View File

@ -5,11 +5,12 @@ import (
"os"
"strings"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
// readGitConfig reads and parses the control file
func (c *controlBox) readControlFile() error {
func readControlFile(repo *gitpb.Repo) error {
pairs := make(map[string]string)
var key string
@ -55,46 +56,52 @@ func (c *controlBox) readControlFile() error {
value := strings.TrimSpace(partsNew[1])
pairs[key] = value
}
if repo.Control == nil {
repo.Control = make(map[string]string)
}
for key, value := range pairs {
switch key {
case "Source":
c.Source.SetText(value)
case "Build-Depends":
c.BuildDepends.SetText(value)
case "Description":
c.Description.SetText(value)
case "Maintainer":
c.Maintainer.SetText(value)
case "Packager":
c.Packager.SetText(value)
case "GoPath":
c.GoPath.SetText(value)
case "URL":
c.URL.SetText(value)
case "Depends":
c.Depends.SetText(value)
case "Recommends":
c.Recommends.SetText(value)
case "Conflicts":
c.Conflicts.SetText(value)
case "Version":
c.Version.SetText(value)
case "Package":
c.Package.SetText(value)
// if c.Package.String() != value {
// log.Warn("not sure what to do with Package", c.Package.String(), value)
// }
case "Architecture":
// todo: add logic to find OS arch
if c.Architecture.String() != value {
log.Warn("attempting to set arch to", value)
c.Architecture.SetText(value)
repo.Control[key] = value
/*
switch key {
case "Source":
c.Source.SetText(value)
case "Build-Depends":
c.BuildDepends.SetText(value)
case "Description":
c.Description.SetText(value)
case "Maintainer":
c.Maintainer.SetText(value)
case "Packager":
c.Packager.SetText(value)
case "GoPath":
c.GoPath.SetText(value)
case "URL":
c.URL.SetText(value)
case "Depends":
c.Depends.SetText(value)
case "Recommends":
c.Recommends.SetText(value)
case "Conflicts":
c.Conflicts.SetText(value)
case "Version":
c.Version.SetText(value)
case "Package":
c.Package.SetText(value)
// if c.Package.String() != value {
// log.Warn("not sure what to do with Package", c.Package.String(), value)
// }
case "Architecture":
// todo: add logic to find OS arch
if c.Architecture.String() != value {
log.Warn("attempting to set arch to", value)
c.Architecture.SetText(value)
}
default:
log.Warn("the 'control' file has a value I don't know about")
log.Warn("error unknown key", key, "value:", value)
}
default:
log.Warn("the 'control' file has a value I don't know about")
log.Warn("error unknown key", key, "value:", value)
}
*/
}
if err := scanner.Err(); err != nil {

View File

@ -20,7 +20,8 @@ func makebasicWindow() *gadgets.BasicWindow {
}
box1 := win.Box()
me.cBox = newControl(box1)
// me.cBox = newControl(box1)
newControl(box1)
vbox := box1.Box().Horizontal()
group1 := vbox.NewGroup("controls").Horizontal() // Vertical()
@ -30,12 +31,12 @@ func makebasicWindow() *gadgets.BasicWindow {
})
group1.NewButton("read control file", func() {
me.cBox.readControlFile()
readControlFile(me.repo)
})
group1.NewButton("Make .deb", func() {
win.Disable()
if ok, err := buildPackage(me.cBox); ok {
if ok, err := buildPackage(me.repo); ok {
log.Info("build worked")
os.Exit(0)
} else {

View File

@ -2,7 +2,6 @@ package main
import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/gitpb"
)
@ -11,12 +10,10 @@ 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
repo *gitpb.Repo // this is the repo we are in
myGui *prep.GuiPrep // 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
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
repo *gitpb.Repo // this is the repo we are in
myGui *prep.GuiPrep // the gui toolkit handle
}