summaryrefslogtreecommitdiff
path: root/buildPackage.go
diff options
context:
space:
mode:
Diffstat (limited to 'buildPackage.go')
-rw-r--r--buildPackage.go100
1 files changed, 47 insertions, 53 deletions
diff --git a/buildPackage.go b/buildPackage.go
index 1ed710c..5f2f2a7 100644
--- a/buildPackage.go
+++ b/buildPackage.go
@@ -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")
+
+ writeControlVar(cf, repo, "Maintainer")
+ writeControlVar(cf, repo, "Packager")
+ writeControlVar(cf, repo, "GoPath")
+ writeControlVar(cf, repo, "URL")
+ writeControlVar(cf, repo, "Conflicts")
- desc := c.Description.String()
+ 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})