Skip to content

Commit

Permalink
go/internal/gcimporter: interpret relative srcDir relative to cwd
Browse files Browse the repository at this point in the history
1) go/types.dir: Correctly return "." if there is no path.
2) go/internal/gcimporter.FindPkg: work-around for build.Import
   (build.Import doesn't produce expected result if srcDir is
   relative). See also issue 14282.

Fixes golang#14215.

Change-Id: Ia3721f9ad8a1115d2595fe99b04baaf30d5765f2
Reviewed-on: https://go-review.googlesource.com/19393
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
griesemer committed Feb 10, 2016
1 parent 811b785 commit 7ebf653
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/go/internal/gcimporter/gcimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var pkgExts = [...]string{".a", ".o"}

// FindPkg returns the filename and unique package id for an import
// path based on package information provided by build.Import (using
// the build.Default build.Context).
// the build.Default build.Context). A relative srcDir is interpreted
// relative to the current working directory.
// If no file was found, an empty filename is returned.
//
func FindPkg(path, srcDir string) (filename, id string) {
Expand All @@ -44,6 +45,9 @@ func FindPkg(path, srcDir string) (filename, id string) {
default:
// "x" -> "$GOPATH/pkg/$GOOS_$GOARCH/x.ext", "x"
// Don't require the source files to be present.
if abs, err := filepath.Abs(srcDir); err == nil { // see issue 14282
srcDir = abs
}
bp, _ := build.Import(path, srcDir, build.FindOnly|build.AllowBinary)
if bp.PkgObj == "" {
return
Expand Down
10 changes: 4 additions & 6 deletions src/go/types/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,9 @@ func pkgName(path string) string {
// (Per the go/build package dependency tests, we cannot import
// path/filepath and simply use filepath.Dir.)
func dir(path string) string {
if i := strings.LastIndexAny(path, "/\\"); i >= 0 {
path = path[:i]
if i := strings.LastIndexAny(path, `/\`); i > 0 {
return path[:i]
}
if path == "" {
path = "."
}
return path
// i <= 0
return "."
}

0 comments on commit 7ebf653

Please sign in to comment.