Fix relative paths inside sources
This commit is contained in:
parent
e51f884b85
commit
ecf0c76348
2 changed files with 23 additions and 16 deletions
|
@ -11,7 +11,9 @@ import (
|
|||
"golang.org/x/mod/module"
|
||||
"golang.org/x/tools/go/vcs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -161,7 +163,7 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
rev = commitShaRev.FindAllStringSubmatch(rev, -1)[0][1]
|
||||
}
|
||||
|
||||
goPackagePathPrefix, _, _ := module.SplitPathVersion(goPackagePath)
|
||||
goPackagePathPrefix, pathMajor, _ := module.SplitPathVersion(goPackagePath)
|
||||
|
||||
// Relative path within the repo
|
||||
relPath := strings.TrimPrefix(goPackagePathPrefix, repoRoot.Root+"/")
|
||||
|
@ -169,9 +171,7 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
relPath = ""
|
||||
}
|
||||
|
||||
newRev := fmt.Sprintf("%s/%s", relPath, rev)
|
||||
if len(caches) > 0 {
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"goPackagePath": goPackagePath,
|
||||
}).Info("Checking previous invocation cache")
|
||||
|
@ -179,8 +179,7 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
for _, cache := range caches {
|
||||
cached, ok := cache[goPackagePath]
|
||||
if ok {
|
||||
for _, rev := range []string{rev, newRev} {
|
||||
if cached.Rev == rev {
|
||||
if cached.SumVersion == sumVersion {
|
||||
log.WithFields(log.Fields{
|
||||
"goPackagePath": goPackagePath,
|
||||
}).Info("Returning cached entry")
|
||||
|
@ -189,7 +188,6 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if repoRoot.VCS.Name != "Git" {
|
||||
return nil, fmt.Errorf("Only git repositories are supported")
|
||||
|
@ -199,7 +197,7 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
URL string `json:"url"`
|
||||
Rev string `json:"rev"`
|
||||
Sha256 string `json:"sha256"`
|
||||
// path string
|
||||
Path string `json:"path"`
|
||||
// date string
|
||||
// fetchSubmodules bool
|
||||
// deepClone bool
|
||||
|
@ -217,6 +215,8 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
"--url", repoRoot.Repo,
|
||||
"--rev", rev).Output()
|
||||
if err != nil {
|
||||
newRev := fmt.Sprintf("%s/%s", relPath, rev)
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"goPackagePath": goPackagePath,
|
||||
"rev": newRev,
|
||||
|
@ -239,7 +239,6 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
}
|
||||
|
||||
var output *prefetchOutput
|
||||
|
||||
err = json.Unmarshal(stdout, &output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -247,8 +246,16 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
|||
|
||||
vendorPath := ""
|
||||
if importPath != goPackagePath {
|
||||
importPathPrefix, _, _ := module.SplitPathVersion(importPath)
|
||||
vendorPath = importPathPrefix
|
||||
vendorPath = importPath
|
||||
}
|
||||
|
||||
if relPath == "" && pathMajor != "" {
|
||||
p := filepath.Join(output.Path, pathMajor)
|
||||
_, err := os.Stat(p)
|
||||
if err == nil {
|
||||
fmt.Println(pathMajor)
|
||||
relPath = strings.TrimPrefix(pathMajor, "/")
|
||||
}
|
||||
}
|
||||
|
||||
return &types.Package{
|
||||
|
|
|
@ -17,8 +17,8 @@ type fetchInfo struct {
|
|||
|
||||
type packageT struct {
|
||||
SumVersion string `toml:"sumVersion"`
|
||||
RelPath string `toml:"relPath"`
|
||||
VendorPath string `toml:"vendorPath"`
|
||||
RelPath string `toml:"relPath,omitempty"`
|
||||
VendorPath string `toml:"vendorPath,omitempty"`
|
||||
Fetch *fetchInfo `toml:"fetch"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue