somewhat is starting to work
This commit is contained in:
parent
b5a5732ead
commit
875435bc02
13
argv.go
13
argv.go
|
@ -17,15 +17,10 @@ func (args) Version() string {
|
|||
|
||||
func (a args) Description() string {
|
||||
return `
|
||||
This will:
|
||||
go-clean will try to verify your go.* files are using the newest package versions
|
||||
|
||||
* Remove your existing go.mod and go.sum files.
|
||||
* Run 'go mod init' and 'go mod tidy'
|
||||
* Trim your 'go.sum' file of missing entries
|
||||
* Test that your binary still builds with 'go build'
|
||||
(testing can only be done if you are working from ~/go/src)
|
||||
|
||||
* This tool is used by forge to also identify golang 'primative' libraries which
|
||||
are libraries that are completely cleanly implemented and self-defined.
|
||||
* Recreate go.* with 'go mod init' and 'go mod tidy'
|
||||
* Check that the most recent master branch versions are used
|
||||
* Try to trim go.sum of non-existent entries
|
||||
`
|
||||
}
|
||||
|
|
81
main.go
81
main.go
|
@ -1,14 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/gui/shell"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/lib/protobuf/gitpb"
|
||||
"go.wit.com/log"
|
||||
|
@ -54,7 +51,7 @@ func main() {
|
|||
warning = append(warning, "this will redo _every_ repo. This is probably fine.")
|
||||
warning = append(warning, fmt.Sprintf("You have %d total repositories in %s", forge.Repos.Len(), forge.GetGoSrc()))
|
||||
warning = append(warning, "")
|
||||
warning = append(warning, "However, this will also do:")
|
||||
warning = append(warning, "However, this will also, at times, do:")
|
||||
warning = append(warning, "")
|
||||
warning = append(warning, "rm -rf ~/go/pkg/")
|
||||
warning = append(warning, "rm -rf ~/.config/go-build/")
|
||||
|
@ -62,7 +59,7 @@ func main() {
|
|||
warning = append(warning, "Which is also probably fine, but will clear all your build cache and go mod cache")
|
||||
warning = append(warning, "")
|
||||
simpleStdin(false, warning)
|
||||
purgeGoCaches()
|
||||
// purgeGoCaches()
|
||||
} else {
|
||||
simpleStdin(true, []string{"go-clean will recreate go.mod and go.sum"})
|
||||
}
|
||||
|
@ -72,21 +69,14 @@ func main() {
|
|||
badExit(err)
|
||||
}
|
||||
|
||||
/*
|
||||
// re-process go deps
|
||||
deps := check.GoDeps.SortByGoPath()
|
||||
for deps.Scan() {
|
||||
depRepo := deps.Next()
|
||||
log.Info("check has dep:", depRepo.GoPath)
|
||||
}
|
||||
*/
|
||||
// check go.sum file
|
||||
if forge.FinalGoDepsCheckOk(check) {
|
||||
if err := forge.CleanGoDepsCheckOk(check); err == nil {
|
||||
log.Info("forge.FinalGoDepsCheck() worked :", check.GoPath)
|
||||
okExit(check.GoPath + " go.sum seems clean")
|
||||
} else {
|
||||
log.Info("forge.FinalGoDepsCheck() failed. boo. :", check.GoPath)
|
||||
badExit(err)
|
||||
}
|
||||
log.Info("forge.FinalGoDepsCheck() failed. boo. :", check.GoPath)
|
||||
badExit(errors.New(check.GoPath + " go.sum is not perfect"))
|
||||
}
|
||||
|
||||
func findPwdRepo() *gitpb.Repo {
|
||||
|
@ -117,62 +107,3 @@ func badExit(err error) {
|
|||
log.Info("Finished go-clean with error", err, forge.GetGoSrc())
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
func purgeGoCaches() {
|
||||
homedir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
pkgdir := filepath.Join(homedir, "go/pkg")
|
||||
var cmd []string
|
||||
cmd = []string{"chmod", "700", "-R", pkgdir}
|
||||
runStrict("", cmd)
|
||||
cmd = []string{"rm", "-rf", pkgdir}
|
||||
runStrict("", cmd)
|
||||
builddir := filepath.Join(homedir, ".cache/go-build")
|
||||
cmd = []string{"rm", "-rf", builddir}
|
||||
runStrict("", cmd)
|
||||
|
||||
// this can't have really happened
|
||||
// echo this still failed in:
|
||||
// echo "Linux hpdev2.grid.wit.com 6.9.8-rt-amd64 #1 SMP PREEMPT_RT Debian 6.9.8-1 (2024-07-07) x86_64 GNU/Linux"
|
||||
// echo and I had to drop the caches after building go install binaries quickly and running them
|
||||
// echo "as an os.Exec() between binaries"
|
||||
// echo sysctl -w vm.drop_caches=3
|
||||
}
|
||||
|
||||
func runStrict(wd string, cmd []string) {
|
||||
var err error
|
||||
if wd != "" {
|
||||
if err = os.Chdir(wd); err != nil {
|
||||
log.Info("cd", "wd", "failed", err)
|
||||
badExit(err)
|
||||
}
|
||||
}
|
||||
log.Info(wd, "running:", wd, cmd)
|
||||
// result := shell.Run(cmd)
|
||||
result := shell.RunRealtime(cmd)
|
||||
if result.Error != nil {
|
||||
log.Info("cmd failed", wd, cmd, err)
|
||||
for i, line := range result.Stdout {
|
||||
log.Info("STDOUT:", i, line)
|
||||
}
|
||||
for i, line := range result.Stderr {
|
||||
log.Info("STDERR:", i, line)
|
||||
}
|
||||
badExit(err)
|
||||
}
|
||||
if result.Exit != 0 {
|
||||
log.Info("cmd failed", wd, cmd, err)
|
||||
for i, line := range result.Stdout {
|
||||
log.Info("STDOUT:", i, line)
|
||||
}
|
||||
for i, line := range result.Stderr {
|
||||
log.Info("STDERR:", i, line)
|
||||
}
|
||||
badExit(errors.New(fmt.Sprintf("cmd failed with %d", result.Exit)))
|
||||
}
|
||||
for i, line := range result.Stdout {
|
||||
log.Info(i, line)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"go.wit.com/lib/gui/shell"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func purgeGoCaches() {
|
||||
homedir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
pkgdir := filepath.Join(homedir, "go/pkg")
|
||||
var cmd []string
|
||||
cmd = []string{"chmod", "700", "-R", pkgdir}
|
||||
runStrict("", cmd)
|
||||
cmd = []string{"rm", "-rf", pkgdir}
|
||||
runStrict("", cmd)
|
||||
builddir := filepath.Join(homedir, ".cache/go-build")
|
||||
cmd = []string{"rm", "-rf", builddir}
|
||||
runStrict("", cmd)
|
||||
|
||||
// this can't have really happened
|
||||
// echo this still failed in:
|
||||
// echo "Linux hpdev2.grid.wit.com 6.9.8-rt-amd64 #1 SMP PREEMPT_RT Debian 6.9.8-1 (2024-07-07) x86_64 GNU/Linux"
|
||||
// echo and I had to drop the caches after building go install binaries quickly and running them
|
||||
// echo "as an os.Exec() between binaries"
|
||||
// echo sysctl -w vm.drop_caches=3
|
||||
}
|
||||
|
||||
func runStrict(wd string, cmd []string) {
|
||||
var err error
|
||||
if wd != "" {
|
||||
if err = os.Chdir(wd); err != nil {
|
||||
log.Info("cd", "wd", "failed", err)
|
||||
badExit(err)
|
||||
}
|
||||
}
|
||||
log.Info(wd, "running:", wd, cmd)
|
||||
// result := shell.Run(cmd)
|
||||
result := shell.RunRealtime(cmd)
|
||||
if result.Error != nil {
|
||||
log.Info("cmd failed", wd, cmd, err)
|
||||
for i, line := range result.Stdout {
|
||||
log.Info("STDOUT:", i, line)
|
||||
}
|
||||
for i, line := range result.Stderr {
|
||||
log.Info("STDERR:", i, line)
|
||||
}
|
||||
badExit(err)
|
||||
}
|
||||
if result.Exit != 0 {
|
||||
log.Info("cmd failed", wd, cmd, err)
|
||||
for i, line := range result.Stdout {
|
||||
log.Info("STDOUT:", i, line)
|
||||
}
|
||||
for i, line := range result.Stderr {
|
||||
log.Info("STDERR:", i, line)
|
||||
}
|
||||
badExit(errors.New(fmt.Sprintf("cmd failed with %d", result.Exit)))
|
||||
}
|
||||
for i, line := range result.Stdout {
|
||||
log.Info(i, line)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue