-
Notifications
You must be signed in to change notification settings - Fork 963
Fix //go:generate code generation to match go1.16 #1300
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
Conversation
Hey @uta-mori, |
@rotemtam |
Thanks for updating the issue @uta-mori. I've tried to reproduce your issue with ➜ go116 go mod init repro
go: creating new go.mod: module repro
➜ go116 go get entgo.io/ent/cmd/ent@latest
go get: added entgo.io/ent v0.6.0
➜ go116 go run entgo.io/ent/cmd/ent init User
➜ go116 go generate ./...
➜ go116 tree ./ent
./ent
├── client.go
├── config.go
├── context.go
├── ent.go
├── enttest
│ └── enttest.go
├── generate.go
├── hook
│ └── hook.go
├── migrate
│ ├── migrate.go
│ └── schema.go
├── mutation.go
├── predicate
│ └── predicate.go
├── runtime
│ └── runtime.go
├── runtime.go
├── schema
│ └── user.go
├── tx.go
├── user
│ ├── user.go
│ └── where.go
├── user.go
├── user_create.go
├── user_delete.go
├── user_query.go
└── user_update.go
7 directories, 22 files WDYT? |
Re-reading your issue description, I'm able to reproduce the issue, even without global installed binaries. Running This is related to the discussion in golang/go#43653. (cc @marwan-at-work ) To fix the issue, we can add this import to the import _ "entgo.io/ent/cmd/ent" This makes the package explicitly depend on the ent command line and its transitive dependencies, in which case @uta-mori , would you like to contribute a fix to change the generated code in this spirit? |
Thanks for your contribution @uta-mori 🙏 Any update on this? |
thank you added
|
@uta-mori @a8m why not instead of changing:
To
Which would only work in Go1.16 and fail for users who have not upgraded yet. Why don't we do this:
This would work for both 1.16 and previous Go versions and more importantly: it would ensure the version compatibility between the library |
@marwan-at-work |
You nailed it @marwan-at-work! Thanks for your help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful! Thanks for fixing this @uta-mori.
Starting with go1.16, the current generate.go statement will result in an error.
To make it behave the same as before, we need to change the description to the following.
Reproducing errors
Global installation of go1.16 style (not reflected in go.mod)
edit
ent/schema/user.go
Since go1.16, go.mod is not automatically updated, so you need to do
go mod tidy
more oftenWhen I try to generate the code, I get the following error:
Same result with
go generate ./...
Reference
Go 1.16 Release Notes: https://golang.org/doc/go1.16