go.work file fixes

This commit is contained in:
Jeff Carr 2024-12-10 01:48:29 -06:00
parent c08079fc2f
commit 757fd9ba55
3 changed files with 41 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import (
"strings"
"time"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@ -36,10 +37,14 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
log.Warn("forge.doBuild repo == nil")
return errors.New("forge.doBuild repo == nil")
}
// always assume all sources have been downloaded
// todo: detect when in ~/go/src vs go.work mode
os.Setenv("GO111MODULE", "off")
defer os.Unsetenv("GO111MODULE")
if f.IsGoWork() {
// when building using a go.work file, never use GO111MODULE=off
os.Unsetenv("GO111MODULE")
} else {
// when building from ~/go/src, always use GO111MODULE=off
os.Setenv("GO111MODULE", "off")
defer os.Unsetenv("GO111MODULE")
}
// get the version
version := repo.GetCurrentBranchVersion()
@ -94,6 +99,12 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
cmd = append(cmd, "-ldflags", "-X "+flag)
}
testenv := os.Getenv("GO111MODULE")
if testenv == "off" {
log.Info("GO111MODULE=off", "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
} else {
log.Info("GO111MODULE=", testenv, "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
}
log.Info("running:", cmd)
result := repo.RunRealtime(cmd)
if result.Exit == 0 {
@ -107,7 +118,7 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
log.Warn("go build failed", cmd)
pwd, _ := os.Getwd()
log.Warn("go build pwd", pwd)
res2 := repo.RunRealtime(cmd)
res2 := shell.RunEcho(cmd)
if res2.Exit == 0 {
log.Info("again failed", res2.Exit)
log.Info("again failed cmd", strings.Join(cmd, "a"))

View File

@ -53,6 +53,21 @@ func useGoSrc() (string, error) {
return pwd, nil
}
func (f *Forge) goWorkExists() bool {
var err error
workFilePath := filepath.Join(f.GetGoSrc(), "go.work")
if _, err = os.Stat(workFilePath); err == nil {
log.Info("f.goWorkExists() found", workFilePath)
return true
} else if !os.IsNotExist(err) {
log.Info("f.goWorkExists() missing", workFilePath)
return false
}
// probably false, but some other error
log.Info("f.goWorkExists() os.Stat() error", err, workFilePath)
return false
}
func digup(path string) (string, error) {
for {
workFilePath := filepath.Join(path, "go.work")

11
init.go
View File

@ -34,9 +34,12 @@ func Init() *Forge {
fullpath := filepath.Join(homeDir, ".config/forge")
os.Setenv("FORGE_CONFIG", fullpath)
}
if f.goWorkExists() {
f.goWork = true
}
log.Info("forgepbb.Init() ~/go/src ", f.goSrc)
log.Info("forgepbb.Init() 2 FORGE_CONFIG", os.Getenv("FORGE_CONFIG"))
log.Info("forgepbb.Init() 2 FORGE_GOSRC", os.Getenv("FORGE_GOSRC"))
log.Info("forgepbb.Init() 2 FORGE_GOSRC", os.Getenv("FORGE_GOSRC"), "f.goWork =", f.IsGoWork())
// cache.go has Do()
// f.initOnce.Do(f.initWork)
@ -63,5 +66,11 @@ func Init() *Forge {
f.ScanGoSrc()
end := f.Repos.Len()
log.Info("forge.ScanGoSrc() Found", end-start, "new repos in", f.goSrc)
testenv := os.Getenv("GO111MODULE")
if testenv == "off" {
log.Info("GO111MODULE=off", "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
} else {
log.Info("GO111MODULE=", testenv, "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
}
return f
}