attempt simple go.sum trim
This commit is contained in:
parent
7512463a57
commit
10e1f545bb
20
build.go
20
build.go
|
@ -1,14 +1,12 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
// for golang repos, this is an attempt to build the package
|
// for golang repos, this is an attempt to build the package
|
||||||
// there might be some 'standard' ways to implement a build
|
//
|
||||||
// that make sense.
|
|
||||||
|
|
||||||
// Additions to 'go build' that are attempted here:
|
// Additions to 'go build' that are attempted here:
|
||||||
//
|
//
|
||||||
// * detect packages that are plugins
|
// * detect packages that are plugins
|
||||||
// * autogen packages that have .proto protobuf files
|
// * run autogenpb packages that have .proto protobuf files
|
||||||
// * define some 'standard' ldflags
|
// * use some 'standard' ldflags (VERISON, BUILDTIME)
|
||||||
//
|
//
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -66,6 +64,8 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
|
||||||
repo.RedoGoMod()
|
repo.RedoGoMod()
|
||||||
f.Repos.ConfigSave()
|
f.Repos.ConfigSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run autogenpb in all protobuf repos
|
||||||
loop1 := repo.GoDeps.SortByGoPath()
|
loop1 := repo.GoDeps.SortByGoPath()
|
||||||
for loop1.Scan() {
|
for loop1.Scan() {
|
||||||
t := loop1.Next()
|
t := loop1.Next()
|
||||||
|
@ -80,7 +80,14 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
|
||||||
if repo.CheckDirty() {
|
if repo.CheckDirty() {
|
||||||
version = version + "-dirty"
|
version = version + "-dirty"
|
||||||
}
|
}
|
||||||
cmd := []string{"go", goWhat, "-v"}
|
cmd := []string{"go", goWhat}
|
||||||
|
|
||||||
|
// if this is a plugin, use buildmode=plugin
|
||||||
|
if repo.RepoType() == "plugin" {
|
||||||
|
_, fname := filepath.Split(repo.FullPath)
|
||||||
|
cmd = append(cmd, "-buildmode=plugin", "-o", fname+".so")
|
||||||
|
}
|
||||||
|
cmd = append(cmd, "-v")
|
||||||
|
|
||||||
// set standard ldflag options
|
// set standard ldflag options
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
@ -105,6 +112,7 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
|
||||||
} else {
|
} else {
|
||||||
log.Info("GO111MODULE=", testenv, "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
|
log.Info("GO111MODULE=", testenv, "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
|
||||||
}
|
}
|
||||||
|
log.Info("running:", repo.FullPath)
|
||||||
log.Info("running:", cmd)
|
log.Info("running:", cmd)
|
||||||
result := repo.RunRealtime(cmd)
|
result := repo.RunRealtime(cmd)
|
||||||
if result.Exit == 0 {
|
if result.Exit == 0 {
|
||||||
|
|
|
@ -3,6 +3,10 @@ package forgepb
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -52,6 +56,11 @@ func (f *Forge) CleanGoDepsCheckOk(check *gitpb.Repo) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simple trim
|
||||||
|
if err := f.TrimGoSum(check); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var err error = nil
|
var err error = nil
|
||||||
log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
|
log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
|
||||||
deps := check.GoDeps.SortByGoPath()
|
deps := check.GoDeps.SortByGoPath()
|
||||||
|
@ -98,3 +107,75 @@ func (f *Forge) CleanGoDepsCheckOk(check *gitpb.Repo) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Forge) TrimGoSum(check *gitpb.Repo) error {
|
||||||
|
var stuff map[string]string
|
||||||
|
stuff = make(map[string]string)
|
||||||
|
|
||||||
|
var modver map[string]string
|
||||||
|
modver = make(map[string]string)
|
||||||
|
|
||||||
|
var good map[string]bool
|
||||||
|
good = make(map[string]bool)
|
||||||
|
|
||||||
|
if check == nil {
|
||||||
|
log.Info("boo, check == nil")
|
||||||
|
return errors.New("*repo == nil")
|
||||||
|
}
|
||||||
|
filename := filepath.Join(filepath.Join(check.FullPath, "go.sum"))
|
||||||
|
data, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, line := range strings.Split(string(data), "\n") {
|
||||||
|
parts := strings.Fields(line)
|
||||||
|
if len(parts) < 3 {
|
||||||
|
log.Info("BAD:", line)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
gopath := parts[0]
|
||||||
|
version := parts[1]
|
||||||
|
hash := parts[2]
|
||||||
|
|
||||||
|
if strings.HasSuffix(version, "/go.mod") {
|
||||||
|
if _, ok := stuff[gopath]; ok {
|
||||||
|
log.Info("MATCHED: gopath:", gopath, "version:", version)
|
||||||
|
modver[gopath] = version + " " + hash
|
||||||
|
good[gopath] = true
|
||||||
|
} else {
|
||||||
|
log.Info("GARBAGE: gopath:", gopath, "version:", version)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Info("GOOD : gopath:", gopath, "version:", version)
|
||||||
|
stuff[gopath] = version + " " + hash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keys := make([]string, 0, len(stuff))
|
||||||
|
for k := range stuff {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
// rewrite the go.sum file
|
||||||
|
newfilename := filepath.Join(filepath.Join(check.FullPath, "go.sum"))
|
||||||
|
newf, err := os.OpenFile(newfilename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer newf.Close()
|
||||||
|
sort.Strings(keys)
|
||||||
|
for _, gopath := range keys {
|
||||||
|
if good[gopath] {
|
||||||
|
fmt.Fprintf(newf, "%s %s\n", gopath, stuff[gopath])
|
||||||
|
fmt.Fprintf(newf, "%s %s\n", gopath, modver[gopath])
|
||||||
|
check := f.Repos.FindByGoPath(gopath)
|
||||||
|
if check == nil {
|
||||||
|
log.Info("gopath does not really exist:", gopath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fmt.Fprintln(newf, "test")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ func loadFile(filename string) ([]byte, error) {
|
||||||
func configWrite(filename string, data []byte) error {
|
func configWrite(filename string, data []byte) error {
|
||||||
fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
|
fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
|
||||||
|
|
||||||
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
|
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
defer cfgfile.Close()
|
defer cfgfile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("open config file :", err)
|
log.Warn("open config file :", err)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
// Package forgepb describes the protobuf's used by 'go.wit.com/apps/forge'
|
||||||
|
package forgepb // import "go.wit.com/lib/protobuf/forgepb"
|
||||||
|
// `go-clean go=1.18`
|
|
@ -17,7 +17,7 @@ func (f *Forge) MakeGoWork() error {
|
||||||
return errors.New("if you want a go.work file in ~/go/src/, touch it first")
|
return errors.New("if you want a go.work file in ~/go/src/, touch it first")
|
||||||
}
|
}
|
||||||
filename := filepath.Join(f.GetGoSrc(), "go.work")
|
filename := filepath.Join(f.GetGoSrc(), "go.work")
|
||||||
workf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
|
workf, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue