Commit 7ebf653f authored by Robert Griesemer's avatar Robert Griesemer

go/internal/gcimporter: interpret relative srcDir relative to cwd

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 #14215.

Change-Id: Ia3721f9ad8a1115d2595fe99b04baaf30d5765f2
Reviewed-on: https://go-review.googlesource.com/19393Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 811b7851
...@@ -31,7 +31,8 @@ var pkgExts = [...]string{".a", ".o"} ...@@ -31,7 +31,8 @@ var pkgExts = [...]string{".a", ".o"}
// FindPkg returns the filename and unique package id for an import // FindPkg returns the filename and unique package id for an import
// path based on package information provided by build.Import (using // 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. // If no file was found, an empty filename is returned.
// //
func FindPkg(path, srcDir string) (filename, id string) { func FindPkg(path, srcDir string) (filename, id string) {
...@@ -44,6 +45,9 @@ func FindPkg(path, srcDir string) (filename, id string) { ...@@ -44,6 +45,9 @@ func FindPkg(path, srcDir string) (filename, id string) {
default: default:
// "x" -> "$GOPATH/pkg/$GOOS_$GOARCH/x.ext", "x" // "x" -> "$GOPATH/pkg/$GOOS_$GOARCH/x.ext", "x"
// Don't require the source files to be present. // 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) bp, _ := build.Import(path, srcDir, build.FindOnly|build.AllowBinary)
if bp.PkgObj == "" { if bp.PkgObj == "" {
return return
......
...@@ -483,11 +483,9 @@ func pkgName(path string) string { ...@@ -483,11 +483,9 @@ func pkgName(path string) string {
// (Per the go/build package dependency tests, we cannot import // (Per the go/build package dependency tests, we cannot import
// path/filepath and simply use filepath.Dir.) // path/filepath and simply use filepath.Dir.)
func dir(path string) string { func dir(path string) string {
if i := strings.LastIndexAny(path, "/\\"); i >= 0 { if i := strings.LastIndexAny(path, `/\`); i > 0 {
path = path[:i] return path[:i]
} }
if path == "" { // i <= 0
path = "." return "."
}
return path
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment