better error handling
This commit is contained in:
parent
d02e23a68a
commit
8d25d3996e
20
Makefile
20
Makefile
|
@ -67,13 +67,13 @@ build-all:
|
||||||
go-deb --no-gui --repo golang.org/x/tools/cmd/goimports
|
go-deb --no-gui --repo golang.org/x/tools/cmd/goimports
|
||||||
|
|
||||||
build-releases:
|
build-releases:
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/autotypist
|
-go-deb --release --no-gui --repo go.wit.com/apps/autotypist
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/control-panel-dns
|
-go-deb --release --no-gui --repo go.wit.com/apps/control-panel-dns
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/control-panel-digitalocean
|
-go-deb --release --no-gui --repo go.wit.com/apps/control-panel-digitalocean
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/control-panel-cloudflare
|
-go-deb --release --no-gui --repo go.wit.com/apps/control-panel-cloudflare
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/control-panel-vpn
|
-go-deb --release --no-gui --repo go.wit.com/apps/control-panel-vpn
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/go-gui-toolkits
|
-go-deb --release --no-gui --repo go.wit.com/apps/go-gui-toolkits
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/guireleaser
|
-go-deb --release --no-gui --repo go.wit.com/apps/guireleaser
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/go-deb
|
-go-deb --release --no-gui --repo go.wit.com/apps/go.wit.com
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/go.wit.com
|
-go-deb --release --no-gui --repo go.wit.com/apps/helloworld
|
||||||
go-deb --release --no-gui --repo go.wit.com/apps/helloworld
|
-go-deb --release --no-gui --repo go.wit.com/apps/go-deb
|
||||||
|
|
108
buildPackage.go
108
buildPackage.go
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -14,7 +15,7 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *controlBox) buildPackage() bool {
|
func (c *controlBox) buildPackage() error {
|
||||||
// TODO: if dirty, set GO111MODULE
|
// TODO: if dirty, set GO111MODULE
|
||||||
// also, if last tag != version
|
// also, if last tag != version
|
||||||
/*
|
/*
|
||||||
|
@ -26,35 +27,14 @@ func (c *controlBox) buildPackage() bool {
|
||||||
*/
|
*/
|
||||||
// ldflags := "main.GOTAG=" + repo.LastTag()
|
// ldflags := "main.GOTAG=" + repo.LastTag()
|
||||||
|
|
||||||
if args.Release {
|
|
||||||
os.Unsetenv("GO111MODULE")
|
|
||||||
path := c.pathL.String() + "@latest"
|
|
||||||
cmd := []string{"go", "install", "-v", "-x", path}
|
|
||||||
if shell.Run(cmd) {
|
|
||||||
log.Warn("build worked")
|
|
||||||
} else {
|
|
||||||
log.Warn("build failed")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
os.Setenv("GO111MODULE", "off")
|
|
||||||
if shell.Run([]string{"go", "build", "-v", "-x"}) {
|
|
||||||
log.Warn("build worked")
|
|
||||||
} else {
|
|
||||||
log.Warn("build failed")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
filename := c.Package.String()
|
filename := c.Package.String()
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
log.Warn("build failed")
|
return errors.New("filename is blank")
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if !shell.Exists(filename) {
|
|
||||||
log.Warn("build failed")
|
homeDir, err := os.UserHomeDir()
|
||||||
return false
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
arch := c.Architecture.String()
|
arch := c.Architecture.String()
|
||||||
|
@ -62,34 +42,70 @@ func (c *controlBox) buildPackage() bool {
|
||||||
if version == "" {
|
if version == "" {
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
debname := filename + "_" + version + "_" + arch + ".deb"
|
debname := filename + "_" + version + "_" + arch + ".deb"
|
||||||
|
var fullfilename string
|
||||||
|
if args.Release {
|
||||||
|
fullfilename = filepath.Join(homeDir, "go/bin", filename)
|
||||||
|
} else {
|
||||||
|
fullfilename = filename
|
||||||
|
}
|
||||||
|
shell.Run([]string{"rm", "-f", fullfilename})
|
||||||
|
|
||||||
|
if shell.Exists(fullfilename) {
|
||||||
|
// something wrong
|
||||||
|
return errors.New("binary existed before build")
|
||||||
|
}
|
||||||
|
|
||||||
|
if args.Release {
|
||||||
|
os.Unsetenv("GO111MODULE")
|
||||||
|
path := c.pathL.String() + "@latest"
|
||||||
|
cmd := []string{"go", "install", "-v", "-x", path}
|
||||||
|
if shell.Run(cmd) {
|
||||||
|
log.Warn("go install worked")
|
||||||
|
} else {
|
||||||
|
return errors.New("go install")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// set the GO111 build var to true. pass the versions to the compiler manually
|
||||||
|
os.Setenv("GO111MODULE", "off")
|
||||||
|
vldflag := "-X main.VERSION=" + version
|
||||||
|
gldflag := "-X main.GUIVERSION=" + version // todo: git this from the filesystem
|
||||||
|
if shell.Run([]string{"go", "build", "-v", "-x", "-ldflags", vldflag, gldflag}) {
|
||||||
|
log.Warn("go build worked")
|
||||||
|
} else {
|
||||||
|
return errors.New("go build")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !shell.Exists(fullfilename) {
|
||||||
|
log.Warn("build failed. filename does not exist", fullfilename)
|
||||||
|
return errors.New("missing" + fullfilename)
|
||||||
|
}
|
||||||
|
|
||||||
if shell.Exists("files") {
|
if shell.Exists("files") {
|
||||||
if !shell.Run([]string{"rm", "-rf", "files"}) {
|
if !shell.Run([]string{"rm", "-rf", "files"}) {
|
||||||
log.Warn("rm failed")
|
log.Warn("rm failed")
|
||||||
return false
|
return errors.New("rm files/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if shell.Exists("files") {
|
if shell.Exists("files") {
|
||||||
log.Warn("rm failed")
|
log.Warn("rm failed")
|
||||||
return false
|
return errors.New("rm files/")
|
||||||
}
|
}
|
||||||
if !shell.Mkdir("files/DEBIAN") {
|
if !shell.Mkdir("files/DEBIAN") {
|
||||||
log.Warn("mkdir failed")
|
return errors.New("mkdir files/DEBIAN")
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if !shell.Mkdir("files/usr/bin") {
|
if !shell.Mkdir("files/usr/bin") {
|
||||||
log.Warn("mkdir failed")
|
log.Warn("mkdir failed")
|
||||||
return false
|
return errors.New("mkdir files/usr/bin")
|
||||||
}
|
}
|
||||||
if !shell.Run([]string{"cp", filename, "files/usr/bin"}) {
|
if !shell.Run([]string{"cp", fullfilename, "files/usr/bin"}) {
|
||||||
log.Warn("cp failed")
|
log.Warn("cp failed")
|
||||||
return false
|
return errors.New("cp " + fullfilename)
|
||||||
}
|
}
|
||||||
if !shell.Run([]string{"strip", "files/usr/bin/" + filename}) {
|
if !shell.Run([]string{"strip", "files/usr/bin/" + filename}) {
|
||||||
log.Warn("strip failed")
|
log.Warn("strip failed")
|
||||||
return false
|
return errors.New("strip " + filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// put the README in there (if missing, generate it?)
|
// put the README in there (if missing, generate it?)
|
||||||
|
@ -105,24 +121,15 @@ func (c *controlBox) buildPackage() bool {
|
||||||
if readme != "" {
|
if readme != "" {
|
||||||
path := filepath.Join("files/usr/lib/" + filename)
|
path := filepath.Join("files/usr/lib/" + filename)
|
||||||
if !shell.Mkdir(path) {
|
if !shell.Mkdir(path) {
|
||||||
log.Warn("mkdir failed")
|
return errors.New("no files/usr/lib")
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if !shell.Run([]string{"cp", readme, path}) {
|
if !shell.Run([]string{"cp", readme, path}) {
|
||||||
log.Warn("cp failed")
|
return errors.New("cp readme")
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.writeFiles() {
|
if !c.writeFiles() {
|
||||||
log.Warn("write control file failed")
|
return errors.New("write control file")
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
homeDir, err := os.UserHomeDir()
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("os.UserHomeDir() failed")
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// experiment for the toolkit package
|
// experiment for the toolkit package
|
||||||
|
@ -139,14 +146,13 @@ func (c *controlBox) buildPackage() bool {
|
||||||
|
|
||||||
shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname})
|
shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname})
|
||||||
if shell.Exists(fulldebname) {
|
if shell.Exists(fulldebname) {
|
||||||
log.Warn("build worked")
|
|
||||||
} else {
|
} else {
|
||||||
log.Warn("build failed")
|
log.Warn("build failed")
|
||||||
return false
|
return errors.New("dpkg-deb --build worked")
|
||||||
}
|
}
|
||||||
shell.Run([]string{"dpkg-deb", "-I", fulldebname})
|
shell.Run([]string{"dpkg-deb", "-I", fulldebname})
|
||||||
shell.Run([]string{"dpkg-deb", "-c", fulldebname})
|
shell.Run([]string{"dpkg-deb", "-c", fulldebname})
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controlBox) writeFiles() bool {
|
func (c *controlBox) writeFiles() bool {
|
||||||
|
|
6
main.go
6
main.go
|
@ -6,9 +6,9 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
"go.wit.com/lib/debugger"
|
"go.wit.com/lib/debugger"
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,10 +49,10 @@ func main() {
|
||||||
|
|
||||||
if args.NoGui {
|
if args.NoGui {
|
||||||
shell.TestTerminalColor()
|
shell.TestTerminalColor()
|
||||||
if cBox.buildPackage() {
|
if err := cBox.buildPackage(); err == nil {
|
||||||
log.Info("build worked")
|
log.Info("build worked")
|
||||||
} else {
|
} else {
|
||||||
log.Warn("build failed")
|
log.Warn("build failed:", err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
|
@ -36,10 +36,10 @@ func makebasicWindow() *gadgets.BasicWindow {
|
||||||
|
|
||||||
group1.NewButton("Make .deb", func() {
|
group1.NewButton("Make .deb", func() {
|
||||||
basicWindow.Disable()
|
basicWindow.Disable()
|
||||||
if cBox.buildPackage() {
|
if err := cBox.buildPackage(); err == nil {
|
||||||
log.Info("build worked")
|
log.Info("build worked")
|
||||||
} else {
|
} else {
|
||||||
log.Warn("build failed")
|
log.Warn("build failed", err)
|
||||||
}
|
}
|
||||||
basicWindow.Enable()
|
basicWindow.Enable()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue