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 // TODO: make some config file for things like this
// can be used to work around temporary problems // 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 { switch gopath {
case "golang.org/x/crypto": case "golang.org/x/crypto":
return "go.googlesource.com/crypto" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/crypto")
case "golang.org/x/mod": case "golang.org/x/mod":
return "go.googlesource.com/mod" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/mod")
case "golang.org/x/net": case "golang.org/x/net":
return "go.googlesource.com/net" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/net")
case "golang.org/x/sys": case "golang.org/x/sys":
return "go.googlesource.com/sys" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/sys")
case "golang.org/x/sync": case "golang.org/x/sync":
return "go.googlesource.com/sync" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/sync")
case "golang.org/x/term": case "golang.org/x/term":
return "go.googlesource.com/term" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/term")
case "golang.org/x/text": case "golang.org/x/text":
return "go.googlesource.com/text" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/text")
case "golang.org/x/tools": case "golang.org/x/tools":
return "go.googlesource.com/tools" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/tools")
case "golang.org/x/xerrors": case "golang.org/x/xerrors":
return "go.googlesource.com/xerrors" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/xerrors")
case "google.golang.org/protobuf": case "google.golang.org/protobuf":
return "go.googlesource.com/protobuf" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/protobuf")
case "google.golang.org/genproto": case "google.golang.org/genproto":
return "go.googlesource.com/genproto" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/genproto")
case "google.golang.org/api": case "google.golang.org/api":
return "go.googlesource.com/api" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/api")
case "google.golang.org/grpc": case "google.golang.org/grpc":
return "go.googlesource.com/grpc" return cloneActual(dirname, basedir, "https://" + "go.googlesource.com/grpc")
case "google.golang.org/appengine": 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 // 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/ // workdir = /home/jcarr/go/src/
// gopath = go.wit.com/apps/helloworld // gopath = go.wit.com/apps/helloworld
func Clone(workdir, gopath string) error { func Clone(workdir, gopath string) error {
// temp hack to fix paths.
gopath = pathHack(gopath)
fullpath := filepath.Join(workdir, gopath) fullpath := filepath.Join(workdir, gopath)
dirname := filepath.Base(fullpath) dirname := filepath.Base(fullpath)
@ -129,6 +132,7 @@ func Clone(workdir, gopath string) error {
log.Info("trying git clone") log.Info("trying git clone")
log.Info("gopath =", gopath) log.Info("gopath =", gopath)
// try a direct git clone against the 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") // cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "http://go.wit.com/apps/helloworld")
if err = cloneActual(dirname, basedir, url); err == nil { 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 // 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 // try the go package system as maybe the git site no longer exists
if url, err = findGoImport(url); err != nil { if url, err = findGoImport(url); err != nil {
return err log.Info("findGoImport() DID NOT WORK", url)
} log.Info("findGoImport() DID NOT WORK", err)
if err := cloneActual(dirname, basedir, url); err == nil { } else {
// git clone worked! if err := cloneActual(dirname, basedir, url); err == nil {
return 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 // 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 // NOTE: take time to thank the go developers and google for designing this wonderful system
if url, err = runGoList(gopath); err != nil { if url, err = runGoList(gopath); err != nil {
log.Info("go list failed", err) 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 { log.Info("git clone from 'git list' info failed", url)
// git clone worked!
return nil
}
log.Info("direct attempt at git clone failed", url)
// try to parse a redirect // 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) return errors.New("can not find git sources for gopath " + gopath)
} }