From 019595d58a02c639ee94250c0b4ad06d0f86ac0b Mon Sep 17 00:00:00 2001 From: Li Jie Date: Fri, 22 Nov 2024 09:50:47 +0800 Subject: [PATCH] fix build env and run env --- internal/env/env.go | 6 ++++-- internal/env/env_test.go | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/env/env.go b/internal/env/env.go index a0665b2..10f856f 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -105,6 +105,8 @@ func SetBuildEnv(projectPath string) { os.Setenv("GOPATH", GetGoPath(absPath)) os.Setenv("GOROOT", GetGoRoot(absPath)) os.Setenv("GOCACHE", GetGoCacheDir(absPath)) + os.Setenv("PKG_CONFIG_PATH", GetPythonPkgConfigDir(absPath)) + os.Setenv("CGO_ENABLED", "1") } func pathSeparator() string { @@ -114,13 +116,13 @@ func pathSeparator() string { return ":" } -// WriteEnvFile writes environment variables to .python/env.txt +// WriteEnvFile writes environment variables to .deps/env.txt func WriteEnvFile(projectPath, pythonHome, pythonPath string) error { // Prepare environment variables envVars := []string{ - fmt.Sprintf("PKG_CONFIG_PATH=%s", filepath.Join(pythonHome, "lib", "pkgconfig")), fmt.Sprintf("PYTHONPATH=%s", strings.TrimSpace(pythonPath)), fmt.Sprintf("PYTHONHOME=%s", pythonHome), + fmt.Sprintf("PATH=%s", GetPythonBinDir(projectPath)), } // Write to env.txt diff --git a/internal/env/env_test.go b/internal/env/env_test.go index 006fcb4..c89b87f 100644 --- a/internal/env/env_test.go +++ b/internal/env/env_test.go @@ -3,7 +3,6 @@ package env import ( "fmt" "os" - "path/filepath" "reflect" "runtime" "strings" @@ -106,7 +105,7 @@ func TestWriteEnvFile(t *testing.T) { // Verify the content contains expected environment variables envContent := string(content) expectedVars := []string{ - fmt.Sprintf("PKG_CONFIG_PATH=%s", filepath.Join(pythonDir, "lib", "pkgconfig")), + fmt.Sprintf("PATH=%s", GetPythonBinDir(projectDir)), fmt.Sprintf("PYTHONPATH=/mock/path1%s/mock/path2", pathSep), fmt.Sprintf("PYTHONHOME=%s", pythonDir), }