diff --git a/compiler/internal/env/env.go b/compiler/internal/env/env.go index 1088de59..09246f60 100644 --- a/compiler/internal/env/env.go +++ b/compiler/internal/env/env.go @@ -41,8 +41,12 @@ func LLGoRuntimeDir() string { } func LLGoROOT() string { - if root, ok := isLLGoRoot(os.Getenv("LLGO_ROOT")); ok { - return root + llgoRootEnv := os.Getenv("LLGO_ROOT") + if llgoRootEnv != "" { + if root, ok := isLLGoRoot(llgoRootEnv); ok { + return root + } + fmt.Fprintf(os.Stderr, "WARNING: LLGO_ROOT is not a valid LLGO root: %s\n", llgoRootEnv) } // Get executable path exe, err := os.Executable() diff --git a/compiler/internal/env/env_test.go b/compiler/internal/env/env_test.go index 0bb19cdb..823edeeb 100644 --- a/compiler/internal/env/env_test.go +++ b/compiler/internal/env/env_test.go @@ -58,10 +58,28 @@ func TestLLGoRuntimeDir(t *testing.T) { defer os.Setenv("LLGO_ROOT", origLLGoRoot) os.Setenv("LLGO_ROOT", "/nonexistent/path") - wd, _ := os.Getwd() - expected, _ := filepath.Abs(filepath.Join(wd, "../../../runtime")) - if got := LLGoRuntimeDir(); got != expected { - t.Errorf("LLGoRuntimeDir() = %v, want %v", got, expected) + wd, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + runtimeDir := filepath.Join(wd, "../../../runtime") + if got := LLGoRuntimeDir(); got != runtimeDir { + t.Errorf("LLGoRuntimeDir() = %v, want %v", got, runtimeDir) + } + }) + + t.Run("devel runtime dir", func(t *testing.T) { + origLLGoRoot := os.Getenv("LLGO_ROOT") + defer os.Setenv("LLGO_ROOT", origLLGoRoot) + + os.Setenv("LLGO_ROOT", "") + wd, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + runtimeDir := filepath.Join(wd, "../../../runtime") + if got := LLGoRuntimeDir(); got != runtimeDir { + t.Errorf("LLGoRuntimeDir() = %v, want %v", got, runtimeDir) } }) } @@ -92,8 +110,13 @@ func TestLLGoROOT(t *testing.T) { defer os.Setenv("LLGO_ROOT", origLLGoRoot) os.Setenv("LLGO_ROOT", "/nonexistent/path") - if got := LLGoROOT(); got != "" { - t.Errorf("LLGoROOT() = %v, want empty string", got) + wd, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + rootDir := filepath.Join(wd, "../../..") + if got := LLGoROOT(); got != rootDir { + t.Errorf("LLGoROOT() = %v, want %v", got, rootDir) } })