2024-12-03 00:35:50 -06:00
|
|
|
package gitpb
|
|
|
|
|
2024-12-12 02:07:25 -06:00
|
|
|
//
|
|
|
|
// DOES NOT MODIFY FILES
|
|
|
|
//
|
2024-12-03 00:35:50 -06:00
|
|
|
// only reads in the go.mod file. doesn't change anything
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-12-15 15:53:08 -06:00
|
|
|
// deprecate use of IsPrimitive() to this function
|
|
|
|
// this assumes go.mod and go.sum are in a releasable state
|
2024-12-18 20:09:18 -06:00
|
|
|
func (repo *Repo) setPrimitive() error {
|
2024-12-17 20:48:23 -06:00
|
|
|
_, err := repo.computePrimitive()
|
2024-12-15 15:53:08 -06:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-18 18:51:51 -06:00
|
|
|
// Detect a 'Primitive' package. Sets the isPrimitive flag
|
2024-12-03 00:35:50 -06:00
|
|
|
// 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
|
2024-12-17 20:48:23 -06:00
|
|
|
func (repo *Repo) computePrimitive() (bool, error) {
|
2024-12-03 00:35:50 -06:00
|
|
|
// go mod init & go mod tidy ran without errors
|
2024-12-18 18:51:51 -06:00
|
|
|
log.Log(GITPB, "isPrimitiveGoMod()", repo.FullPath)
|
2024-12-03 00:35:50 -06:00
|
|
|
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()
|
|
|
|
|
2024-12-18 18:51:51 -06:00
|
|
|
if repo.Exists("go.sum") {
|
|
|
|
repo.GoInfo.GoPrimitive = false
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2024-12-03 00:35:50 -06:00
|
|
|
scanner := bufio.NewScanner(gomod)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
|
2024-12-13 00:19:33 -06:00
|
|
|
parts := strings.Fields(line)
|
2024-12-03 00:35:50 -06:00
|
|
|
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")
|
2024-12-18 18:51:51 -06:00
|
|
|
return false, errors.New("go.mod file is not primitive")
|
2024-12-03 00:35:50 -06:00
|
|
|
}
|
2024-12-18 18:51:51 -06:00
|
|
|
/*
|
|
|
|
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())
|
|
|
|
}
|
2024-12-13 00:19:33 -06:00
|
|
|
}
|
2024-12-18 18:51:51 -06:00
|
|
|
*/
|
2024-12-03 00:35:50 -06:00
|
|
|
}
|
|
|
|
}
|
2024-12-17 06:37:14 -06:00
|
|
|
repo.GoInfo.GoPrimitive = true
|
2024-12-03 00:35:50 -06:00
|
|
|
repo.GoDeps = nil
|
|
|
|
return true, nil
|
|
|
|
}
|