Skip to content

Commit cf74be9

Browse files
authored
codgen: Include serialized codegen options (#1890)
* codgen: Include serialized codegen options These options were already included, but not in a way that made them easy to use. We could also pass in a pointer to the existing setting document, but I think this is cleaner * Fix tests * Fix tests (again)
1 parent a5d4ed9 commit cf74be9

File tree

7 files changed

+87
-18
lines changed

7 files changed

+87
-18
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build-endtoend:
1717

1818
test-ci: test-examples build-endtoend
1919

20-
regen: sqlc-dev
20+
regen: sqlc-dev sqlc-gen-json
2121
go run ./scripts/regenerate/
2222

2323
sqlc-dev:
@@ -26,6 +26,9 @@ sqlc-dev:
2626
sqlc-pg-gen:
2727
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen
2828

29+
sqlc-gen-json:
30+
go build -o ~/bin/sqlc-gen-json ./cmd/sqlc-gen-json
31+
2932
start:
3033
docker-compose up -d
3134

internal/cmd/generate.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/kyleconroy/sqlc/internal/codegen/python"
1818
"github.com/kyleconroy/sqlc/internal/compiler"
1919
"github.com/kyleconroy/sqlc/internal/config"
20+
"github.com/kyleconroy/sqlc/internal/config/convert"
2021
"github.com/kyleconroy/sqlc/internal/debug"
2122
"github.com/kyleconroy/sqlc/internal/ext"
2223
"github.com/kyleconroy/sqlc/internal/ext/process"
@@ -295,6 +296,7 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
295296
if debug.Traced {
296297
region = trace.StartRegion(ctx, "codegen")
297298
}
299+
req := codeGenRequest(result, combo)
298300
var handler ext.Handler
299301
var out string
300302
switch {
@@ -335,10 +337,16 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
335337
return "", nil, fmt.Errorf("unsupported plugin type")
336338
}
337339

340+
opts, err := convert.YAMLtoJSON(sql.Plugin.Options)
341+
if err != nil {
342+
return "", nil, fmt.Errorf("invalid plugin options")
343+
}
344+
req.PluginOptions = opts
345+
338346
default:
339347
return "", nil, fmt.Errorf("missing language backend")
340348
}
341-
resp, err := handler.Generate(ctx, codeGenRequest(result, combo))
349+
resp, err := handler.Generate(ctx, req)
342350
if region != nil {
343351
region.End()
344352
}

internal/endtoend/testdata/codegen_json/gen/codegen.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49697,5 +49697,6 @@
4969749697
"insert_into_table": null
4969849698
}
4969949699
],
49700-
"sqlc_version": "v1.15.0"
49700+
"sqlc_version": "v1.15.0",
49701+
"plugin_options": ""
4970149702
}

internal/endtoend/testdata/process_plugin_sqlc_gen_json/gen/codegen.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49697,5 +49697,6 @@
4969749697
"insert_into_table": null
4969849698
}
4969949699
],
49700-
"sqlc_version": "v1.15.0"
49700+
"sqlc_version": "v1.15.0",
49701+
"plugin_options": "eyJmaWxlbmFtZSI6ImNvZGVnZW4uanNvbiIsImluZGVudCI6IiAgIn0="
4970149702
}

internal/plugin/codegen.pb.go

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/plugin/codegen_vtproto.pb.go

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/plugin/codegen.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ message CodeGenRequest
208208
Catalog catalog = 2 [json_name="catalog"];
209209
repeated Query queries = 3 [json_name="queries"];
210210
string sqlc_version = 4 [json_name="sqlc_version"];
211+
bytes plugin_options = 5 [json_name="plugin_options"];
211212
}
212213

213214
message CodeGenResponse

0 commit comments

Comments
 (0)