Skip to content

mod vendor, require/replace, and local source code #27601

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

Closed
glenvan opened this issue Sep 10, 2018 · 2 comments
Closed

mod vendor, require/replace, and local source code #27601

glenvan opened this issue Sep 10, 2018 · 2 comments

Comments

@glenvan
Copy link

glenvan commented Sep 10, 2018

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

go1.11 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH=amd64
GOHOSTARCH=amd64
GOHOSTOS=windows

What did you do?

I have a local project outside of my GOPATH that consumes packages from another related local project, also outside of GOPATH.

/proj1/somepkg
/proj2/

proj2's go.mod redirects the package path: replace example.com/proj1 => ../proj1

This builds perfectly using go build - but if I want to do vendored builds, using go mod vendor copies contents of proj1/somepkg into proj2/vendor/example.com/proj1/somepkg/.

What did you expect to see?

Since proj1 and proj2 are both local code, and Go Modules are meant to facilitate local code outside of a GOPATH, I had hoped local code could be left in place - then go build -mod=vendor would use a combination of the go.mod require/replace specs to build with local code requirements and vendored external package requirements.

What did you see instead?

go build -mod=vendor seems to make the logical assumption that all imported external modules are under the vendor/ subdirectory. It seems to be a binary choice - either all vendored or all versioned modules.

This makes sense to me. I understand this design choice and the need for compatibility with dep. But for the sake of local code, it would be nice to have total control over where the vendored module requirements are found.

As a (failed) workaround I tried using go mod vendor to collect dependencies, removed my copied source, added a replace for all external dependencies with the vendored path in go.mod, and go build normally. However, Go Modules isn't happy:

go: parsing vendor\github.com\google\gops\go.mod: open <path>proj2\vendor\github.com\google\gops\go.mod: The system cannot find the file specified.
go: parsing vendor\github.com\globalsign\mgo\go.mod: open <path>proj2\vendor\github.com\globalsign\mgo\go.mod: The system cannot find the file specified.
go: error loading module requirements
@bcmills
Copy link
Contributor

bcmills commented Sep 10, 2018

for the sake of local code, it would be nice to have total control over where the vendored module requirements are found.

I don't think you'll ever have “total control” short of managing an ungainly number of replace directives, but I think your use-case is more or less #27542. It's not obvious to me whether the solution should build on the existing vendor support or not.

@bcmills
Copy link
Contributor

bcmills commented Sep 10, 2018

Closing as a dup of #27542.

@bcmills bcmills closed this as completed Sep 10, 2018
@golang golang locked and limited conversation to collaborators Sep 10, 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

3 participants