Skip to content

codgen: Include serialized codegen options #1890

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

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build-endtoend:

test-ci: test-examples build-endtoend

regen: sqlc-dev
regen: sqlc-dev sqlc-gen-json
go run ./scripts/regenerate/

sqlc-dev:
Expand All @@ -26,6 +26,9 @@ sqlc-dev:
sqlc-pg-gen:
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen

sqlc-gen-json:
go build -o ~/bin/sqlc-gen-json ./cmd/sqlc-gen-json

start:
docker-compose up -d

Expand Down
10 changes: 9 additions & 1 deletion internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kyleconroy/sqlc/internal/codegen/python"
"github.com/kyleconroy/sqlc/internal/compiler"
"github.com/kyleconroy/sqlc/internal/config"
"github.com/kyleconroy/sqlc/internal/config/convert"
"github.com/kyleconroy/sqlc/internal/debug"
"github.com/kyleconroy/sqlc/internal/ext"
"github.com/kyleconroy/sqlc/internal/ext/process"
Expand Down Expand Up @@ -295,6 +296,7 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
if debug.Traced {
region = trace.StartRegion(ctx, "codegen")
}
req := codeGenRequest(result, combo)
var handler ext.Handler
var out string
switch {
Expand Down Expand Up @@ -335,10 +337,16 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
return "", nil, fmt.Errorf("unsupported plugin type")
}

opts, err := convert.YAMLtoJSON(sql.Plugin.Options)
if err != nil {
return "", nil, fmt.Errorf("invalid plugin options")
}
req.PluginOptions = opts

default:
return "", nil, fmt.Errorf("missing language backend")
}
resp, err := handler.Generate(ctx, codeGenRequest(result, combo))
resp, err := handler.Generate(ctx, req)
if region != nil {
region.End()
}
Expand Down
3 changes: 2 additions & 1 deletion internal/endtoend/testdata/codegen_json/gen/codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -49697,5 +49697,6 @@
"insert_into_table": null
}
],
"sqlc_version": "v1.15.0"
"sqlc_version": "v1.15.0",
"plugin_options": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -49697,5 +49697,6 @@
"insert_into_table": null
}
],
"sqlc_version": "v1.15.0"
"sqlc_version": "v1.15.0",
"plugin_options": "eyJmaWxlbmFtZSI6ImNvZGVnZW4uanNvbiIsImluZGVudCI6IiAgIn0="
}
38 changes: 24 additions & 14 deletions internal/plugin/codegen.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions internal/plugin/codegen_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protos/plugin/codegen.proto
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ message CodeGenRequest
Catalog catalog = 2 [json_name="catalog"];
repeated Query queries = 3 [json_name="queries"];
string sqlc_version = 4 [json_name="sqlc_version"];
bytes plugin_options = 5 [json_name="plugin_options"];
}

message CodeGenResponse
Expand Down