71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package gitpb
|
|
|
|
//
|
|
// DOES NOT MODIFY FILES
|
|
//
|
|
// only reads in the go.mod file. doesn't change anything
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
// deprecate use of IsPrimitive() to this function
|
|
// this assumes go.mod and go.sum are in a releasable state
|
|
func (repo *Repo) setPrimitive() error {
|
|
_, err := repo.computePrimitive()
|
|
return err
|
|
}
|
|
|
|
// Detect a 'Primitive' package. Sets the isPrimitive flag
|
|
// will return true if the repo is truly not dependent on _anything_ else
|
|
// like spew or lib/widget
|
|
// it assumes go mod ran init and tidy ran without error
|
|
func (repo *Repo) computePrimitive() (bool, error) {
|
|
// go mod init & go mod tidy ran without errors
|
|
log.Log(GITPB, "isPrimitiveGoMod()", repo.FullPath)
|
|
tmp := filepath.Join(repo.FullPath, "go.mod")
|
|
gomod, err := os.Open(tmp)
|
|
if err != nil {
|
|
log.Log(GITPB, "missing go.mod", repo.FullPath)
|
|
return false, err
|
|
}
|
|
defer gomod.Close()
|
|
|
|
if repo.Exists("go.sum") {
|
|
repo.GoInfo.GoPrimitive = false
|
|
return false, nil
|
|
}
|
|
|
|
scanner := bufio.NewScanner(gomod)
|
|
for scanner.Scan() {
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
parts := strings.Fields(line)
|
|
log.Log(GITPB, " gomod:", parts)
|
|
if len(parts) >= 1 {
|
|
log.Log(GITPB, " gomod: part[0] =", parts[0])
|
|
if parts[0] == "require" {
|
|
log.Log(GITPB, " should return false here")
|
|
return false, errors.New("go.mod file is not primitive")
|
|
}
|
|
/*
|
|
if parts[0] == "go" {
|
|
if parts[1] != "1.21" {
|
|
log.Log(GITPBWARN, "go not set to 1.21 for", repo.GetGoPath())
|
|
// return false, errors.New("go not set to 1.21 for " + repo.GetGoPath())
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
repo.GoInfo.GoPrimitive = true
|
|
repo.GoDeps = nil
|
|
return true, nil
|
|
}
|