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

cmd/go: go test -compiler $pkg can mask std package with name $(basename $pkg) #6793

Closed
mwhudson opened this issue Nov 19, 2013 · 7 comments
Closed

Comments

@mwhudson
Copy link
Contributor

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. Set up a package like this:

mwhudson@narsil:goplay$ cd $GOPATH/src/mwhudson/testing
mwhudson@narsil:testing$ for fname in *.go; do echo ++ $fname ++; cat $fname; done
++ t2_test.go ++
package testing

++ t.go ++
package testing

++ t_test.go ++
package testing_test
import stdtesting "testing"
func f(t *stdtesting.T) {}


2. Run "go test -compiler gccgo mwhudson/testing"

What is the expected output?

ok      mwhudson/testing    0.004s

What do you see instead?

# mwhudson/testing_test
./t_test.go:3:11: error: reference to undefined identifier ‘testing.T’
 func f(t *stdtesting.T) {}
           ^
FAIL    mwhudson/testing [build failed]


Which compiler are you using (5g, 6g, 8g, gccgo)?

gccgo

Which operating system are you using?

Ubuntu 13.10


Which version are you using?  (run 'go version')

mwhudson@narsil:testing$ go version
go version devel +b1edf8faa5d6 Wed Nov 13 21:29:34 2013 -0500 linux/amd64


Please provide any additional information below.

I think what's going on here is that the testing package is recompiled into a
libtesting.a and the flags passed to gccgo when compiling the test binary mean that this
is found when gccgo is looking for the 'testing' package.
@mwhudson
Copy link
Contributor Author

Comment 1:

Ah.  It's that the .o file that gets put in libtesting.a is left lying around in the
wrong place.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Can you give more details about comment #1?
I don't understand.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 3:

Labels changed: added go1.3maybe.

@mwhudson
Copy link
Contributor Author

Comment 4:

I can try.  It's pretty confusing though.  I'll paste the output of "go test -compiler
gccgo -x mwhudson/testing" and explain what I think is going on at each step.  I'm not
trying to explain things to you, I'm trying to explain what _I_ think is going on so
that you can correct me if I'm wrong :-)
mwhudson@narsil:testing$ go test -compiler gccgo -x mwhudson/testing
WORK=/tmp/go-build342732787
#### 
mkdir -p $WORK/mwhudson/testing/_test/mwhudson/
### This is the main scratch directory for testing mwhudson/testing
mkdir -p $WORK/mwhudson/testing/_test/
### Where the source lives
cd /home/mwhudson/goplay2/src/mwhudson/testing
### mwhudson/testing has both "internal test files" i.e. a file _test that says "package
testing" and 
### "external test files" that say package testing_test, so it is necessary to rebuild a
version of the
### package for testing.
*** The problem here is that the intermediate testing.o is created directly in the main
scratch directory ***
gccgo -I $WORK -c -g -m64 -fgo-pkgpath=mwhudson/testing
-fgo-relative-import-path=_/home/mwhudson/goplay2/src/mwhudson/testing -o
$WORK/mwhudson/testing/_test/testing.o ./t.go ./t2_test.go
### Make the version of libtesting.a for the compilation of testing.test to link against
ar cru $WORK/mwhudson/testing/_test/mwhudson/libtesting.a
$WORK/mwhudson/testing/_test/testing.o
### Compile the code that will make up testing.test.
### This is the command that fails.  Because of the "-I $WORK/mwhudson/testing/_test"
when trying to resolve 
### the `import "testing"`, gccgo finds the testing.o file created above, and obviously
this does not define
### all of (or indeed any of) the things that the standard testing package provides.
gccgo -I $WORK/mwhudson/testing/_test -I $WORK -c -g -m64
-fgo-pkgpath=mwhudson/testing_test
-fgo-relative-import-path=_/home/mwhudson/goplay2/src/mwhudson/testing -o
$WORK/mwhudson/testing/_test/testing_test.o ./t_test.go
# mwhudson/testing_test
./t_test.go:3:11: error: reference to undefined identifier ‘testing.T’
 func f(t *stdtesting.T) {}
I don't completely understand why gccgo looks for a .o file when looking for a package,
but dumping intermediate objects directly into a directory that's passed as an -I option
just feels risky.  My fix at https://golang.org/cl/27650045/ puts the testing.o
file in a sub-directory of the scratch directory:
mkdir -p $WORK/mwhudson/testing/_test/_obj_test/
cd /home/mwhudson/goplay2/src/mwhudson/testing
gccgo -I $WORK -c -g -m64 -fgo-pkgpath=mwhudson/testing
-fgo-relative-import-path=_/home/mwhudson/goplay2/src/mwhudson/testing -o
$WORK/mwhudson/testing/_test/_obj_test/testing.o ./t.go ./t2_test.go
This is analogous to what "go build" does:
mwhudson@narsil:testing$ go build -x -compiler gccgo mwhudson/testing 
...
gccgo -I $WORK -c -g -m64 -fgo-pkgpath=mwhudson/testing
-fgo-relative-import-path=_/home/mwhudson/goplay2/src/mwhudson/testing -o
$WORK/mwhudson/testing/_obj/testing.o ./t.go
...
I hope this helps!

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 6:

Labels changed: added repo-main.

@rsc
Copy link
Contributor

rsc commented Jan 8, 2014

Comment 7:

This issue was closed by revision 7178c05.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants