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

Add back support for go modules (fixes #155) #159

Merged
merged 7 commits into from
Jan 3, 2019

Conversation

coopernurse
Copy link
Contributor

This work was done by @domgreen (see: https://github.com/domgreen/errcheck)

I've only tested this with Go 1.11 so I'm not sure if older go versions will still work properly.

@coopernurse
Copy link
Contributor Author

Looks like CI hates it.. I don't have time to dig into it today but I'll try to look into it this week. If anyone sees something obvious let me know.

@bufdev
Copy link

bufdev commented Dec 26, 2018

I checked out the branch and installed the binary, and tested it against github.com/uber/prototool, checked out outside of my GOPATH, and this works, FYI.

@kisielk
Copy link
Owner

kisielk commented Dec 27, 2018

Thanks for the patch. I can merge it once the tests are fixed

@coopernurse
Copy link
Contributor Author

Sounds good - I'll see if I can figure out what's up with the tests tomorrow.

@coopernurse
Copy link
Contributor Author

Well, the good news is CI passes after I rebased. The bad news is that Go 1.11 modules don't seem to work anymore. Hmm.. Looking into it.

@coopernurse
Copy link
Contributor Author

Nevermind - I didn't have GO111MODULE=on set properly when I re-tested. I think we're good. @peter-edge would you mind double checking this branch against your repo and confirm? If so I'd say we could merge this.

@bufdev
Copy link

bufdev commented Dec 28, 2018

Just tested again against 4c22418 (last commit on the 155-go-modules branch), this works on github.com/uber/prototool.

loadcfg.ParserMode = parser.ParseComments
}
// loadPackages is used for testing.
var loadPackages = func(cfg *packages.Config, paths ...string) ([]*packages.Package, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just do var loadPackages = packages.Load since the function signature is the same? And if so, is this variable needed?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is replaced by a different function in the unit tests. The definition could probably be simplified down as you propose.

cfg := &packages.Config{
Mode: packages.LoadAllSyntax,
Tests: !c.WithoutTests,
BuildFlags: []string{fmt.Sprintf("-tags=%s", strings.Join(c.Tags, " "))},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually work with multiple tags? I feel like it would need to be quoted. Is this even needed anymore?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely should continue to support build tags, I don't know if this works or not as there are no tests for the functionality.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoting is for shells, not argv. This should work, but I didn't test the PR.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produces a single string though, not a set of strings (which would make sense to do)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BuildFlags is an array of arguments to pass to the go tool, in addition to the flags go/packages generates. Same semantics as os.Args, exec.Command or execve.

go list -tags="foo bar" becomes

([]string) (len=3 cap=3) {
 (string) (len=5) "go",
 (string) (len=4) "list",
 (string) (len=13) "-tags=foo bar"
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I get it now. Carry on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've put up a PR that adds tests for this at #160.

I applied the test to this PR (with the necessary modifications: see coopernurse#1) and verified that this seems to work as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fabulous. I merged your tests in and they're now included in this PR (which was rebased off master today).

@kisielk kisielk mentioned this pull request Dec 30, 2018
@bufdev
Copy link

bufdev commented Jan 3, 2019

Anything left to do here? :-) This still works from my testing.

@coopernurse
Copy link
Contributor Author

I think we're all set unless any maintainers / reviewers have additional thoughts. If not let's merge it!

@kisielk kisielk merged commit e14f8d5 into kisielk:master Jan 3, 2019
@kisielk
Copy link
Owner

kisielk commented Jan 3, 2019

Merged!

@kisielk
Copy link
Owner

kisielk commented Jan 3, 2019

Just wanted to add a thanks for everyone who had input and worked on this. Working on Go projects isn't my full-time job any more and my available hours for maintaining my open source packages are fairly limited (plus I was on vacation the last few weeks). I really appreciate the support of all the community members in helping out with this package.

@nmiyake
Copy link
Contributor

nmiyake commented Jan 3, 2019

@kisielk thanks for merging! Could we also get a tagged release for this? I don't believe this change broke anything (except possibly not working for some older versions of Go), so I think v1.2.0 should be good.

@kisielk
Copy link
Owner

kisielk commented Jan 3, 2019

I've tagged v1.2.0 now.

ghost pushed a commit to topgate/errcheck that referenced this pull request Mar 22, 2019
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.

6 participants