Compare commits

...

33 Commits

Author SHA1 Message Date
Jeff Carr 6732640068 fix build 2025-09-22 16:34:17 -05:00
Jeff Carr ac02bbc094 dep stuff 2025-09-11 22:14:48 -05:00
Jeff Carr cd75bd9f61 set default max to 50 2025-09-11 18:40:17 -05:00
Jeff Carr e9e318c4b2 back to a common forge.Init() 2025-09-11 04:38:37 -05:00
Jeff Carr b984a53aac new init() and config() 2025-09-11 03:36:47 -05:00
Jeff Carr c8d67da4cc use --max counter 2025-09-09 12:38:30 -05:00
Jeff Carr 519be64689 argv 2025-09-09 09:25:56 -05:00
Jeff Carr e629211edd make args work again 2025-09-09 08:41:15 -05:00
Jeff Carr 49820069c9 minor fix to make me happier 2025-09-04 10:38:41 -05:00
Jeff Carr 9c3fff72b2 minor 2025-08-16 21:51:46 -05:00
Jeff Carr 1602db0d1e fix lookup 2025-03-23 11:42:59 -05:00
Jeff Carr f0e327f834 this was broken 2025-02-22 09:42:13 -06:00
Jeff Carr d687de6c04 fix build with zoopb out of forge 2025-02-22 07:17:13 -06:00
Jeff Carr 84c772dc41 attempt to merge devel 2025-02-22 04:46:51 -06:00
Jeff Carr 9139a4a6b4 duh. make fails 2025-02-22 04:05:21 -06:00
Jeff Carr 1e62b82640 allow building just changed .deb packages 2025-02-22 03:41:23 -06:00
Jeff Carr 1bda450759 minor 2025-02-21 05:41:39 -06:00
Jeff Carr ee49338376 new autogenpb 2025-02-20 09:39:31 -06:00
Jeff Carr e86ac8c728 don't need the other ones 2025-02-15 12:31:30 -06:00
Jeff Carr 2aee70c24e also put CC on .proto files 2025-02-15 05:33:47 -06:00
Jeff Carr cb8ebc9e04 ignore building go plugins 2025-02-14 20:39:50 -06:00
Jeff Carr 48585f15a5 attempt to stabilize deb package creation 2025-02-14 18:39:14 -06:00
Jeff Carr 339f5ff27e complete restructure 2025-02-14 17:27:00 -06:00
Jeff Carr 22e0cbe022 add common GPL headers 2025-02-01 11:38:22 -06:00
Jeff Carr 899cbb3483 maybe right? 2025-02-01 11:26:07 -06:00
Jeff Carr a6c5755fcd add the GPL headers 2025-02-01 11:22:46 -06:00
Jeff Carr 0b5c7de337 test code 2025-01-29 12:28:36 -06:00
Jeff Carr fb372aad6f code rearange 2025-01-20 01:40:14 -06:00
Jeff Carr 96f2795bf3 updated go-deb syntax 2025-01-18 15:48:15 -06:00
Jeff Carr 6e7049f4a8 fix autocomplete 'upgrade' 2025-01-17 06:04:51 -06:00
Jeff Carr 14fc461af8 old 2025-01-08 10:11:01 -06:00
Jeff Carr f213d26ceb general fixups 2025-01-07 21:21:44 -06:00
Jeff Carr 7e47940796 cleanups due to autocomplete support 2025-01-07 17:17:01 -06:00
12 changed files with 801 additions and 322 deletions

View File

