Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/build: Import(".", ".", 0) fails to resolve the full package path relative to GOPATH while build.Import(".", <cwd>, 0) works #9057

maruel opened this issue Nov 3, 2014 · 1 comment


Copy link

maruel commented Nov 3, 2014

What does 'go version' print?
go version go1.3.3 linux/amd64

What steps reproduce the problem?
1. mkdir $HOME/src2
2. mkdir $HOME/src2/golang
3. export GOPATH=$HOME/src2/golang
4. mkdir -p $GOPATH/src/foo
5. Put the content of into $GOPATH/src/foo/a.go
6. go run a.go

What happened?
build.ImportDir() and build.Import() fail to correctly resolve Package.ImportPath to
"foo". I think it used (?) to work recently.

I reproduce the problem via but it can be easily
reproduced with the code I provided above. The problem is actually surfacing in which does the build.ImportDir(".", 0) call,
which fails to return the correct ImportPath.

What should have happened instead?
build.ImportDir() and build.Import() with "." should have the same behavior
than when provided os.Getwd(), e.g.:

Do the same code path as would 
dir, _ := os.Getwd()
pkg, err := build.Import(".", dir, 0)

should have the same result than:

pkg, err := build.Import(".", ".", 0)
Copy link

ianlancetaylor commented Nov 3, 2014

Comment 1:

For Import I think this is working-as-intended, but we should consider returning an
error when we need to use the srcDir argument but it is not an absolute path.
ImportDir shouldn't require a srcDir argument if there is no local import, but at
present ImportDir is always treated as a local import.  That is probably a minor bug.

Labels changed: added repo-main, release-none.

@maruel maruel added new labels Nov 3, 2014
@bradfitz bradfitz removed the new label Dec 18, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

4 participants