diff options
| author | Jeff Carr <[email protected]> | 2025-09-11 17:41:59 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-11 17:41:59 -0500 | 
| commit | 95d1f6fc7c6af1565749979d1ac7a85fbb311de6 (patch) | |
| tree | 2fd90a03cdaf82c9052792e76139f248dc221e0b | |
| parent | d011972b708cb5cab8e95c1c5f9459c3a451c277 (diff) | |
more fixes. almost works againv0.22.130
| -rw-r--r-- | build.go | 83 | ||||
| -rw-r--r-- | doGui.go | 6 | ||||
| -rw-r--r-- | readControlFile.go | 17 | ||||
| -rw-r--r-- | update.go | 5 | 
4 files changed, 67 insertions, 44 deletions
@@ -32,16 +32,11 @@ func buildPackage(repo *gitpb.Repo) (bool, error) {  		return false, errors.New("filename is blank")  	} -	homeDir, err := os.UserHomeDir() -	if err != nil { -		return false, err -	} -  	arch := repo.Control["Architecture"] // c.Architecture.String()  	if arch == "" {  		arch = "amd64" // todo: detect what you are building on  	} -	version := repo.GetCurrentVersion() +	version := repo.Control["Version"]  	log.Info("version is:", version)  	debname := filename + "_" + version + "_" + arch + ".deb"  	var fulldebname string @@ -57,12 +52,19 @@ func buildPackage(repo *gitpb.Repo) (bool, error) {  	}  	var fullfilename string -	if argv.Release { -		fullfilename = filepath.Join(homeDir, "go/bin", filename) -	} else { -		fullfilename = filename +	_, fullfilename = filepath.Split(filename) + +	if fullfilename == "" { +		log.Info("fullfilename =", fullfilename) +		badExit(log.Errorf("binary name was blank")) +	} +	if fullfilename == "." { +		log.Info("fullfilename =", fullfilename) +		badExit(log.Errorf("binary name was .")) +	} +	if shell.Exists(fullfilename) { +		repo.RunVerbose([]string{"rm", "-f", fullfilename})  	} -	shell.Run([]string{"rm", "-f", fullfilename})  	if shell.Exists(fullfilename) {  		// something wrong @@ -117,7 +119,7 @@ func buildPackage(repo *gitpb.Repo) (bool, error) {  			cmd = append(cmd, "-ldflags", "-X "+flag)  		} -		_, err := shell.RunVerbose(cmd) +		err := repo.RunVerbose(cmd)  		if err != nil {  			return false, fmt.Errorf("go build err %v", err)  		} @@ -139,15 +141,15 @@ func buildPackage(repo *gitpb.Repo) (bool, error) {  	}  	if shell.Exists("files") { -		shell.Run([]string{"rm", "-rf", "files"}) +		repo.RunVerbose([]string{"rm", "-rf", "files"})  		// log.Info("running sync") -		shell.Run([]string{"sync"}) +		repo.RunVerbose([]string{"sync"})  		if shell.Exists("files") {  			log.Warn("rm failed for some reason")  			return false, errors.New("rm files/")  		}  	} -	shell.Run([]string{"sync"}) // for some reason the next check fails sometimes? +	repo.RunVerbose([]string{"sync"}) // for some reason the next check fails sometimes?  	if shell.Exists("files") {  		// probably the 'shell' package id being stupid and not waiting for the process to actually exit  		log.Warn("rm failed. files/ still exists. is golang doing these in parallel?") @@ -162,14 +164,20 @@ func buildPackage(repo *gitpb.Repo) (bool, error) {  	}  	if os.Getenv("GO_DEB_CUSTOM") == "true" {  		// skip cp & strip on custom 'control' files +		// probably deprecate this +		log.Info("REPO GO_DEB_CUSTOM=true means binary is not copied")  	} else { -		if r := shell.Run([]string{"cp", fullfilename, "files/usr/bin"}); r.Error != nil { +		fname := repo.Control["Package"] +		cmd := []string{"cp", fname, "files/usr/bin"} +		log.Info("REPO FILENAME cp", cmd) +		if err := repo.RunVerbose(cmd); err != nil {  			log.Warn("cp failed") -			return false, r.Error +			return false, err  		} -		if r := shell.Run([]string{"strip", "files/usr/bin/" + filename}); r.Error != nil { +		cmd = []string{"strip", "files/usr/bin/" + filename} +		if err := repo.RunVerbose(cmd); err != nil {  			log.Warn("strip failed") -			return false, r.Error +			return false, err  		}  	} @@ -188,8 +196,8 @@ func buildPackage(repo *gitpb.Repo) (bool, error) {  		if err := os.MkdirAll(path, os.ModePerm); err != nil {  			return false, errors.New("no files/usr/lib")  		} -		if r := shell.Run([]string{"cp", readme, path}); r.Error != nil { -			return false, r.Error +		if err := repo.RunVerbose([]string{"cp", readme, path}); err != nil { +			return false, err  		}  	} @@ -197,33 +205,38 @@ func buildPackage(repo *gitpb.Repo) (bool, error) {  		return false, errors.New("write control file")  	}  	if shell.Exists("postinst") { -		shell.Run([]string{"cp", "postinst", "files/DEBIAN/"}) +		repo.RunVerbose([]string{"cp", "postinst", "files/DEBIAN/"})  	}  	// experiment for the toolkit package  	// if the git repo has a "./build" script run it before packaging  	// this way the user can put custom files in the .deb package  	if shell.Exists("build") { -		shell.Run([]string{"./build"}) +		log.Info(repo.FullPath, "FOUND ./build HERE") +		repo.RunVerbose([]string{"./build"}) +	} else { +		log.Info(repo.FullPath, "NOT FOUND ./build HERE")  	} -	shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname}) +	cmd := []string{"dpkg-deb", "--build", "files", fulldebname} +	result := repo.RunVerbose(cmd)  	if shell.Exists(fulldebname) {  	} else { +		log.Warn("CMD FAILED", cmd, result)  		log.Warn("build failed: full name was not created:", fulldebname)  		return false, errors.New("dpkg-deb --build failed")  	} -	shell.Run([]string{"dpkg-deb", "-I", fulldebname}) -	shell.Run([]string{"dpkg-deb", "-c", fulldebname}) +	repo.RunVerbose([]string{"dpkg-deb", "-I", fulldebname}) +	repo.RunVerbose([]string{"dpkg-deb", "-c", fulldebname})  	// cleanup files  	if shell.Exists("files") {  		if argv.KeepFiles {  			log.Info("keeping the build files/")  		} else { -			shell.Run([]string{"rm", "-rf", "files"}) +			repo.RunVerbose([]string{"rm", "-rf", "files"})  			// log.Info("running sync") -			shell.Run([]string{"sync"}) +			repo.RunVerbose([]string{"sync"})  			if shell.Exists("files") {  				log.Warn("rm -rf files/ failed. Run() returned false")  				return false, errors.New("rm files/") @@ -240,9 +253,9 @@ func writeDebianControlFile(repo *gitpb.Repo) bool {  		log.Info("open control file failed", err)  		return false  	} -	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, "Package:", repo.Control["Package"]) // c.Package.String()) +	fmt.Fprintln(cf, "Source:", repo.Control["Source"])   // c.Source.String()) +	fmt.Fprintln(cf, "Version:", repo.Control["Version"])  	fmt.Fprintln(cf, "Architecture:", repo.Control["Architecture"]) // c.Architecture.String())  	writeControlVar(cf, repo, "Depends") @@ -271,7 +284,7 @@ func writeControlVar(f *os.File, repo *gitpb.Repo, varname string) {  	if val == "" {  		return  	} -	fmt.Fprintln(f, val+":", val) +	fmt.Fprintln(f, varname+":", val)  }  // try to guess or figure out the config file values @@ -306,11 +319,7 @@ func computeControlValues(repo *gitpb.Repo) bool {  func getDateStamp(tag string) string {  	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}) -	} +	r = me.repo.Run([]string{"git", "log", "-1", "--format=%at", tag})  	out := strings.Join(r.Stdout, "\n")  	out = strings.TrimSpace(out) @@ -39,10 +39,6 @@ func doGui() {  		writeDebianControlFile(me.repo)  	}) -	group1.NewButton("update gui", func() { -		updateControl(cbox) -	}) -  	group1.NewButton("dump repo.Control", func() {  		// log.Info("CONTROL:", me.repo.Control)  		for v := range me.repo.Control { @@ -63,6 +59,8 @@ func doGui() {  	grid := win.Middle.RawGrid()  	cbox = newControl(grid) + +	updateControl(cbox)  }  // This initializes the control box diff --git a/readControlFile.go b/readControlFile.go index 21e141a..b53a79d 100644 --- a/readControlFile.go +++ b/readControlFile.go @@ -4,11 +4,26 @@ import (  	"bufio"  	"os"  	"strings" +	"unicode"  	"go.wit.com/lib/protobuf/gitpb"  	"go.wit.com/log"  ) +func trimNonNumericPrefix(s string) string { +	// Find the index of the first character that IS a digit. +	firstDigitIndex := strings.IndexFunc(s, unicode.IsDigit) + +	// If no digit is found, IndexFunc returns -1. +	// In this case, the result should be an empty string. +	if firstDigitIndex == -1 { +		return "" +	} + +	// Return the substring starting from the first digit. +	return s[firstDigitIndex:] +} +  // readGitConfig reads and parses the control file  func readControlFile(repo *gitpb.Repo) error {  	pairs := make(map[string]string) @@ -31,6 +46,8 @@ func readControlFile(repo *gitpb.Repo) error {  	}  	defer file.Close() +	pairs["Version"] = trimNonNumericPrefix(repo.GetCurrentVersion()) +  	scanner := bufio.NewScanner(file)  	for scanner.Scan() {  		line := scanner.Text() @@ -4,13 +4,12 @@ func updateControl(c *controlBox) {  	c.Namespace.SetText(me.repo.Namespace)  	c.URL.SetText(me.repo.URL)  	c.Package.SetText(me.repo.Control["Package"]) -	c.Source.SetText(me.repo.Control["Package"]) +	c.Source.SetText(me.repo.Control["Source"])  	c.Maintainer.SetText(me.repo.Control["Maintainer"])  	c.Packager.SetText(me.repo.Control["Packager"]) -	c.Version.SetText(me.repo.GetCurrentVersion()) +	c.Version.SetText(me.repo.Control["Version"])  	c.Description.SetText(me.repo.Control["Description"])  	c.Depends.SetText(me.repo.Control["Depends"]) -	c.Package.SetText(me.repo.Control["Package"])  	c.Recommends.SetText(me.repo.Control["Recommends"])  	c.Architecture.SetText("amd64")  | 
