go primative logic is correct now
This commit is contained in:
parent
2a19cd5eef
commit
70e8c98b1c
9
args.go
9
args.go
|
@ -12,6 +12,9 @@ var INFO *log.LogFlag
|
||||||
var WARN *log.LogFlag
|
var WARN *log.LogFlag
|
||||||
var CHANGE *log.LogFlag
|
var CHANGE *log.LogFlag
|
||||||
|
|
||||||
|
var REPO *log.LogFlag
|
||||||
|
var REPOWARN *log.LogFlag
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
full := "go.wit.com/lib/gui/repostatus"
|
full := "go.wit.com/lib/gui/repostatus"
|
||||||
short := "repostatus"
|
short := "repostatus"
|
||||||
|
@ -19,4 +22,10 @@ func init() {
|
||||||
INFO = log.NewFlag("INFO", false, full, short, "general repo things")
|
INFO = log.NewFlag("INFO", false, full, short, "general repo things")
|
||||||
WARN = log.NewFlag("WARN", true, full, short, "bad things")
|
WARN = log.NewFlag("WARN", true, full, short, "bad things")
|
||||||
CHANGE = log.NewFlag("CHANGE", true, full, short, "when repo changes")
|
CHANGE = log.NewFlag("CHANGE", true, full, short, "when repo changes")
|
||||||
|
|
||||||
|
full = "go.wit.com/lib/gui/repo"
|
||||||
|
short = "repo"
|
||||||
|
|
||||||
|
REPO = log.NewFlag("REPO", false, full, short, "general repo things")
|
||||||
|
REPOWARN = log.NewFlag("REPOWARN", true, full, short, "repo warnings")
|
||||||
}
|
}
|
||||||
|
|
85
goConfig.go
85
goConfig.go
|
@ -15,13 +15,14 @@ import (
|
||||||
// Detect a 'Primative' package. Sets the isPrimative flag
|
// Detect a 'Primative' package. Sets the isPrimative flag
|
||||||
// will return true if the repo is truly not dependent on _anything_ else
|
// will return true if the repo is truly not dependent on _anything_ else
|
||||||
// like spew or lib/widget
|
// like spew or lib/widget
|
||||||
|
// it assumes go mod ran init and tidy ran without error
|
||||||
func (rs *RepoStatus) isPrimativeGoMod() (bool, error) {
|
func (rs *RepoStatus) isPrimativeGoMod() (bool, error) {
|
||||||
// go mod init & go mod tidy ran without errors
|
// go mod init & go mod tidy ran without errors
|
||||||
log.Log(WARN, "isPrimativeGoMod()", rs.realPath.String())
|
log.Log(REPO, "isPrimativeGoMod()", rs.realPath.String())
|
||||||
tmp := filepath.Join(rs.realPath.String(), "go.mod")
|
tmp := filepath.Join(rs.realPath.String(), "go.mod")
|
||||||
gomod, err := os.Open(tmp)
|
gomod, err := os.Open(tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(WARN, "missing go.mod", rs.realPath.String())
|
log.Log(REPO, "missing go.mod", rs.realPath.String())
|
||||||
rs.goConfig = nil
|
rs.goConfig = nil
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -32,12 +33,12 @@ func (rs *RepoStatus) isPrimativeGoMod() (bool, error) {
|
||||||
line := strings.TrimSpace(scanner.Text())
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
|
||||||
parts := strings.Split(line, " ")
|
parts := strings.Split(line, " ")
|
||||||
log.Log(INFO, " gomod:", parts)
|
log.Log(REPO, " gomod:", parts)
|
||||||
if len(parts) >= 1 {
|
if len(parts) >= 1 {
|
||||||
log.Log(INFO, " gomod: part[0] =", parts[0])
|
log.Log(REPO, " gomod: part[0] =", parts[0])
|
||||||
if parts[0] == "require" {
|
if parts[0] == "require" {
|
||||||
log.Log(INFO, " should return false here")
|
log.Log(REPO, " should return false here")
|
||||||
return false, errors.New("bad go.mod file" + rs.GoPath())
|
return false, errors.New("go.mod file is not primative")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,28 +47,12 @@ func (rs *RepoStatus) isPrimativeGoMod() (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// readGoMod reads and parses the go.sum file
|
// readGoMod reads and parses the go.sum file
|
||||||
// saves the config information in repo.goConfig
|
// saves the config information in *Repo.goConfig
|
||||||
func (rs *RepoStatus) parseGoSum() (bool, error) {
|
func (rs *RepoStatus) parseGoSum() (bool, error) {
|
||||||
ok, err := rs.isPrimativeGoMod()
|
|
||||||
if err != nil {
|
|
||||||
// this means this repo does not depend on any other package
|
|
||||||
log.Info("PRIMATIVE repo:", rs.String(), "err =", err)
|
|
||||||
rs.goConfig = nil
|
|
||||||
rs.primitive.SetText("false")
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
// this means the repo is primitive so there is no go.sum
|
|
||||||
rs.goConfig = nil
|
|
||||||
rs.primitive.SetText("true")
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
rs.primitive.SetText("false")
|
|
||||||
|
|
||||||
tmp := filepath.Join(rs.realPath.String(), "go.sum")
|
tmp := filepath.Join(rs.realPath.String(), "go.sum")
|
||||||
gosum, err := os.Open(tmp)
|
gosum, err := os.Open(tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(WARN, "missing go.sum", rs.realPath.String())
|
log.Log(REPO, "missing go.sum", rs.realPath.String())
|
||||||
rs.goConfig = nil
|
rs.goConfig = nil
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -77,7 +62,7 @@ func (rs *RepoStatus) parseGoSum() (bool, error) {
|
||||||
deps = make(GoConfig)
|
deps = make(GoConfig)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(gosum)
|
scanner := bufio.NewScanner(gosum)
|
||||||
log.Log(INFO, "gosum:", tmp)
|
log.Log(REPO, "gosum:", tmp)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := strings.TrimSpace(scanner.Text())
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
|
||||||
|
@ -90,23 +75,21 @@ func (rs *RepoStatus) parseGoSum() (bool, error) {
|
||||||
}
|
}
|
||||||
currentversion, ok := deps[godep]
|
currentversion, ok := deps[godep]
|
||||||
if ok {
|
if ok {
|
||||||
if currentversion != version {
|
// only use the first value found in the file?
|
||||||
// ignore these warnings for now
|
// this shouldn't have been possible. this function should
|
||||||
depname := rs.String()
|
// only be called from MakeRedomod()
|
||||||
if strings.HasPrefix(depname, "go.wit.com") {
|
// todo: make go things a seperate package so this function
|
||||||
log.Log(INFO, "REPO:", rs.realPath.String())
|
// isn't exported?
|
||||||
log.Log(INFO, " version mismatch:", godep, version, currentversion)
|
if version != currentversion {
|
||||||
} else {
|
log.Log(REPOWARN, "\tgo.sum ", godep, "had both", version, currentversion)
|
||||||
log.Log(INFO, "REPO:", rs.realPath.String())
|
|
||||||
log.Log(INFO, " version mismatch:", godep, version, currentversion)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
deps[godep] = version
|
deps[godep] = version
|
||||||
log.Log(INFO, "\t", godep, "=", version)
|
log.Log(REPO, "\t", godep, "=", version)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Log(WARN, "\t INVALID:", parts)
|
// I've never seen this happen yet
|
||||||
|
return false, errors.New("go.sum invalid: " + line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +114,7 @@ func (rs *RepoStatus) MakeRedomod() (bool, error) {
|
||||||
var err error
|
var err error
|
||||||
var output string
|
var output string
|
||||||
if rs.ReadOnly() {
|
if rs.ReadOnly() {
|
||||||
log.Log(WARN, "will not go mod redo read only repos", rs.String())
|
log.Log(REPO, "will not go mod redo read only repos", rs.String())
|
||||||
return false, errors.New(rs.GoPath() + " is read-only ")
|
return false, errors.New(rs.GoPath() + " is read-only ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,24 +122,42 @@ func (rs *RepoStatus) MakeRedomod() (bool, error) {
|
||||||
os.Unsetenv("GO111MODULE")
|
os.Unsetenv("GO111MODULE")
|
||||||
err, output = rs.RunCmd([]string{"rm", "-f", "go.mod", "go.sum"})
|
err, output = rs.RunCmd([]string{"rm", "-f", "go.mod", "go.sum"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(WARN, "rm failed", err, output)
|
log.Log(REPO, "rm failed", err, output)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
err, output = rs.RunCmd([]string{"go", "mod", "init"})
|
err, output = rs.RunCmd([]string{"go", "mod", "init"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(WARN, "go mod init failed", err, output)
|
log.Log(REPO, "go mod init failed", err, output)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
err, output = rs.RunCmd([]string{"go", "mod", "tidy"})
|
err, output = rs.RunCmd([]string{"go", "mod", "tidy"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(WARN, "go mod tidy failed", err, output)
|
log.Log(REPO, "go mod tidy failed", err, output)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
log.Log(INFO, "MakeRedomod() worked", rs.GoPath())
|
log.Log(REPO, "MakeRedomod() worked", rs.GoPath())
|
||||||
|
|
||||||
|
if rs.Exists("go.sum") {
|
||||||
// return the attempt to parse go.mod & go.sum
|
// return the attempt to parse go.mod & go.sum
|
||||||
return rs.parseGoSum()
|
return rs.parseGoSum()
|
||||||
}
|
}
|
||||||
|
rs.goConfig = nil
|
||||||
|
rs.primitive.SetText("false")
|
||||||
|
|
||||||
|
ok, err := rs.isPrimativeGoMod()
|
||||||
|
if err != nil {
|
||||||
|
// this means this repo does not depend on any other package
|
||||||
|
log.Info("PRIMATIVE repo:", rs.String(), "err =", err)
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
// this means the repo is primitive so there is no go.sum
|
||||||
|
rs.primitive.SetText("true")
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
// this should never happen
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (rs *RepoStatus) IsReleased() bool {
|
func (rs *RepoStatus) IsReleased() bool {
|
||||||
if rs.GetTargetVersion() == rs.GetCurrentVersion() {
|
if rs.GetTargetVersion() == rs.GetCurrentVersion() {
|
||||||
|
|
Loading…
Reference in New Issue