diff --git a/build.go b/build.go index 24c2879..c1d0dcd 100644 --- a/build.go +++ b/build.go @@ -1,3 +1,3 @@ package main -var build = "305" +var build = "339" diff --git a/gbld.go b/gbld.go index 085f2cd..2fa2315 100644 --- a/gbld.go +++ b/gbld.go @@ -8,7 +8,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -19,7 +18,7 @@ import ( "github.com/AlecAivazis/survey/v2" ) -var version = "1.18.4" +var version = "1.19.2" var VERSIONURL = "http://gozilla.fhi.mpg.de/gbld/version.txt" var UPDATEBASEURL = "http://gozilla.fhi.mpg.de/gbld" @@ -31,7 +30,7 @@ var GO string var GOIMPORTS string var done chan bool - +var r1, r2, r3 *regexp.Regexp func main() { // ========================================================================================== main @@ -77,16 +76,16 @@ func main() { // =============================================================== info() P() P(Cw("Usage:")) - P(Cy(" gbld [-b] [-1] [-i] [-a] [-c ] [-o ] [build name]")) - P(Cy(" gbld -u")) + P(Cy(" gbld [-b] [-1] [-i] [-c ] [-o ] [build name]")) + P(Cy(" gbld [-a] [-u]")) P(Cw(" -b build only")) P(Cw(" -1 run only once")) P(Cw(" -i run gpimports before build")) - P(Cw(" -a build for all platforms")) P(Cw(" -o exec options")) P(Cw(" -c run command after build")) P(Cw(" -v show version")) P(Cw(" -h show help")) + P(Cw(" -a build for all platforms")) P(Cw(" -u upload builds to gozilla")) P() P(Cw(" · if build is supplied the current directory name will be used")) @@ -150,27 +149,46 @@ func main() { // =============================================================== var st int = 1 var xmd *exec.Cmd = nil - if (!*opt_1) { + if (!*opt_1 && !*opt_a && !*opt_u) { PN("\033[2J\033[1;1H") + } info() + + if *opt_a { // ······························································· build for other platforms + targetversion:=gettargetversion(file) + P(Ccb("build for all platforms")) + for _, osys := range oses { + for _, arch := range arches { + + ofile:="bin/"+name+"_"+targetversion+"_"+osys+"_"+arch + P(Cy(ofile)) + + cmd := exec.Command(GO, "build", "-o", ofile, name) + cmd.Env = append(os.Environ(), "GOOS="+osys, "GOARCH="+arch) + cmd.Run() + } + } + + os.WriteFile("bin/version.txt", []byte(targetversion), 0644) + } - if *opt_u { // ······································································ upload builds to gozilla - targetversion:=targetversion(file) - + targetversion:=gettargetversion(file) + P(Ccb("upload builds to gozilla")) + for _, osys := range oses { for _, arch := range arches { ofile:="bin/"+name+"_"+targetversion+"_"+osys+"_"+arch _, err := os.Stat(ofile) if err == nil { - cmd := exec.Command("ssh","root@gozilla","rm", "/db/www/"+prgname()+"/*_"+osys+"_"+arch ) + cmd := exec.Command("ssh","root@gozilla","rm", "/db/www/"+name+"/*_"+osys+"_"+arch ) P(Cy(cmd)) cmd.Run() - cmd = exec.Command("scp",ofile, "root@gozilla:/db/www/"+prgname()) + cmd = exec.Command("scp",ofile, "root@gozilla:/db/www/"+name) P(Cy(cmd)) cmd.Run() } @@ -178,15 +196,20 @@ func main() { // =============================================================== } _, err := os.Stat("bin/version.txt") if err == nil { - cmd := exec.Command("scp","bin/version.txt", "root@gozilla:/db/www/"+prgname()) + cmd := exec.Command("scp","bin/version.txt", "root@gozilla:/db/www/"+name) P(Cy(cmd)) cmd.Run() } - os.Exit(0) } + if (*opt_a || *opt_u) { os.Exit(0) } + + r1 = regexp.MustCompile("^\\.") + r2 = regexp.MustCompile("build\\.go") + r3 = regexp.MustCompile("\\.go$") + for { // ------------------------------------------------------------------------------------------- main loop lmf := lmf("./") @@ -211,6 +234,7 @@ func main() { // =============================================================== readFile, err := os.Open("build.go") if err == nil { + defer readFile.Close() backup("build.go") fileScanner := bufio.NewScanner(readFile) fileScanner.Split(bufio.ScanLines) @@ -226,7 +250,6 @@ func main() { // =============================================================== o = o + line + "\n" } } - readFile.Close() os.WriteFile("build.go", []byte(o), 0644) } @@ -290,23 +313,6 @@ func main() { // =============================================================== } else { // ·············································································· build succeeded - if *opt_a { // ······························································· build for other platforms - for _, osys := range oses { - for _, arch := range arches { - - ofile:="bin/"+name+"_"+targetversion+"_"+osys+"_"+arch - P(Cy(ofile)) - - cmd := exec.Command(GO, "build", "-o", ofile, name) - cmd.Env = append(os.Environ(), "GOOS="+osys, "GOARCH="+arch) - cmd.Run() - } - } - - os.WriteFile("bin/version.txt", []byte(targetversion), 0644) - - } - P(Cb("--- compiling done: " + name + " ---")) if len(*opt_c) > 0 { // ··························································· execute post command @@ -370,7 +376,7 @@ func backup(src string) { // --------------------------------------------------- // ===================================================================================================== SUPPORT -func targetversion(file string) string { // ---------------------------------------------- detect target version +func gettargetversion(file string) string { // ------------------------------------------- detect target version targetversion:="" readFile, err := os.Open(file) if err == nil { @@ -398,11 +404,8 @@ func targetversion(file string) string { // ------------------------------------ func lmf(dir string) int64 { // -------------------------------------- get last modification date from .go files var tmax int64 = 0 - files, err := ioutil.ReadDir("./") + files, err := os.ReadDir(dir) if err == nil { - r1, _ := regexp.Compile("^\\.") - r2, _ := regexp.Compile("build\\.go") - r3, _ := regexp.Compile("\\.go$") for _, file := range files { if r3.MatchString(file.Name()) { if !r1.MatchString(file.Name()) && !r2.MatchString(file.Name()) { diff --git a/tools.go b/tools.go index 9841c92..f0b81cd 100644 --- a/tools.go +++ b/tools.go @@ -29,7 +29,7 @@ import ( "github.com/tidwall/gjson" ) -var tbversion = "0.4.1" +var tbversion = "0.4.3" var CHRS = "VW9IdGJ6eXh1T25DRHdrc2M5MlhOQVNQcEJFWnJhWVY2ZEowaFJLdmoxNUdxVDRJZkZpTTdRZW0zTFc4Z2w=" var LR = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") @@ -48,7 +48,8 @@ func checkforupdate() { // ----------------------------------------------------- sv_lversion, err := semver.NewVersion(lversion) if err == nil { if (sv_lversion.GreaterThan(sv_version)) { - ans:=Yesno(SF("new '%s' version found (%s -> %s), update now?",prg,sv_version,sv_lversion),true); + ans:=Yesno(SF("new '%s' version found (%s -> %s), update now?", + prg,sv_version,sv_lversion),true,false); if (ans) { updateurl:=SF("%s/%s_%s_%s_%s",UPDATEBASEURL,prg,lversion,runtime.GOOS,runtime.GOARCH) @@ -127,7 +128,10 @@ func Inputpw(msg string) string { // ---------------------------------------- Al return tmp } -func Yesno(msg string, def bool) bool { // ------------------------------------------ AlecAivazis/survey: yes/no +func Yesno(msg string, def bool, overwrite bool) bool { // -------------------------- AlecAivazis/survey: yes/no + + if (overwrite) { return true } + var err error tmp := "" if def { @@ -263,11 +267,11 @@ func SF(format string, a ...any) string { return fmt.Sprintf(format, func PE(msg ...string) (n int, err error) { if (len(msg)==2) { return fmt.Fprintf(os.Stdout, "%s: %s (%s)\n", Crb("ERROR"), Cwb(msg[0]),msg[1]) } - return fmt.Fprintf(os.Stdout, "%s: %s\n", Crb("ERROR"), Cwb(msg)) + return fmt.Fprintf(os.Stdout, "%s: %s\n", Crb("ERROR"), Cwb(msg[0])) } func PO(msg ...string) (n int, err error) { if (len(msg)==2) { return fmt.Fprintf(os.Stdout, "%s: %s (%s)\n", Cgb("OK"), Cwb(msg[0]),msg[1]) } - return fmt.Fprintf(os.Stdout, "%s: %s\n", Cgb("OK"), Cwb(msg)) + return fmt.Fprintf(os.Stdout, "%s: %s\n", Cgb("OK"), Cwb(msg[0])) } // ------------------------------------------------------------------------------------------ regular expression