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: mod tidy doesn't look in GOPATH when converting a legacy GOPATH project #42441

Open
dwschulze opened this issue Nov 7, 2020 · 6 comments
Open

Comments

@dwschulze
Copy link

@dwschulze dwschulze commented Nov 7, 2020

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

$ go version
1.14

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
Ubuntu 19.10  
amd64

What did you do?

Migrating legacy GOPATH code to use modules. Following this blog post I run go mod init bitbucket.org/username/reponame.git/integration-project/golang/lctlk8s in the project root directory. Then I run go mod tidy it gives

$GOPATH/go.mod exists but should not

If I change to the src/ directory and create the go.mod and run go tidy it fails to find to code in the current project and GOPATH:

go mod tidy
bitbucket.org/username/reponame.git/integration-project/golang/lctlk8s/cmd/lctlk8s imports
internal/composerestclient: package internal/composerestclient is not in GOROOT (/home/dean/bin/go1.14.linux-amd64/go/src/internal/composerestclient)
bitbucket.org/username/reponame.git/integration-project/golang/lctlk8s/internal/composerestclient imports
pkg/lctlutil: package pkg/lctlutil is not in GOROOT (/home/dean/bin/go1.14.linux-amd64/go/src/pkg/lctlutil)

Is this a bug in go mod tidy for not looking in the GOPATH, or is the blog post just wrong about how to migrate a legacy GOPATH project?

Here's my tree under the project root:

└── src
├── cmd
│   └── lctlk8s
│   └── lctlk8s.go
├── internal
│   ├── composerestclient
│   │   ├── compose.rest.client.go
│   │   ├── json.strings.go
│   │   ├── rest.client.structs.go
│   │   └── version.go
└── pkg
├── lctlutil
│   ├── readascii.go
│   └── readconf.go

What did you expect to see?

What did you see instead?

@dwschulze
Copy link
Author

@dwschulze dwschulze commented Nov 7, 2020

The problem is that before you can run go mod tidy on the legacy project you have to add the module name to the import statements. That needs to be included in that blog post. Also the project used in the blog post has already been converted to modules so it doesn't illustrate anything.

@cagedmantis cagedmantis changed the title go mod tidy doesn't look in GOPATH when converting a legacy GOPATH project cmd/go: mod tidy doesn't look in GOPATH when converting a legacy GOPATH project Nov 10, 2020
@bcmills bcmills added the modules label Nov 10, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Nov 10, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Nov 10, 2020

@stevetraut is working on new tutorial content for modules.

(We should take this feedback into account in the tutorials.)

@stevetraut
Copy link

@stevetraut stevetraut commented Nov 10, 2020

I think the first place folks will look for information about what the command requires to run usefully is in the reference for go mod tidy. This behavior should be reflect in other module docs, but I don't think people will look there first because it's less immediate.

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 10, 2020

In this case, I think what we're missing is probably a tutorial on “converting a GOPATH project to use modules” when the existing GOPATH contains packages that are intended to go in different modules.

(Our existing blog post assumes that the whole GOPATH project is a single module, so it doesn't describe how to use replace directives to wire in other dependencies from outside of that module that can't — or can't yet — be fetched using go get.)

@stevetraut
Copy link

@stevetraut stevetraut commented Nov 10, 2020

Can we set aside the content delivery vehicle for a moment and focus on what users need to be successful? What bits of information does a user need to have in order to successfully migrate GOPATH code to modules?

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 12, 2020

In this particular case, the user needs to know that they should add replace directives in the go.mod file for their new module for for any existing dependencies that cannot be fetched using go get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.