-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat(orm): add query proto codegen #13438
Changes from all commits
ab112f9
08f697d
35c9811
0cbc766
be5c00b
acaa854
819a119
a33d0c3
e7ac662
50c1451
3029d26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
codegen: | ||
go install ./cmd/protoc-gen-go-cosmos-orm | ||
go install ./cmd/protoc-gen-go-cosmos-orm-proto | ||
# generate .proto files first | ||
(cd internal; buf generate --template buf.proto.gen.yaml) | ||
# generate go code | ||
(cd internal; buf generate) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"google.golang.org/protobuf/compiler/protogen" | ||
|
||
"github.com/cosmos/cosmos-sdk/orm/internal/codegen" | ||
) | ||
|
||
func main() { | ||
protogen.Options{}.Run(codegen.QueryProtoPluginRunner) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: v1 | ||
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: github.com/cosmos/cosmos-sdk/orm/internal | ||
override: | ||
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api | ||
plugins: | ||
- name: go-cosmos-orm-proto | ||
out: . | ||
opt: paths=source_relative |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ package codegen | |
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"google.golang.org/protobuf/compiler/protogen" | ||
"google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/types/pluginpb" | ||
|
||
ormv1 "cosmossdk.io/api/cosmos/orm/v1" | ||
"github.com/cosmos/cosmos-proto/generator" | ||
|
@@ -17,7 +19,8 @@ const ( | |
ormTablePkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/model/ormtable") | ||
) | ||
|
||
func PluginRunner(p *protogen.Plugin) error { | ||
func ORMPluginRunner(p *protogen.Plugin) error { | ||
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) | ||
for _, f := range p.Files { | ||
if !f.Generate { | ||
continue | ||
|
@@ -32,12 +35,42 @@ func PluginRunner(p *protogen.Plugin) error { | |
GeneratedFile: gen, | ||
LocalPackages: map[string]bool{}, | ||
} | ||
f := fileGen{GeneratedFile: cgen, file: f} | ||
err := f.gen() | ||
fgen := fileGen{GeneratedFile: cgen, file: f} | ||
err := fgen.gen() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func QueryProtoPluginRunner(p *protogen.Plugin) error { | ||
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) | ||
Check failure Code scanning / gosec Potential integer overflow by integer type conversion
Potential integer overflow by integer type conversion
|
||
for _, f := range p.Files { | ||
if !f.Generate { | ||
continue | ||
} | ||
|
||
if !hasTables(f) { | ||
continue | ||
} | ||
|
||
out, err := os.OpenFile(fmt.Sprintf("%s_query.proto", f.GeneratedFilenamePrefix), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0644) | ||
Check failure Code scanning / gosec Expect file permissions to be 0600 or less
Expect file permissions to be 0600 or less
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to say this seems rather strange... 0644 is pretty standard 🤔 |
||
if err != nil { | ||
return err | ||
} | ||
|
||
err = queryProtoGen{ | ||
File: f, | ||
svc: newWriter(), | ||
msgs: newWriter(), | ||
outFile: out, | ||
imports: map[string]bool{}, | ||
}.gen() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
|
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
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.
Umm.. the value of the const is
1
.gosec
should be able to statically inspectconst
values...