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
cmd/go: document that vendor directories are ignored for packages without import paths #18007
Comments
We'll figure out whether it was intentional during the Go 1.9 cycle It's not Go 1.8 material since it's presumably been like this for a few cycles. Correct me if that's wrong. |
More specifically, Go fails to apply the vendor directory for subdirectories of testdata. That is, |
Go 1.8 rejects testdata entirely. (see also cl31665 and #17597)
|
… language. Mixing C++ and Go source files fail with: "can't build package github.com/pascaldekloe/colfer/testdata because it contains C++ files (Colfer.cpp) but it's not using cgo nor SWIG" Go 1.8 fails to compile source code in "testdata". See also: golang/go#18007
I'm not sure what the previous comment means, but when I run my repro in Go 1.8 I get exactly the same output as I did in 1.7.3. |
I get the same in go1.8 and go1.9beta2 linux/amd64: chen@chen-pc:~/git/go/src/text$ go build
unexpected directory layout:
import path: github.com/go-sql-driver/mysql
root: /home/chen/git/go/src
dir: /home/chen/git/go/src/text/vendor/github.com/go-sql-driver/mysql
expand root: /home/chen/git/go/src
expand dir: /home/chen/git/go/src/text/vendor/github.com/go-sql-driver/mysql
separator: / But my project is chen@chen-pc:~/git/go/src/text$ ll -a
总用量 16
drwxr-xr-x 3 chen chen 4096 6月 28 22:57 .
drwxr-xr-x 12 chen chen 4096 6月 28 22:55 ..
-rwxr-xr-x 1 chen chen 1031 6月 28 22:30 main.go
drwxr-xr-x 4 chen chen 4096 6月 28 22:46 vendor
chen@chen-pc:~/git/go/src/text$ echo $GOPATH
/home/chen/git/go
chen@chen-pc:~/git/go/src/text$ pwd
/home/chen/git/go/src/text |
Different issue. You can't use package text as it's already in the core
library.
Op 28 jun. 2017 5:04 p.m. schreef "chenhao" <notifications@github.com>:
… I get the same in go1.8 and go1.9beta2 linux/amd64:
***@***.***:~/git/go/src/text$ go build
unexpected directory layout:
import path: github.com/go-sql-driver/mysql
root: /home/chen/git/go/src
dir: /home/chen/git/go/src/text/vendor/github.com/go-sql-driver/mysql
expand root: /home/chen/git/go/src
expand dir: /home/chen/git/go/src/text/vendor/github.com/go-sql-driver/mysql
separator: /
*But my project is text*:
***@***.***:~/git/go/src/text$ ll -a
总用量 16
drwxr-xr-x 3 chen chen 4096 6月 28 22:57 .
drwxr-xr-x 12 chen chen 4096 6月 28 22:55 ..
-rwxr-xr-x 1 chen chen 1031 6月 28 22:30 main.go
drwxr-xr-x 4 chen chen 4096 6月 28 22:46 vendor
***@***.***:~/git/go/src/text$ echo $GOPATH
/home/chen/git/go
***@***.***:~/git/go/src/text$ pwd
/home/chen/git/go/src/text
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#18007 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEpEAHHwHeuvDJH4rBb4yeFtgi0M0ex5ks5sImtfgaJpZM4K4ujc>
.
|
@pascaldekloe Thinks for your answer. |
I've just hit this myself too, and was confused by how this limitation isn't documented anywhere. Like @cespare, I was using I currently don't see an easy workaround. I could make the test make a full copy of |
Hey @bcmills, thanks for taking a look. However, I don't follow the argument you're making.
Can you explain this more? Packages inside a testdata directory are treated as though they're in the surrounding GOPATH today. You can import any package you like from the GOPATH, just like packages outside testdata, except that you cannot import from vendor. You can even import packages that transitively use vendor packages and that works fine. I've run into this multiple times with tests that build Go code. In one case we had a test that worked fine for months but then started failing because the generated code it was building started (directly) using a vendored package. If code in testdata "isn't in GOPATH", then it should behave like that and it should be documented. It should not behave as though it is in GOPATH but with one tiny difference. |
Given that it remains surprising and undocumented, I'm reopening this issue. I understand that the resolution may not be the fix I'm asking for (make vendor work inside testdata) but the behavior should at least make sense in a way that's derivable from the documentation. |
Packages inside
|
Retitled accordingly. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Go 1.7.3 and tip
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
A package inside a directory named
testdata
cannot use vendored packages from above the testdata directory. Here's a demo:This came up while writing tests for a program that itself invokes
go build
to build and run a temp binary.I'm aware that testdata is special. It's documented in
go help test
:and
go help packages
:but it wasn't obvious to me that not being able to use vendored packages is a consequence of this. Should it have been? Is this intended?
The text was updated successfully, but these errors were encountered: