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

V3: Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' #2182

Merged
merged 12 commits into from
Jul 10, 2019

Conversation

ikawaha
Copy link
Contributor

@ikawaha ikawaha commented Jul 6, 2019

Fix issue #2181

@ikawaha ikawaha changed the title Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' V3: Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' Jul 6, 2019
@raphael
Copy link
Member

raphael commented Jul 7, 2019

Thank you for the great issue report and the PR! A couple of questions:

  1. Would it make sense to search for "go.mod" recursively going up the directories to support the case where a single Go module hosts multiple Goa projects, e.g.:
root
├── go.mod
├── project1
│   └── design
└── project2
    └── design

Here the goa command would be run within project1 and project2 and it would be nice if it could pickup the go.mod file under root like the go command does.

  1. Instead of adding a dependency on a third party package ("github.com/sirkon/goproxy/gomod") would it be better to just copy the modfile package from the Go source code: https://github.com/golang/go/tree/master/src/cmd/go/internal/modfile. It's unfortunate that it is an internal package but it seems better to copy and give proper attribution than to add a dependency on another package.

Thank you again, this is a great contribution!

@ikawaha
Copy link
Contributor Author

ikawaha commented Jul 7, 2019

Thank you for your comment !

  1. The location of go.mod to be used can be found by go env.
    (cf. https://dave.cheney.net/2013/06/14/you-dont-need-to-set-goroot-really)
$ echo $GOMOD

$ go env GOMOD
/Users/ikawaha/go/src/github.com/ikawaha/calc/go.mod

So, I fixed to use go env MOD instead of "go.mod".

  1. That's right.
    However, go/internal/modfile (It can not be used alone. I think there needs modfetch, modload etc) seems a bit complicated. I think that it is best to be porting go/internal, but how about using this package until then?

Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

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

Looks good, thanks

cmd/goa/gen.go Outdated
@@ -142,16 +142,34 @@ func (g *Generator) Write(debug bool) error {
return err
}

const GOMODENVKEY = "GOMOD"

func findGoMod() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this function can never return an error which is good so the error return value can be removed.

@raphael
Copy link
Member

raphael commented Jul 7, 2019

Thinking a bit more about parsing go.mod: we really don't need a full parser. All we need is to find the line that starts with goa.design/goa/v3 and capture what's after. Seems a little heuristic here might be better than bringing in all these dependencies. Thank you!

@ikawaha ikawaha changed the title V3: Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' [WIP]V3: Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' Jul 7, 2019
@ikawaha ikawaha force-pushed the fix/v3/go-mod-require branch from bcce715 to da4ef14 Compare July 7, 2019 10:44
@ikawaha
Copy link
Contributor Author

ikawaha commented Jul 7, 2019

I replaced the third party package with a heuristic parser.
Does it make sense?

@ikawaha ikawaha changed the title [WIP]V3: Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' V3: Fix to use the version of goa specified in go.mod file, when 'goa gen'/'goa example' Jul 7, 2019
@ikawaha
Copy link
Contributor Author

ikawaha commented Jul 7, 2019

It may be better to output the version of goa when go get. 🤔

@raphael
Copy link
Member

raphael commented Jul 8, 2019

The parser looks great! Thank you for making the change. I'm happy to merge the PR as is.

@ikawaha
Copy link
Contributor Author

ikawaha commented Jul 8, 2019

That's all.

go.mod Outdated
@@ -13,6 +13,7 @@ require (
github.com/manveru/gobdd v0.0.0-20131210092515-f1a17fdd710b // indirect
github.com/pkg/errors v0.8.1
github.com/sergi/go-diff v1.0.0
github.com/sirkon/goproxy v1.4.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops

@raphael
Copy link
Member

raphael commented Jul 10, 2019

I wonder if we need to print the version on the console? this may break scripts that wrap goa and capture its output.

@raphael
Copy link
Member

raphael commented Jul 10, 2019

Thank you!

@raphael raphael merged commit 59098d1 into goadesign:v3 Jul 10, 2019
@ikawaha
Copy link
Contributor Author

ikawaha commented Jul 10, 2019

What about displaying the version of goa modules by 'go get', when 'goa version' command run? If it looks good, I create another pull request.

@ikawaha ikawaha deleted the fix/v3/go-mod-require branch July 10, 2019 03:51
@raphael
Copy link
Member

raphael commented Jul 10, 2019

Not sure about goa version but it would probably be OK to show it when running with the --debug flag.

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.

2 participants