summaryrefslogtreecommitdiff
path: root/build.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-11 17:41:59 -0500
committerJeff Carr <[email protected]>2025-09-11 17:41:59 -0500
commit95d1f6fc7c6af1565749979d1ac7a85fbb311de6 (patch)
tree2fd90a03cdaf82c9052792e76139f248dc221e0b /build.go
parentd011972b708cb5cab8e95c1c5f9459c3a451c277 (diff)
more fixes. almost works againv0.22.130
Diffstat (limited to 'build.go')
-rw-r--r--build.go83
1 files changed, 46 insertions, 37 deletions
diff --git a/build.go b/build.go
index 0904c0b..becbcd4 100644
--- a/build.go
+++ b/build.go
@@ -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)