Skip to content

Commit 06d9ea8

Browse files
committed
Fix
1 parent c66c070 commit 06d9ea8

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error creating compiler: unknown engine: bad_engine
2+
3+
To use a custom database engine, add it to the 'engines' section of sqlc.yaml:
4+
5+
engines:
6+
- name: bad_engine
7+
process:
8+
cmd: sqlc-engine-bad_engine
9+
10+
Then install the plugin: go install github.com/example/sqlc-engine-bad_engine@latest

internal/ext/process/gen.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,30 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
7575
if r.Dir != "" {
7676
cmd.Dir = r.Dir
7777
}
78-
// Inherit the current environment (excluding SQLC_AUTH_TOKEN) and add SQLC_VERSION
79-
for _, env := range os.Environ() {
80-
if !strings.HasPrefix(env, "SQLC_AUTH_TOKEN=") {
81-
cmd.Env = append(cmd.Env, env)
78+
// Pass only SQLC_VERSION and explicitly configured environment variables
79+
cmd.Env = []string{
80+
fmt.Sprintf("SQLC_VERSION=%s", info.Version),
81+
}
82+
for _, key := range r.Env {
83+
if key == "SQLC_AUTH_TOKEN" {
84+
continue
85+
}
86+
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, os.Getenv(key)))
87+
}
88+
// For "go run" commands, inherit PATH and Go-related environment
89+
if len(cmdParts) > 1 && cmdParts[0] == "go" {
90+
for _, env := range os.Environ() {
91+
if strings.HasPrefix(env, "PATH=") ||
92+
strings.HasPrefix(env, "GOPATH=") ||
93+
strings.HasPrefix(env, "GOROOT=") ||
94+
strings.HasPrefix(env, "GOWORK=") ||
95+
strings.HasPrefix(env, "HOME=") ||
96+
strings.HasPrefix(env, "GOCACHE=") ||
97+
strings.HasPrefix(env, "GOMODCACHE=") {
98+
cmd.Env = append(cmd.Env, env)
99+
}
82100
}
83101
}
84-
cmd.Env = append(cmd.Env, fmt.Sprintf("SQLC_VERSION=%s", info.Version))
85102

86103
out, err := cmd.Output()
87104
if err != nil {

0 commit comments

Comments
 (0)