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: compilation fails with replace with repository module #32389

Closed
av86743 opened this issue Jun 2, 2019 · 9 comments
Closed

cmd/go: compilation fails with replace with repository module #32389

av86743 opened this issue Jun 2, 2019 · 9 comments

Comments

@av86743
Copy link

@av86743 av86743 commented Jun 2, 2019

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

$ go version
go version go1.12.5 linux/amd64

Does this issue reproduce with the latest release?

Sure, why not?

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ubuntu/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build755825477=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ env GO111MODULE= go get github.com/av86743/go-b0rken 
go build github.com/av86743/go-b0rken: no non-test Go files in /home/ubuntu/go/src/github.com/av86743/go-b0rken
$ ( cd go/src/github.com/av86743/go-b0rken/ && env GO111MODULE=on go test . -run inner ) 
go: extracting github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965
go: extracting github.com/syndtr/goleveldb v1.0.0
# github.com/av86743/go-b0rken/inner
inner/inner.go:17:28: cannot use opt (type *"github.com/av86743/go-leveldb/leveldb/opt".Options) as type *"github.com/syndtr/goleveldb/leveldb/opt".Options in argument to leveldb.OpenFile
FAIL    github.com/av86743/go-b0rken [build failed]
$ 

What did you expect to see?

Compilation does not fail, at least. See 'inner/inner.go' for a variant with imports replaced manually, which compiles.

What did you see instead?

Oh, come on now. Repository 'github.com/av86743/go-leveldb' does not even exist. Are you sure you know what you are talking about?

@ALTree ALTree changed the title Compilation fails with replace for inner package cmd/go: compilation fails with replace for inner package Jun 3, 2019
@ALTree ALTree added this to the Go1.14 milestone Jun 3, 2019
@av86743

This comment has been minimized.

Copy link
Author

@av86743 av86743 commented Jun 3, 2019

Thanks for accepting!

@thepudds

This comment has been minimized.

Copy link

@thepudds thepudds commented Jun 3, 2019

@av86743 the first error reported here:

env GO111MODULE= go get github.com/av86743/go-b0rken
go build github.com/av86743/go-b0rken: no non-test Go files in /home/ubuntu/go/src/github.com/av86743/go-b0rken

might be an instance of #29268 (comment). Does that seem related to the first error you reported here?

Aside from that, can you expand a bit on what you are attempting to do here?

For example, you say:

Repository 'github.com/av86743/go-leveldb' does not even exist

Could you expand on why you are using a repository that does not exist? For example, is this a simplified example of something else you saw?

@av86743

This comment has been minimized.

Copy link
Author

@av86743 av86743 commented Jun 3, 2019

@thepudds

@av86743 the first error reported here:

env GO111MODULE= go get github.com/av86743/go-b0rken
go build github.com/av86743/go-b0rken: no non-test Go files in /home/ubuntu/go/src/github.com/av86743/go-b0rken

might be an instance of #29268 (comment). Does that seem related to the first error you reported here?

Irrelevant, disregard this. It is just statement of a fact, it's not even tagged as an error.

Aside from that, can you expand a bit on what you are attempting to do here?

I am giving you a straight example where go.mod "replace" directive does not work. And registering your response.

For example, you say:

Repository 'github.com/av86743/go-leveldb' does not even exist

This is to bring your attention to the fact that compiler's error message reports a type from repository which does not even exist. How much sense does it make to you?

Could you expand on why you are using a repository that does not exist? For example, is this a simplified example of something else you saw?

Whether that repository exists or not, is immaterial - in the presence of "replace" directive for this repository. Don't you agree?

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Jun 5, 2019

The replace directive replaces the source code for a module, not its import path (see #26904).

When you replace the package github.com/av86743/go-leveldb/leveldb, you end up loading the source code within github.com/syndtr/goleveldb/leveldb, and the files there import github.com/syndtr/goleveldb/leveldb/opt.

With the current semantics of replace, github.com/syndtr/goleveldb/leveldb/opt is a separate package from github.com/av86743/go-leveldb/leveldb/opt, even if they are built from source code in the same underlying repository. If github.com/syndtr/goleveldb is meant as a drop-in replacement for the source code of github.com/av86743/go-leveldb, then today it must use the original github.com/av86743/go-leveldb module and import paths.

We know that there is a use-case for replace to aid in un-forking modules that were previously forked, but we have not been able to address it yet. That's #26904 (and, to some extent, #30831).

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Jun 5, 2019

Duplicate of #26904

@bcmills bcmills marked this as a duplicate of #26904 Jun 5, 2019
@bcmills bcmills closed this Jun 5, 2019
@av86743

This comment has been minimized.

Copy link
Author

@av86743 av86743 commented Jun 5, 2019

@bcmills

The replace directive replaces the source code for a module, not its import path (see #26904).

When you replace the package github.com/av86743/go-leveldb/leveldb, you end up loading the source code within github.com/syndtr/goleveldb/leveldb, and the files there import github.com/syndtr/goleveldb/leveldb/opt.

With the current semantics of replace, github.com/syndtr/goleveldb/leveldb/opt is a separate package from github.com/av86743/go-leveldb/leveldb/opt, even if they are built from source code in the same underlying repository. If github.com/syndtr/goleveldb is meant as a drop-in replacement for the source code of github.com/av86743/go-leveldb, then today it must use the original github.com/av86743/go-leveldb module and import paths.

What do mean by saying "...it must use..." etc etc? github.com/syndtr/goleveldb is what it is. I have no control over its content.

@av86743 av86743 changed the title cmd/go: compilation fails with replace for inner package cmd/go: compilation fails with replace with repository module Jun 6, 2019
@av86743

This comment has been minimized.

Copy link
Author

@av86743 av86743 commented Jun 6, 2019

The replace directive replaces the source code for a module, not its import path (see #26904).

When you replace the package github.com/av86743/go-leveldb/leveldb, you end up loading the source code within github.com/syndtr/goleveldb/leveldb, and the files there import github.com/syndtr/goleveldb/leveldb/opt.

With the current semantics of replace, github.com/syndtr/goleveldb/leveldb/opt is a separate package from github.com/av86743/go-leveldb/leveldb/opt, even if they are built from source code in the same underlying repository. If github.com/syndtr/goleveldb is meant as a drop-in replacement for the source code of github.com/av86743/go-leveldb, then today it must use the original github.com/av86743/go-leveldb module and import paths.

We know that there is a use-case for replace to aid in un-forking modules that were previously forked, but we have not been able to address it yet. That's #26904 (and, to some extent, #30831).

You could simply say: "@rsc solved it in https://golang.org/cl/174939 ." Thanks, in any case.

Cox rocks. Which also rhymes. Niccce, whichever way you look at it.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Jun 6, 2019

Note that CL 174939 isn't merged (and won't be for 1.13). There are some remaining issues with replacement semantics that we need to work out (described in a comment on the CL), and I'm planning to make another run at it for 1.14.

@av86743

This comment has been minimized.

Copy link
Author

@av86743 av86743 commented Jun 6, 2019

I've backported that CL (plus related changesets) to go1.12.5. It looks all right so far, but I need more time to validate typical use cases, review 5 items from CL which you mentioned, and just cool down a bit before I publish the port.

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