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: can't build binary that depends on both v1 and v2 of the same library #24851

Closed
nicksnyder opened this issue Apr 13, 2018 · 5 comments

Comments

@nicksnyder
Copy link

commented Apr 13, 2018

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

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

Does this issue reproduce with the latest release?

Yes.

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

$ vgo env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nick/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nick/dev/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l6/djg_zw1j5lgbwz4h5q92lnwr0000gn/T/go-build082459775=/tmp/go-build -gno-record-gcc-switches -fno-common"
VGOMODROOT=""

What did you do?

$ git clone https://github.com/nicksnyder/app
$ cd app
$ vgo build

Or just create a main.go with this content and run vgo build main.go:

package main

import (
	"fmt"

	hola1 "github.com/nicksnyder/hola/hola"
	hola2 "github.com/nicksnyder/hola/v2/hola"
)

func main() {
	fmt.Println(hola1.Hola())
	fmt.Println(hola2.Hola2())
}

What did you expect to see?

I expect the build to succeed because github.com/nicksnyder/hola has a structure that mirrors what is documented in this diagram from https://research.swtch.com/vgo-module

What did you see instead?

$ vgo build
vgo: resolving import "github.com/nicksnyder/hola/hola"
vgo: finding github.com/nicksnyder/hola (latest)
vgo: adding github.com/nicksnyder/hola v1.0.0
vgo: import "github.com/nicksnyder/app" ->
	import "github.com/nicksnyder/hola/v2/hola" [/Users/nick/dev/gopath/src/v/github.com/nicksnyder/hola@v1.0.0/v2/hola]: open /Users/nick/dev/gopath/src/v/github.com/nicksnyder/hola@v1.0.0/v2/hola: no such file or directory

Attempted workarounds

I tried to manually pin hola to v2, but I get a different (unexpected) error then.

$ echo 'require "github.com/nicksnyder/hola/v2" v2.0.0' >> go.mod
$ vgo build
vgo: resolving import "github.com/nicksnyder/hola/hola"
vgo: finding github.com/nicksnyder/hola (latest)
vgo: adding github.com/nicksnyder/hola v1.0.0
vgo: import "github.com/nicksnyder/app" ->
	import "github.com/nicksnyder/hola/v2/hola": found in both github.com/nicksnyder/hola v1.0.0 and github.com/nicksnyder/hola/v2 v2.0.0

This is a possible duplicate of #24687 (comment) but I wanted to file a fresh set of reproduction steps.

@gopherbot gopherbot added this to the vgo milestone Apr 13, 2018

@jamie-digital

This comment has been minimized.

Copy link

commented May 18, 2018

What if you create a go.mod in github.com/nicksnyder/hola/hola/ with the module name "github.com/nicksnyder/hola/hola"?

@nicksnyder

This comment has been minimized.

Copy link
Author

commented May 22, 2018

@jamie-digital I forked hola to hola-fix and added the go.mod you suggested. Here is the new error:

$ vgo build
vgo: resolving import "github.com/nicksnyder/hola-fix/hola"
vgo: finding github.com/nicksnyder/hola-fix/hola (latest)
vgo: adding github.com/nicksnyder/hola-fix/hola v0.0.0-20180522053231-3689843ea837
vgo: resolving import "github.com/nicksnyder/hola-fix/v2/hola"
vgo: finding github.com/nicksnyder/hola-fix/v2 (latest)
vgo: adding github.com/nicksnyder/hola-fix/v2 v2.0.0
vgo: finding github.com/nicksnyder/hola-fix/v2 v2.0.0
vgo: finding github.com/nicksnyder/hola-fix/hola v0.0.0-20180522053231-3689843ea837
vgo: downloading github.com/nicksnyder/hola-fix/hola v0.0.0-20180522053231-3689843ea837
vgo: downloading github.com/nicksnyder/hola-fix/v2 v2.0.0
vgo: import "github.com/nicksnyder/app" ->
	import "github.com/nicksnyder/hola-fix/v2/hola": git archive --format=zip --prefix=prefix/ 25699644ca542507cbac1e183a62c0eb5fda51da -- /v2 in /Users/nick/dev/gopath/src/v/cache/vcswork/d3501c0618b68ea7154f87c4c973bd6a4f3657f3091dedd543da57086f790bf2: exit status 128:
	fatal: /v2: '/v2' is outside repository
@jamie-digital

This comment has been minimized.

Copy link

commented May 22, 2018

I looks like we're getting much closer. To be honest I'm finding the repo structure a bit hard to understand; the approach I've been using (with no issues) is when I reach v2 of a package I update the existing go.mod's module name to add v2, and I tag the repo with v2.x.y, rather than having both v1 and v2 in the repo at the same time. Note that if you have multiple modules in a single repo you just prefix the tag with the module name (so if you have a repo containing a module in dir foo, you tag versions of foo as foo/v1.2.3).

What happens if you tag v2 as v2/v2.0.0 to make it clearer that v2 is in the v2 directory?

@nicksnyder

This comment has been minimized.

Copy link
Author

commented May 22, 2018

rather than having both v1 and v2 in the repo at the same time

Russ explicitly documented that this structure should work. The reason this structure needs to work is to (1) support the transition to modules and (2) so clients of libraries can gradually upgrade a codebase.

As a library owner who currently has a v1 library and is releasing v2, I can neither remove nor move the v1 files because that would break backwards compatibility with the existing tooling.

What happens if you tag v2 as v2/v2.0.0 to make it clearer that v2 is in the v2 directory?

Same error (and this wouldn't have been an acceptable solution anyway because that tag isn't a proper semver).

$ vgo build .
vgo: resolving import "github.com/nicksnyder/hola-fix/hola"
vgo: finding github.com/nicksnyder/hola-fix/hola (latest)
vgo: adding github.com/nicksnyder/hola-fix/hola v0.0.0-20180522053231-3689843ea837
vgo: resolving import "github.com/nicksnyder/hola-fix/v2/hola"
vgo: finding github.com/nicksnyder/hola-fix/v2 (latest)
vgo: adding github.com/nicksnyder/hola-fix/v2 v2.0.0
vgo: downloading github.com/nicksnyder/hola-fix/v2 v2.0.0
vgo: import "github.com/nicksnyder/app" ->
	import "github.com/nicksnyder/hola-fix/v2/hola": git archive --format=zip --prefix=prefix/ 25699644ca542507cbac1e183a62c0eb5fda51da -- /v2 in /Users/nick/dev/gopath/src/v/cache/vcswork/d3501c0618b68ea7154f87c4c973bd6a4f3657f3091dedd543da57086f790bf2: exit status 128:
	fatal: /v2: '/v2' is outside repository

I think I have provided enough information here to reproduce the issue. I don't have any more unique knowledge at this point.

@gopherbot

This comment has been minimized.

Copy link

commented Jul 10, 2018

Change https://golang.org/cl/123095 mentions this issue: cmd/go/internal/modload: finish Import implementation

@golang golang locked and limited conversation to collaborators Jul 12, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.