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

x/vgo: cannot determine module path for source directory ... (outside GOPATH, no import comments) #25176

Closed
ilius opened this issue Apr 30, 2018 · 9 comments
Milestone

Comments

@ilius
Copy link

ilius commented Apr 30, 2018

What version of Go are you using (go version)?

go version go1.10.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/s/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/go"
GORACE=""
GOROOT="/usr/local/go1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build375970443=/tmp/go-build -gno-record-gcc-switches"

What did you do?

My GOPATH is /home/go, and my user has full access to it.
I created a directory named "test" in /home/go/src/bitbucket.org/saeedgnu/
Then cd to /home/go/src/bitbucket.org/saeedgnu/test/
And created a minimal "main.go" file in current directory:

package main

import "fmt"

func main() {
	fmt.Println("Hello")
}

Then created an empty file "go.mod" in current directory (touch go.mod)
And ran vgo build

What did you expect to see?

The package to be compiled (a binary file named "test" created in current directory)

What did you see instead?

I got this error:

vgo: cannot determine module path for source directory /home/go/src/bitbucket.org/saeedgnu/test (outside GOPATH, no import comments)

Note: Adding the import comment will fix the problem:

package main // import "bitbucket.org/saeedgnu/test"

But the bug is in the outside GOPATH part of error, while the current directory in inside GOPATH.

@gopherbot gopherbot added this to the vgo milestone Apr 30, 2018
@ALTree
Copy link
Member

ALTree commented Apr 30, 2018

Does adding a line like:

module "bitbucket.org/saeedgnu/test"

at the top of the go.mod file fix this?

@ilius
Copy link
Author

ilius commented Apr 30, 2018

@ALTree Yes that would fix the problem. Is this an expected behavior?

In some other repos this step was not needed. It's not mentioned in https://research.swtch.com/vgo-tour
Is there a more up to date documentation?

@ALTree
Copy link
Member

ALTree commented Apr 30, 2018

It's not mentioned in https://research.swtch.com/vgo-tour

The tour is meant to give an overview of how you'll use vgo, and I don't think the goal was to exhaustively document how vgo works. It explicitly says to create a folder outside gopath, and if you deviate from the given path your "tour experience" wont' be as smooth. Keep in mind that vgo will likely effectively deprecate GOPATH... so you're not supposed to create your vgo modules there.

@ilius
Copy link
Author

ilius commented Apr 30, 2018

What do you mean deprecate GOPATH?
I don't think most companies would be willing to move their Go projects into outside of GOPATH.
Since they usually use the Team Name as the owner/parent of our git repos, so all the packages (main and non-main) are sub-directories of a single directory associated to that team (if they are not in a single repo) inside GOPATH.
Also some main packages main contain sub-packages that are imported by another main package, so they all need to be inside GOPATH.

Your approach is only possible in a Mono Repo design, that overrides GOPATH inside that repo.

@ALTree
Copy link
Member

ALTree commented Apr 30, 2018

Ensuring a smooth transition from the current status is one of the top priorities for the vgo proposal.

Anyway we don't use the issue tracker for general discussion or asking questions about the language. The Github bug tracker is only used to track Go bugs.

Please see the Questions wiki page; it has a list of good places for asking questions.

@kardianos
Copy link
Contributor

Your GOPATH is probably not explicitly set. Maybe this code doesn't yet use default GOPATH when adding module path. Make sure you have updated vgo to latest.

@ilius
Copy link
Author

ilius commented May 2, 2018

@kardianos My GOPATH is set in ~/.bashrc, and echo $GOPATH in my test repo shows it.
And I'm using the latest (with go get -u golang.org/x/vgo)
Looks like I only have this problem in repos in "bitbucket.org" directory, but not "github.com".
Oh, and there is no .envrc in my test repo.

@gopherbot
Copy link

Change https://golang.org/cl/111264 mentions this issue: cmd/go/internal/vgo: do not shadow GOPATH dir var

@ilius
Copy link
Author

ilius commented May 15, 2018

I can confirm that the bug is fixed. Thank you :)

@golang golang locked and limited conversation to collaborators May 15, 2019
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

4 participants