@ -2,82 +2,66 @@ VERSION = $(shell git describe --tags)
GUIVERSION = $(shell git describe --tags) GUIVERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d) BUILDTIME = $(shell date +%Y.%m.%d)
all: go-build all: install
@echo "make debian-dry-run # shows what could be packaged"
@echo "make debian-build # make .deb files for versions that are missing"
@echo "make test-build # test build everything"
@echo "make make-install # run 'make install' in each app repo to copy to ~/go/bin"
@echo "make list # --list: list packaged apps in the wit repo"
@echo "make update # --update: run apt update and apt install on all packages"
@echo "make repomap # parse the go.wit.com repomap"
go-build: goimports go-build: goimports
GO111MODULE=off go build \ GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
verbose:
GO111MODULE=off go build -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
install: goimports
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
vet: vet:
GO111MODULE=off go vet GO111MODULE=off go vet
only-me: go-build
./wit-test --only-me
stderr: go-build stderr: go-build
echo "writing to /tmp/wit-test.log" echo "writing to /tmp/wit-test.log"
./wit-test >/tmp/wit-test.log 2>&1 ./wit-test >/tmp/wit-test.log 2>&1
goimports: goimports:
reset
goimports -w *.go goimports -w *.go
# // to globally reset paths: # // to globally reset paths:
# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go # // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go
gocui: go-build clean:
./wit-test --gui gocui >/tmp/wit-test.log 2>&1 rm -f go.*
install: goimports gpl:
GO111MODULE=off go install \ wit-test --witcom
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
check-git-clean: check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
list: go-build old-debian-release: install
./wit-test --no-gui --list wit-test debian --dry-run --verbose --release
pull: go-build debian-release: install
./wit-test --git-pull forge dirty
rm -f ~/incoming/*.deb
update: go-build rm -f ~/go/lib/go-gui/*
./wit-test --apt-update --dry-run forge --install go.wit.com/apps/go-deb
go-deb -h # check to make sure go-deb builds
force-build: go-build wit-test debian --verbose
./wit-test --force ls -hl ~/incoming/
make-install: install
wit-test --no-gui --make-install
forge --find-private
test-build: go-build
./wit-test --test-build
make-install-dry-run: go-build
./wit-test --no-gui --make-install --dry-run
protobuf:
go-clone go.wit.com/apps/go-clone
debian-dry-run: go-build
./wit-test --no-gui --dry-run --debian
debian-build: go-build
./wit-test --no-gui --debian
do-aptly do-aptly
rm -f ~/go/bin/forged # causes bash completion annoyances
repomap: go-build debian-release-force: install
./wit-test --no-gui --repomap /etc/gowebd/repomap forge dirty
rm -f ~/incoming/*.deb
rm -f ~/go/lib/go-gui/*
forge --install go.wit.com/apps/go-deb
go-deb -h # check to make sure go-deb builds
wit-test debian --force --verbose
ls -hl ~/incoming/
-dpkg-deb -c ~/incoming/go-gui-toolkits*.deb
do-aptly
rm -f ~/go/bin/forged # causes bash completion annoyances
repomap-dryrun: go-build debian-release-build-only: install
./wit-test --no-gui --repomap /etc/gowebd/repomap --dry-run wit-test debian --verbose --release
test: go-build
./wit-test --no-gui --make-install --test

59
argv.go
View File

@ -1,3 +1,6 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
/* /*
@ -6,7 +9,9 @@ package main
*/ */
import ( import (
"go.wit.com/dev/alexflint/arg" "fmt"
"os"
"go.wit.com/lib/debugger" "go.wit.com/lib/debugger"
"go.wit.com/lib/gui/logsettings" "go.wit.com/lib/gui/logsettings"
"go.wit.com/log" "go.wit.com/log"
@ -15,21 +20,28 @@ import (
var argv args var argv args
type args struct { type args struct {
TestBuild bool `arg:"--test-build" help:"try appropriate 'go build'"` TestBuild *EmptyCmd `arg:"subcommand:build" help:"try appropriate 'go build'"`
DebBuild bool `arg:"--debian" help:"build missing .deb packages"` DebBuild *EmptyCmd `arg:"subcommand:debian" help:"build missing .deb packages"`
MacBuild *EmptyCmd `arg:"subcommand:macos" help:"build macos packages"`
MakeInstall *EmptyCmd `arg:"subcommand:install" help:"run make install in each repo"`
ListPkgs *EmptyCmd `arg:"subcommand:list" help:"list all the packages on mirrors.wit.com"`
Test *EmptyCmd `arg:"subcommand:test" help:"test build everything first"`
Clone *EmptyCmd `arg:"subcommand:repomap-clone" help:"go-clone from a gowebd repomap"`
Upgrade *EmptyCmd `arg:"subcommand:upgrade" help:"apt upgrade packages installed from mirrors.wit.com"`
RepoMap string `arg:"--repomap" help:"location of the repomap"`
Release bool `arg:"--release" help:"use go-deb --release"` Release bool `arg:"--release" help:"use go-deb --release"`
DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` DryRun bool `arg:"--dry-run" help:"only show what would be packaged"`
ListPkgs bool `arg:"--list" help:"list all the packages on mirrors.wit.com"` Verbose bool `arg:"--verbose" help:"be loud about it"`
Upgrade bool `arg:"--apt-upgrade" help:"apt install on every mirrors.wit.com package already installed"` Force bool `arg:"--force" help:"rebuild everything"`
MakeInstall bool `arg:"--make-install" help:"run make install in each repo"`
RepoMap string `arg:"--repomap" help:"parse a repomap from gowebd"`
Recursive bool `arg:"--recursive" help:"go-clone --recursive"` Recursive bool `arg:"--recursive" help:"go-clone --recursive"`
Test bool `arg:"--test" help:"test build after everything else"` WITCOM bool `arg:"--witcom" help:"add the GPL header"`
Max int32 `arg:"--max" help:"stop building after max builds"`
}
type EmptyCmd struct {
} }
func init() { func init() {
arg.MustParse(&argv)
if debugger.ArgDebug() { if debugger.ArgDebug() {
log.Info("cmd line --debugger == true") log.Info("cmd line --debugger == true")
go func() { go func() {
@ -51,3 +63,30 @@ func init() {
func (args) Version() string { func (args) Version() string {
return "wit-test " + VERSION + " Built on " + BUILDTIME return "wit-test " + VERSION + " Built on " + BUILDTIME
} }
/*
handles shell autocomplete
*/
func (a args) DoAutoComplete(argv []string) {
switch argv[0] {
case "list":
fmt.Println("--all --mine --favorites --private")
case "debian":
fmt.Println("--dry-run --force --release --verbose macos --max")
case "upgrade":
fmt.Println("--dry-run")
case "build":
fmt.Println("--verbose --force")
case "install":
fmt.Println("--verbose")
case "repomap-clone":
fmt.Println("--repomap")
default:
if argv[0] == ARGNAME {
// list the subcommands here
fmt.Println("--bash list build debian install repomap-clone upgrade")
}
}
os.Exit(0)
}

View File

@ -1,79 +0,0 @@
package main
import (
"fmt"
"os"
"path/filepath"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func buildDeb() {
if argv.DryRun {
return
}
log.DaemonMode(true)
defer log.DaemonMode(false)
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
var cmd []string
check := all.Next()
if state[check] != "need to build" {
// log.Info("skipping build for", check.GetGoPath(), state[check])
continue
}
outdir := getOutdir(check)
os.MkdirAll(outdir, 0755)
_, err := os.Stat(filepath.Join(outdir, debnames[check]))
if err == nil {
if debnames[check] == "" {
log.Info("something went wrong. .deb blank", check.GetGoPath())
}
// already built
continue
}
if argv.Release {
cmd = []string{"go-deb", "--release", "--auto", "--repo", check.GetGoPath(), "--dir", outdir}
} else {
cmd = []string{"go-deb", "--auto", "--no-gui", "--repo", check.GetGoPath(), "--dir", outdir}
}
if me.forge.Config.IsPrivate(check.GetGoPath()) {
cmd = []string{"go-deb", "--auto", "--repo", check.GetGoPath(), "--dir", outdir}
}
log.Info("build cmd:", cmd)
if r := check.RunRealtime(cmd); r.Error != nil {
log.Info("go-deb failed error:", r.Error, check.GetGoPath())
failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error)
} else if r.Exit != 0 {
log.Info("go-deb failed exit =", r.Exit, check.GetGoPath())
failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error)
} else {
log.Info("build worked")
}
}
}
func getOutdir(repo *gitpb.Repo) string {
if repo.GetLastTag() != repo.GetMasterVersion() {
return "/home/jcarr/incoming-devel"
}
if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() {
return "/home/jcarr/incoming-devel"
}
if repo.CheckDirty() {
return "/home/jcarr/incoming-devel"
}
if me.forge.Config.IsPrivate(repo.GetGoPath()) {
return "/home/jcarr/incoming-private"
}
return "/home/jcarr/incoming"
}

75
doAptUpgrade.go Normal file
View File

@ -0,0 +1,75 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"fmt"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
func doAptUpgrade() {
if argv.DryRun {
log.Info("--dry-run", []string{"apt", "update"})
} else {
result := shell.Run([]string{"apt", "update"})
if result.Error != nil {
log.Info("apt update error:", result.Error)
badExit(result.Error)
}
}
fmt.Println("Installed Packages:")
loop := me.machine.Wit.SortByName()
for loop.Scan() {
p := loop.Next()
// log.Info("apt install", name)
if me.machine.IsInstalled(p.Name) {
cmd := []string{"apt", "install", p.Name}
if argv.DryRun {
log.Info("--dry-run", cmd)
} else {
log.Info("Running:", cmd)
shell.RunRealtime([]string{"apt", "install", p.Name})
}
}
}
okExit("installed")
}
func doAptList() {
log.DaemonMode(true)
defer log.DaemonMode(false)
fmt.Println("Installed Packages:")
loop := me.machine.Wit.SortByName()
for loop.Scan() {
p := loop.Next()
var end string
var version string
if me.forge.Config.IsPrivate(p.Name) {
end += "(private) "
}
if actualp := me.machine.FindByVersion(p.Name, p.Version); actualp != nil {
// end += "(version match) "
} else {
end += "(version mismatch) " + actualp.Version + " " + version + " "
}
if actualp := me.machine.FindInstalledByName(p.Name); actualp != nil {
if p.Version != actualp.Version {
end += "(installed " + actualp.Version + " vs " + p.Version + ") "
} else {
end += "(installed ok) "
}
version = actualp.Version
}
if me.forge.Config.IsReadOnly(p.Name) {
// end += " (readonly) "
} else {
end += "(writable) "
}
log.Printf("%-30s %-8s %s\n", p.Name, p.Version, end) // p.PkgName)
}
okExit("")
}

136
doDebian.go Normal file
View File

@ -0,0 +1,136 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"fmt"
"os"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func buildDeb() {
log.DaemonMode(true)
defer log.DaemonMode(false)
if argv.Test != nil {
if err := doInstall(); err != nil {
log.Info("doInstall() failed", err)
badExit(err)
}
}
var counter int
if int(argv.Max) == 0 {
argv.Max = 50
}
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
var cmd []string
check := all.Next()
outdir := getOutdir(check)
os.MkdirAll(outdir, 0755)
if me.forge.Config.IsReadOnly(check.GetGoPath()) {
continue
}
if !check.IsBinary() {
continue
}
if check.IsGoPlugin() {
continue
}
if argv.Release {
cmd = []string{"go-deb", "--release", "--dir", outdir}
} else {
cmd = []string{"go-deb", "--dir", outdir}
}
if me.forge.Config.IsPrivate(check.GetGoPath()) {
cmd = []string{"go-deb", "--dir", outdir}
continue
}
if argv.Verbose {
log.Info("build cmd:", cmd)
cmd = append(cmd, "--verbose")
}
if argv.DryRun {
continue
}
if argv.Force {
// build everything no matter what
} else {
if state[check] != "need to build" {
// log.Info("skipping build for", check.GetGoPath(), state[check])
continue
}
}
counter += 1
if counter > int(argv.Max) {
log.Info("did --max builds", argv.Max)
okExit("")
}
/*
build-darwin:
GOOS=darwin GOARCH=amd64 GO111MODULE=off go build -v -o go-clone-darwin.x86 \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
build-darwin-arm64:
GOOS=darwin GOARCH=arm64 GO111MODULE=off go build -v -o go-clone-darwin.arm \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
*/
if argv.MacBuild != nil {
log.Info("todo: add mac builds")
continue
}
/*
_, err := os.Stat(filepath.Join(outdir, debnames[check]))
if err == nil {
if debnames[check] == "" {
log.Info("something went wrong. .deb blank", check.GetGoPath())
}
// already built
continue
}
*/
if err := check.RunVerbose(cmd); err != nil {
log.Info(check.FullPath, cmd)
failed[check] = fmt.Sprint("godeb failed", cmd, "with", err)
badExit(err)
} else {
log.Info("build worked")
}
}
}
func getOutdir(repo *gitpb.Repo) string {
if repo.GetLastTag() != repo.GetMasterVersion() {
return "/home/jcarr/incoming-devel"
}
if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() {
return "/home/jcarr/incoming-devel"
}
if repo.CheckDirty() {
return "/home/jcarr/incoming-devel"
}
if me.forge.Config.IsPrivate(repo.GetGoPath()) {
return "/home/jcarr/incoming-private"
}
return "/home/jcarr/incoming"
}

145
doInstall.go Normal file
View File

@ -0,0 +1,145 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"go.wit.com/log"
)
func doInstall() error {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
check := all.Next()
repotype := check.GetRepoType()
if repotype == "binary" || repotype == "plugin" {
// we only want to process things that can be compiled with 'go build'
} else {
// log.Info("skipping repo", check.GetGoPath(), repotype)
continue
}
if me.forge.Config.IsReadOnly(check.GetGoPath()) {
// ignore read only stuff
continue
}
// var cmd []string
var start string
var end string
// add te repotype
end += check.GetRepoType()
manufactured := check.GetCurrentVersion()
ver := trimNonNumericFromStart(manufactured)
name := me.forge.Config.DebName(check.GetGoPath())
var realver string
if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil {
realver = installedPackage.Version
}
if actualp := me.machine.FindByVersion(name, ver); actualp != nil {
end += " (version match) " + actualp.Version + " " + ver + " "
state[check] = "on mirrors"
} else {
if realver != "" {
end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver)
}
// end += "" + ver + " "
}
if me.machine.IsInstalled(name) {
if actualp := me.machine.FindInstalledByName(name); actualp != nil {
if ver != actualp.Version {
end += "(installed " + actualp.Version + ") "
} else {
end += "(installed ok) "
}
} else {
end += "(installed) "
}
}
debname := name + "_" + ver + "_amd64.deb"
debnames[check] = debname
outdir := getOutdir(check)
_, err := os.Stat(filepath.Join(outdir, debname))
if err == nil {
// log.Info("exists", filepath.Join(outdir, debname))
state[check] = "in incoming"
} else {
// log.Info(debname, "does not exist")
}
if state[check] == "" {
state[check] = "need to build"
}
start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname)
if state[check] == "need to build" {
end += " (will build) "
}
log.Info(start, end)
if name == "" {
// err := fmt.Sprintf("name is blank error %+v", repo)
log.Warn("name is blank error", check.GetGoPath())
}
if argv.DryRun {
continue
}
if argv.TestBuild != nil {
if argv.DryRun {
continue
}
if argv.Verbose {
verbose := []string{"-v", "-x"}
if err := me.forge.Build(check, verbose); err != nil {
log.Warn("BUILD FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
}
} else {
if err := me.forge.Build(check, nil); err != nil {
log.Warn("BUILD FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
}
}
continue
}
log.Info("STARTING 'make install' in", check.GetGoPath())
if argv.DryRun {
continue
}
if argv.Verbose {
verbose := []string{"-v", "-x"}
if err := me.forge.Install(check, verbose); err != nil {
log.Warn("INSTALL FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
}
} else {
if err := me.forge.Install(check, nil); err != nil {
log.Warn("INSTALL FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
}
}
}
if len(failed) != 0 {
log.Info("")
log.Info("something failed on:")
for repo, cmd := range failed {
log.Info("failed cmd :", cmd, repo.GetGoPath())
}
// me.forge.CheckoutUser()
// shell.Run([]string{"forge", "--find-private"})
badExit(errors.New("some repos failed"))
return errors.New("some repos failed")
}
return nil
}

93
doListRepos.go Normal file
View File

@ -0,0 +1,93 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"fmt"
"os"
"path/filepath"
"go.wit.com/log"
)
func doListRepos() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
check := all.Next()
repotype := check.GetRepoType()
if repotype == "binary" || repotype == "plugin" {
// we only want to process things that can be compiled with 'go build'
} else {
// log.Info("skipping repo", check.GetGoPath(), repotype)
continue
}
if me.forge.Config.IsReadOnly(check.GetGoPath()) {
// ignore read only stuff
continue
}
// var cmd []string
var start string
var end string
// add te repotype
end += check.GetRepoType()
manufactured := check.GetCurrentVersion()
ver := trimNonNumericFromStart(manufactured)
name := me.forge.Config.DebName(check.GetGoPath())
var realver string
if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil {
realver = installedPackage.Version
}
if actualp := me.machine.FindByVersion(name, ver); actualp != nil {
end += " (version match) " + actualp.Version + " " + ver + " "
state[check] = "on mirrors"
} else {
if realver != "" {
end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver)
}
// end += "" + ver + " "
}
if me.machine.IsInstalled(name) {
if actualp := me.machine.FindInstalledByName(name); actualp != nil {
if ver != actualp.Version {
end += "(installed " + actualp.Version + ") "
} else {
end += "(installed ok) "
}
} else {
end += "(installed) "
}
}
debname := name + "_" + ver + "_amd64.deb"
debnames[check] = debname
outdir := getOutdir(check)
_, err := os.Stat(filepath.Join(outdir, debname))
if err == nil {
// log.Info("exists", filepath.Join(outdir, debname))
state[check] = "in incoming"
} else {
// log.Info(debname, "does not exist")
}
if state[check] == "" {
state[check] = "need to build"
}
start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname)
if state[check] == "need to build" {
end += " (will build) "
}
log.Info(start, end)
if name == "" {
// err := fmt.Sprintf("name is blank error %+v", repo)
log.Warn("name is blank error", check.GetGoPath())
}
}
}

118
doWITCOM.go Normal file
View File

@ -0,0 +1,118 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"go.wit.com/log"
)
func doWITCOM() {
pwd, err := os.Getwd()
if err != nil {
return
}
files, err := scanForGoFiles(pwd)
if err != nil {
return
}
for _, file := range files {
addCommonHeader(file)
}
}
// add a common header for WIT files
// add a common header for WIT files
func addCommonHeader(filename string) error {
// read in the .proto file
data, err := os.ReadFile(filename)
if err != nil {
log.Info("file read failed", filename, err)
return err
}
var newfile string
var start bool = true
var found bool
var done bool
// drop the old copywrite lines
for _, line := range strings.Split(string(data), "\n") {
// first line must have WIT.COM
if strings.HasPrefix(line, "//") && start {
start = false
if strings.Contains(line, "WIT.COM") {
found = true
} else {
newfile += fmt.Sprintln(line)
}
continue
}
// dump every other comment
if strings.HasPrefix(line, "//") && found {
continue
} else {
found = false
}
// print the header once
if !done {
newfile += fmt.Sprintln("// Copyright 2017-2025 WIT.COM Inc. All rights reserved.")
newfile += fmt.Sprintln("// Use of this source code is governed by the GPL 3.0")
newfile += fmt.Sprintln("")
done = true
}
newfile += fmt.Sprintln(line)
}
pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Info("file open error. permissions?", filename, err)
return err
}
// trim trailing empty lines from the new file
newfile = strings.TrimSpace(newfile)
fmt.Fprintln(pf, newfile)
pf.Close()
return nil
}
// look for any .go files. do not enter directories
func scanForGoFiles(startDir string) ([]string, error) {
var files []string
err := filepath.Walk(startDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// ignore the start dir
if startDir == path {
return nil
}
if strings.HasSuffix(path, ".go") {
files = append(files, path)
}
if strings.HasSuffix(path, ".proto") {
files = append(files, path)
}
// don't go into any directories
if info.IsDir() {
return filepath.SkipDir
}
return nil
})
return files, err
}

228
main.go
View File

@ -1,78 +1,72 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (
"errors" "debug/buildinfo"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"unicode" "unicode"
"go.wit.com/lib/gui/shell" "go.wit.com/dev/alexflint/arg"
"go.wit.com/log" "go.wit.com/lib/gui/prep"
"go.wit.com/gui"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
) )
// sent via -ldflags // sent via -ldflags
var VERSION string var VERSION string
var BUILDTIME string var BUILDTIME string
// used for shell auto completion
var ARGNAME string = "wit-test" // todo: get this from $0 ?
var failed map[*gitpb.Repo]string var failed map[*gitpb.Repo]string
var state map[*gitpb.Repo]string var state map[*gitpb.Repo]string
var debnames map[*gitpb.Repo]string var debnames map[*gitpb.Repo]string
func main() { func main() {
me = new(autoType) me = new(autoType)
prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: this line should be: prep.Bash(argv)
// me.myGui = prep.Gui() // prepares the GUI package for go-args
me.argpp = arg.MustParse(&argv)
dumpDebug()
failed = make(map[*gitpb.Repo]string) failed = make(map[*gitpb.Repo]string)
state = make(map[*gitpb.Repo]string) state = make(map[*gitpb.Repo]string)
debnames = make(map[*gitpb.Repo]string) debnames = make(map[*gitpb.Repo]string)
// load the ~/.config/forge/ config
me.forge = forgepb.Init() me.forge = forgepb.Init()
me.myGui = gui.New() me.machine, _ = zoopb.InitMachine()
me.myGui.Default()
if argv.Clone != nil {
if argv.RepoMap != "" { if argv.RepoMap != "" {
repomap(argv.RepoMap) repomap(argv.RepoMap)
okExit("") okExit("")
} }
if argv.Upgrade {
if argv.DryRun {
log.Info("--dry-run", []string{"apt", "update"})
} else {
result := shell.Run([]string{"apt", "update"})
if result.Error != nil {
log.Info("apt update error:", result.Error)
badExit(result.Error)
}
} }
fmt.Println("Installed Packages:") if argv.WITCOM {
loop := me.forge.Machine.Wit.SortByName() doWITCOM()
for loop.Scan() { okExit("")
p := loop.Next()
// log.Info("apt install", name)
if me.forge.Machine.IsInstalled(p.Name) {
if argv.DryRun {
log.Info("--dry-run", []string{"apt", "install", p.Name})
} else {
shell.RunRealtime([]string{"apt", "install", p.Name})
}
}
}
okExit("installed")
} }
if argv.ListPkgs { if argv.Upgrade != nil {
doAptUpgrade()
}
if argv.ListPkgs != nil {
doAptList()
log.DaemonMode(true) log.DaemonMode(true)
defer log.DaemonMode(false) defer log.DaemonMode(false)
fmt.Println("Installed Packages:") fmt.Println("Installed Packages:")
loop := me.forge.Machine.Wit.SortByName() loop := me.machine.Wit.SortByName()
for loop.Scan() { for loop.Scan() {
p := loop.Next() p := loop.Next()
var end string var end string
@ -80,12 +74,12 @@ func main() {
if me.forge.Config.IsPrivate(p.Name) { if me.forge.Config.IsPrivate(p.Name) {
end += "(private) " end += "(private) "
} }
if actualp := me.forge.Machine.FindVersion(p.Name, p.Version); actualp != nil { if actualp := me.machine.FindByVersion(p.Name, p.Version); actualp != nil {
// end += "(version match) " // end += "(version match) "
} else { } else {
end += "(version mismatch) " + actualp.Version + " " + version + " " end += "(version mismatch) " + actualp.Version + " " + version + " "
} }
if actualp := me.forge.Machine.FindInstalledByName(p.Name); actualp != nil { if actualp := me.machine.FindInstalledByName(p.Name); actualp != nil {
if p.Version != actualp.Version { if p.Version != actualp.Version {
end += "(installed " + actualp.Version + " vs " + p.Version + ") " end += "(installed " + actualp.Version + " vs " + p.Version + ") "
} else { } else {
@ -103,137 +97,21 @@ func main() {
okExit("") okExit("")
} }
all := me.forge.Repos.SortByFullPath() doListRepos()
for all.Scan() {
check := all.Next()
repotype := check.GetRepoType() if argv.DebBuild != nil {
if repotype == "binary" || repotype == "plugin" {
// we only want to process things that can be compiled with 'go build'
} else {
// log.Info("skipping repo", check.GetGoPath(), repotype)
continue
}
if me.forge.Config.IsReadOnly(check.GetGoPath()) {
// ignore read only stuff
continue
}
// var cmd []string
var start string
var end string
// add te repotype
end += check.GetRepoType()
manufactured := check.GetCurrentVersion()
ver := trimNonNumericFromStart(manufactured)
name := me.forge.Config.DebName(check.GetGoPath())
var realver string
if installedPackage := me.forge.Machine.FindInstalledByName(name); installedPackage != nil {
realver = installedPackage.Version
}
if actualp := me.forge.Machine.FindVersion(name, ver); actualp != nil {
end += " (version match) " + actualp.Version + " " + ver + " "
state[check] = "on mirrors"
} else {
if realver != "" {
end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver)
}
// end += "" + ver + " "
}
if me.forge.Machine.IsInstalled(name) {
if actualp := me.forge.Machine.FindInstalledByName(name); actualp != nil {
if ver != actualp.Version {
end += "(installed " + actualp.Version + ") "
} else {
end += "(installed ok) "
}
} else {
end += "(installed) "
}
}
debname := name + "_" + ver + "_amd64.deb"
debnames[check] = debname
outdir := getOutdir(check)
_, err := os.Stat(filepath.Join(outdir, debname))
if err == nil {
// log.Info("exists", filepath.Join(outdir, debname))
state[check] = "in incoming"
} else {
// log.Info(debname, "does not exist")
}
if state[check] == "" {
state[check] = "need to build"
}
start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname)
if state[check] == "need to build" {
end += " (will build) "
}
log.Info(start, end)
if name == "" {
// err := fmt.Sprintf("name is blank error %+v", repo)
log.Warn("name is blank error", check.GetGoPath())
}
if argv.DryRun {
continue
}
if argv.TestBuild {
if argv.DryRun {
continue
}
if err := me.forge.Build(check, nil); err != nil {
log.Warn("BUILD FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
}
continue
}
if argv.MakeInstall {
log.Info("STARTING 'make install' in", check.GetGoPath())
if argv.DryRun {
continue
}
if err := me.forge.Install(check, nil); err != nil {
log.Warn("INSTALL FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
}
continue
}
}
if argv.DebBuild {
buildDeb() buildDeb()
okExit("")
} }
if len(failed) != 0 {
log.Info("")
log.Info("something failed on:")
for repo, cmd := range failed {
log.Info("failed cmd :", cmd, repo.GetGoPath())
}
me.forge.CheckoutUser()
shell.Run([]string{"forge", "--find-private"})
badExit(errors.New("some repos failed"))
}
if argv.Test {
homeDir, _ := os.UserHomeDir()
testdir := filepath.Join(homeDir, "go/src/go.wit.com/apps/utils/wit-utils/go-clone-test/") if argv.MakeInstall != nil {
os.Chdir(testdir) if err := doInstall(); err != nil {
shell.RunRealtime([]string{"go", "install"}) log.Info("doInstall() failed", err)
workdir := filepath.Join(homeDir, "gowork")
if err := os.MkdirAll(workdir, os.ModePerm); err != nil {
badExit(err) badExit(err)
} }
os.Chdir(workdir) okExit("EVERYTHING BUILT!")
shell.RunRealtime([]string{"go-clone-test"})
} }
okExit("everything compiled") okExit("everything compiled")
} }
@ -256,6 +134,34 @@ func okExit(thing string) {
} }
func badExit(err error) { func badExit(err error) {
log.Info("go-clean failed: ", err, me.forge.GetGoSrc()) log.Info("go-clean failed: ", err, me.forge.Config.ReposDir)
os.Exit(-1) os.Exit(-1)
} }
func dumpDebug() {
// Get absolute path of the currently running binary
exePath, err := os.Executable()
if err != nil {
fmt.Println("Error getting executable path:", err)
return
}
// Resolve symlinks if necessary
exePath, err = filepath.EvalSymlinks(exePath)
if err != nil {
fmt.Println("Error resolving symlink:", err)
return
}
// Read build info
bi, err := buildinfo.ReadFile(exePath)
if err != nil {
fmt.Println("Error reading build info:", err)
return
}
fmt.Println("Go Version:", bi.GoVersion)
for _, dep := range bi.Deps {
fmt.Printf("Dependency: %s %s\n", dep.Path, dep.Version)
}
}

View File

@ -1,3 +1,6 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (

View File

@ -1,24 +1,19 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (
"go.wit.com/gui" "go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/zoopb"
) )
var me *autoType var me *autoType
// this app's variables // this app's variables
type autoType struct { type autoType struct {
// allrepos map[string]*repo argpp *arg.Parser // go-arg preprocessor
myGui *gui.Node forge *forgepb.Forge // your customized repo preferences and settings
machine *zoopb.Machine // your customized repo preferences and settings
// the window from the /lib/gui/gowit package
// lw *gadgets.BasicWindow
// our view of the repositories
// repos *repoWindow
// repoList *repolist.RepoList
// your customized repo preferences and settings
forge *forgepb.Forge
} }

64
windowApply.go Normal file
View File

@ -0,0 +1,64 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"sync"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
"go.wit.com/gui"
)
// Shout out to "Go Generics 101" by Tapir Liu. Buy this book!
type Lockable[T any] struct {
mu sync.Mutex
data T
}
func (l *Lockable[T]) Do(f func(*T)) {
}
func (l *Lockable[T]) Hide() {
log.Info("testing:", l)
}
type applyWindow struct {
win *gadgets.BasicWindow
box *gui.Node
// the top box of the repolist window
topbox *gui.Node
}
type C3 = interface {
Show()
Hide()
Hidden() bool
Enable()
Disable()
~*gadgets.BasicWindow | ~*gui.Node
}
func (r applyWindow) Hidden() bool {
return r.win.Hidden()
}
func (r applyWindow) Show() {
r.win.Show()
}
func (r applyWindow) Hide() {
r.win.Hide()
}
func (r applyWindow) Disable() {
r.box.Disable()
}
func (r applyWindow) Enable() {
r.box.Enable()
}