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

Support Go 1.11 modules #218

Merged
merged 4 commits into from
Nov 16, 2018
Merged

Support Go 1.11 modules #218

merged 4 commits into from
Nov 16, 2018

Conversation

atombender
Copy link
Contributor

@atombender atombender commented Nov 13, 2018

This uses the new package golang.org/x/tools/go/packages instead of golang.org/x/tools/go/loader to load code, so that we can support checking packages that use Go modules with Go >= 1.11. This fixes #213.

This preserves a bunch of code that probably isn't needed anymore; go/packages supports the Go package pattern that go list uses (in fact, it appears to use go list internally), so all the file system walking could be removed in favour of just relying on that. The current code is inefficient, since doing packages.Load(&conf, "file=./mypkg/myfile.go") actually loads the entire package, and there's no need to then do packages.Load(&conf, "file=./mypkg/otherfile.go"), since it's already loaded.

There is one change here that I wasn't 100% sure about. The generator test cases have a test case for relative paths, something which I believe is moot with the new Go module system (and I'm not even sure if relative imports are officially supported in Go?). I have removed the test case in favour of using Go module imports instead of relative ones. Comments are welcome.

I added a go.mod file for good measure.

Note that this changes Mockery to require Go >= 1.9, as go/packages does not support earlier versions.

@evanphx evanphx merged commit 2be70d1 into vektra:master Nov 16, 2018
@evanphx
Copy link
Member

evanphx commented Nov 16, 2018

Thanks!

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

Successfully merging this pull request may close these issues.

Fails with import errors with modules on Go 1.11
2 participants