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: vgo run|build *.go fails for module versions >=2 where module is in GOPATH #26046

Closed
mwf opened this issue Jun 25, 2018 · 9 comments

Comments

Projects
None yet
4 participants
@mwf
Copy link

commented Jun 25, 2018

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

go version go1.10.1 darwin/amd64 vgo:2018-02-20.1

Latest vgo:

commit 0f3e556044ecbd8a0805d098e52a743a1d0e3566 (HEAD -> master, origin/master, origin/HEAD)
Author: Tim Cooper <tim.cooper@layeh.com>
Date:   Fri Jun 22 17:51:20 2018 -0300

    cmd/go/internal/modcmd: fix sorting

What did you do?

Please refer to https://github.com/mwf/goplay/tree/master/vgo/hello_world

I check a case when we've got a binary with major version v2.0.0 and there is no v2 subdirectory or branch, major version is listed in go.mod instead.
It should be OK for vgo if I'm not mistaken, because you didn't want to force all go users to use a single workflow with branches or subdirectories. So we assume master branch is our current stable version, tags correspond with major version set in module directive.

go.mod:

module github.com/mwf/goplay/vgo/hello_world/v2

main.go:

package main

import (
	"fmt"
)

const Version = "V2"

func main() {
	fmt.Println("Hello world!")
	fmt.Println("Version:", Version)
}

vgo run . or vgo build . work without errors.

What did you expect to see?

vgo run main.go should run without errors

What did you see instead?

$ vgo run main.go
build github.com/mwf/goplay/vgo/hello_world: cannot find module for path github.com/mwf/goplay/vgo/hello_world
@mwf

This comment has been minimized.

Copy link
Author

commented Jul 6, 2018

@bcmills @myitcv
Sorry for bothering guys, but have you looked at this issue?

I think it's rather important, because we usually use a command like go build main.go. Would be pity if it breaks in case of v2+ modules after the go1.11 release.

@myitcv

This comment has been minimized.

Copy link
Member

commented Jul 6, 2018

@mwf is this still an issue? I don't see any problems as of 6cd5a417451d8ee907692eded07ef1b6b53825b1:

cd `mktemp -d`
export GOPATH=$PWD
mkdir hello
cd hello
vgo mod -init -module example.com/hello/v2
cat <<EOD > main.go
package main

import (
        "fmt"
)

const Version = "V2"

func main() {
        fmt.Println("Hello world!")
        fmt.Println("Version:", Version)
}
EOD
vgo run main.go
vgo build
./v2

(note: the last step needing to be ./v2 is covered by #24667)

@mwf

This comment has been minimized.

Copy link
Author

commented Jul 6, 2018

@myitcv yeap, I checked it with the same version. And there is some crazy thing about it.

Compare this (failing):

cd `mktemp -d`
export GOPATH=$PWD
git clone https://github.com/mwf/goplay src/github.com/mwf/goplay
cd src/github.com/mwf/goplay/vgo/hello_world
vgo build main.go

Output: build github.com/mwf/goplay/vgo/hello_world: cannot find module for path github.com/mwf/goplay/vgo/hello_world

And this (OK):

cd `mktemp -d`
git clone https://github.com/mwf/goplay
vgo build main.go

It's weird, but it builds OK if outside of GOPATH and fails if inside.
And the problem is only with v2+ modules, v1 works well in both cases.

@myitcv myitcv changed the title x/vgo: `vgo build *.go` fails for module versions >=2 x/vgo: vgo run|build *.go fails for module versions >=2 where module is in GOPATH Jul 6, 2018

@myitcv

This comment has been minimized.

Copy link
Member

commented Jul 6, 2018

@mwf nicely tracked down. Here's a standalone repro:

cd `mktemp -d`
export GOPATH=$PWD
mkdir -p src/example.com/hello
cd src/example.com/hello
vgo mod -init -module example.com/hello/v2
cat <<EOD > main.go
package main

import (
        "fmt"
)

const Version = "V2"

func main() {
        fmt.Println("Hello world!")
        fmt.Println("Version:", Version)
}
EOD
vgo run main.go

gives

build example.com/hello: cannot find module for path example.com/hello

@myitcv myitcv added the NeedsFix label Jul 6, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2018

Reproduced, thanks for these great scripts @myitcv.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2018

Related: #25281. Both are about incorrectly guessing the import path of the current directory because it happens to be in GOPATH.

@rsc rsc modified the milestones: vgo, Go1.11 Jul 12, 2018

@rsc rsc added the modules label Jul 12, 2018

@rsc rsc changed the title x/vgo: vgo run|build *.go fails for module versions >=2 where module is in GOPATH cmd/go: vgo run|build *.go fails for module versions >=2 where module is in GOPATH Jul 12, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

commented Aug 11, 2018

This script works for me now (updated to use go instead of vgo).
Please reopen if you can still reproduce the problem some other way.

cd `mktemp -d`
export GOPATH=$PWD
mkdir -p src/example.com/hello
cd src/example.com/hello
go mod init example.com/hello/v2
cat <<EOD > main.go
package main

import (
        "fmt"
)

const Version = "V2"

func main() {
        fmt.Println("Hello world!")
        fmt.Println("Version:", Version)
}
EOD
go run main.go

@rsc rsc closed this Aug 11, 2018

@myitcv myitcv reopened this Aug 12, 2018

@myitcv

This comment has been minimized.

Copy link
Member

commented Aug 12, 2018

@rsc I think this issue remains.

The point I missed when I was when retesting a couple of days ago is that since this issue was opened we have introduced the concept of GO111MODULE.

A slight tweak to the above shows the issue remains:

export GO111MODULE=on
cd `mktemp -d`
export GOPATH=$PWD
mkdir -p src/example.com/hello
cd src/example.com/hello
go mod init example.com/hello/v2
cat <<EOD > main.go
package main

import (
        "fmt"
)

const Version = "V2"

func main() {
        fmt.Println("Hello world!")
        fmt.Println("Version:", Version)
}
EOD
go run main.go

gives

build example.com/hello: cannot find module for path example.com/hello
@gopherbot

This comment has been minimized.

Copy link

commented Aug 18, 2018

Change https://golang.org/cl/129798 mentions this issue: cmd/go: allow 'go run x.go' to use nearby internal imports in module mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.