work towards a global override file

This commit is contained in:
Jeff Carr 2024-11-22 22:30:08 -06:00
parent 4c46927bc7
commit 2866815e3c
1 changed files with 41 additions and 28 deletions

View File

@ -77,39 +77,44 @@ func guessPaths(path string) (string, string, string, bool, error) {
// TODO: make some config file for things like this
// can be used to work around temporary problems
func pathHack(gopath string) string {
func clonePathHack(dirname string, basedir string, gopath string) error {
// newdir = helloworld
// basedir = /home/jcarr/go/src/go.wit.com/apps
// giturl = https://gitea.wit.com/gui/helloworld
// func cloneActual(newdir, basedir, giturl string) error {
switch gopath {
case "golang.org/x/crypto":
return "go.googlesource.com/crypto"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/crypto")
case "golang.org/x/mod":
return "go.googlesource.com/mod"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/mod")
case "golang.org/x/net":
return "go.googlesource.com/net"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/net")
case "golang.org/x/sys":
return "go.googlesource.com/sys"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/sys")
case "golang.org/x/sync":
return "go.googlesource.com/sync"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/sync")
case "golang.org/x/term":
return "go.googlesource.com/term"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/term")
case "golang.org/x/text":
return "go.googlesource.com/text"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/text")
case "golang.org/x/tools":
return "go.googlesource.com/tools"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/tools")
case "golang.org/x/xerrors":
return "go.googlesource.com/xerrors"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/xerrors")
case "google.golang.org/protobuf":
return "go.googlesource.com/protobuf"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/protobuf")
case "google.golang.org/genproto":
return "go.googlesource.com/genproto"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/genproto")
case "google.golang.org/api":
return "go.googlesource.com/api"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/api")
case "google.golang.org/grpc":
return "go.googlesource.com/grpc"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/grpc")
case "google.golang.org/appengine":
return "go.googlesource.com/appengine"
return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/appengine")
}
return gopath
return errors.New("no gopath override here")
}
// attempt to git clone if the go path doesn't exist
@ -117,8 +122,6 @@ func pathHack(gopath string) string {
// workdir = /home/jcarr/go/src/
// gopath = go.wit.com/apps/helloworld
func Clone(workdir, gopath string) error {
// temp hack to fix paths.
gopath = pathHack(gopath)
fullpath := filepath.Join(workdir, gopath)
dirname := filepath.Base(fullpath)
@ -129,6 +132,7 @@ func Clone(workdir, gopath string) error {
log.Info("trying git clone")
log.Info("gopath =", gopath)
// try a direct git clone against the gopath
// cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "http://go.wit.com/apps/helloworld")
if err = cloneActual(dirname, basedir, url); err == nil {
@ -141,26 +145,35 @@ func Clone(workdir, gopath string) error {
// go directly to the URL as that is autoritive. If that failes
// try the go package system as maybe the git site no longer exists
if url, err = findGoImport(url); err != nil {
return err
}
if err := cloneActual(dirname, basedir, url); err == nil {
// git clone worked!
return nil
log.Info("findGoImport() DID NOT WORK", url)
log.Info("findGoImport() DID NOT WORK", err)
} else {
if err := cloneActual(dirname, basedir, url); err == nil {
// git clone worked!
return nil
}
}
log.Info("git clone from 'go-import' info failed", url)
// query the golang package system for the last known location
// NOTE: take time to thank the go developers and google for designing this wonderful system
if url, err = runGoList(gopath); err != nil {
log.Info("go list failed", err)
} else {
if err := cloneActual(dirname, basedir, url); err == nil {
// git clone worked!
return nil
}
}
if err := cloneActual(dirname, basedir, url); err == nil {
// git clone worked!
return nil
}
log.Info("direct attempt at git clone failed", url)
log.Info("git clone from 'git list' info failed", url)
// try to parse a redirect
if err = clonePathHack(dirname, basedir, gopath); err == nil {
// WTF didn't go-import or go list work?
return nil
}
return errors.New("can not find git sources for gopath " + gopath)
}