Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

Commit

Permalink
Parameterize import mode by go version
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed Jun 21, 2016
1 parent 8b7e0d3 commit 82908e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 3 additions & 5 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ func listPackages(fileRoot, importRoot string) (PackageTree, error) {
//pretty.Printf("ip:\t\t%s\n", ip)

// Find all the imports, across all os/arch combos
// 0x8 is build.IgnoreVendor, but that was introduced in go1.6. This
// gives us easy backwards compat.
p, err := ctx.ImportDir(path, build.ImportComment|0x8)
p, err := ctx.ImportDir(path, analysisImportMode())
var pkg Package
if err == nil {
pkg = happy(ip, p)
Expand Down Expand Up @@ -216,12 +214,12 @@ func listPackages(fileRoot, importRoot string) (PackageTree, error) {
// outf first; if there's another err there, we bail out with a
// return
ctx.ReadDir = outf
po, err2 := ctx.ImportDir(path, build.ImportComment|0x8)
po, err2 := ctx.ImportDir(path, analysisImportMode())
if err2 != nil {
return nil
}
ctx.ReadDir = inf
pi, err2 := ctx.ImportDir(path, build.ImportComment|0x8)
pi, err2 := ctx.ImportDir(path, analysisImportMode())
if err2 != nil {
return nil
}
Expand Down
13 changes: 13 additions & 0 deletions import_mode_go15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !go1.6

package vsolver

import "go/build"

// analysisImportMode returns the import mode used for build.Import() calls for
// standard package analysis.
//
// build.NoVendor was added in go1.6, so we have to omit it here.
func analysisImportMode() build.ImportMode {
return build.ImportComment
}
11 changes: 11 additions & 0 deletions import_mode_go16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build go1.6

package vsolver

import "go/build"

// analysisImportMode returns the import mode used for build.Import() calls for
// standard package analysis.
func analysisImportMode() build.ImportMode {
return build.ImportComment | build.IgnoreVendor
}

0 comments on commit 82908e4

Please sign in to comment.