Skip to content

Commit

Permalink
fix(go): Fix go import resolution from within vendored packages
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed May 15, 2018
1 parent 9e856c8 commit cc9586b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions builders/bindata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion builders/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,15 +692,19 @@ func (builder *GoBuilder) Analyze(m module.Module, allowUnresolved bool) ([]modu
if strings.HasPrefix(pkg.Project, "vendor/golang_org") {
continue
}

// Strip `/vendor/` folders.
const vendorPrefix = "/vendor/"
vendoredPathSections := strings.Split(pkg.Project, vendorPrefix)
importPath := vendoredPathSections[len(vendoredPathSections)-1]
log.Debugf("Resolving import: %s", importPath)

vendoredProjectSections := strings.Split(projectGopath, vendorPrefix)
projectVendored := vendoredProjectSections[len(vendoredProjectSections)-1]

importedProject, err := findRevision(lockfile, importPath)
if err != nil {
if strings.Index(importPath, projectGopath) == 0 {
if strings.Index(importPath, projectGopath) == 0 || strings.Index(importPath, projectVendored) == 0 {
log.Debugf("Did not resolve import: %#v", pkg.Project)
traced[i].Revision = lockfile[importedProject]
} else if allowUnresolved {
Expand All @@ -711,6 +715,7 @@ func (builder *GoBuilder) Analyze(m module.Module, allowUnresolved bool) ([]modu
log.Debugf("Project folder: %#v", projectFolder)
log.Debugf("$GOPATH: %#v", os.Getenv("GOPATH"))
log.Debugf("Project folder relative to $GOPATH: %#v", projectGopath)
log.Debugf("Project folder relative to vendoring: %#v", projectVendored)
log.Debugf("Lockfile versions: %#v", lockfile)
return nil, fmt.Errorf("could not resolve import: %#v", importPath)
}
Expand Down

0 comments on commit cc9586b

Please sign in to comment.