fix #1252 check LLGO_ROOT with pkg github.com/goplus/llgo/runtime
This commit is contained in:
4
internal/env/env.go
vendored
4
internal/env/env.go
vendored
@@ -97,12 +97,12 @@ func isLLGoRoot(root string) (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
// Check for go.mod
|
// Check for go.mod
|
||||||
data, err := os.ReadFile(filepath.Join(root, "go.mod"))
|
data, err := os.ReadFile(filepath.Join(root, LLGoRuntimePkgName, "go.mod"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
// Check module name
|
// Check module name
|
||||||
if !strings.Contains(string(data), "module "+LLGoCompilerPkg+"\n") {
|
if !strings.Contains(string(data), "module "+LLGoRuntimePkg+"\n") {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
return root, true
|
return root, true
|
||||||
|
|||||||
18
internal/env/env_test.go
vendored
18
internal/env/env_test.go
vendored
@@ -41,8 +41,10 @@ func TestLLGoRuntimeDir(t *testing.T) {
|
|||||||
defer os.Setenv("LLGO_ROOT", origLLGoRoot)
|
defer os.Setenv("LLGO_ROOT", origLLGoRoot)
|
||||||
|
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
goModContent := []byte("module github.com/goplus/llgo\n")
|
runtimeDir := filepath.Join(tmpDir, "runtime")
|
||||||
if err := os.WriteFile(filepath.Join(tmpDir, "go.mod"), goModContent, 0644); err != nil {
|
os.MkdirAll(runtimeDir, 0755)
|
||||||
|
goModContent := []byte("module github.com/goplus/llgo/runtime\n")
|
||||||
|
if err := os.WriteFile(filepath.Join(runtimeDir, "go.mod"), goModContent, 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +94,10 @@ func TestLLGoROOT(t *testing.T) {
|
|||||||
defer os.Setenv("LLGO_ROOT", origLLGoRoot)
|
defer os.Setenv("LLGO_ROOT", origLLGoRoot)
|
||||||
|
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
goModContent := []byte("module github.com/goplus/llgo\n")
|
runtimeDir := filepath.Join(tmpDir, "runtime")
|
||||||
if err := os.WriteFile(filepath.Join(tmpDir, "go.mod"), goModContent, 0644); err != nil {
|
os.MkdirAll(runtimeDir, 0755)
|
||||||
|
goModContent := []byte("module github.com/goplus/llgo/runtime\n")
|
||||||
|
if err := os.WriteFile(filepath.Join(runtimeDir, "go.mod"), goModContent, 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,8 +174,10 @@ func TestIsLLGoRoot(t *testing.T) {
|
|||||||
// Test with valid path and valid go.mod
|
// Test with valid path and valid go.mod
|
||||||
t.Run("valid path and go.mod", func(t *testing.T) {
|
t.Run("valid path and go.mod", func(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
goModContent := []byte("module github.com/goplus/llgo\n")
|
runtimeDir := filepath.Join(tmpDir, "runtime")
|
||||||
if err := os.WriteFile(filepath.Join(tmpDir, "go.mod"), goModContent, 0644); err != nil {
|
os.MkdirAll(runtimeDir, 0755)
|
||||||
|
goModContent := []byte("module github.com/goplus/llgo/runtime\n")
|
||||||
|
if err := os.WriteFile(filepath.Join(runtimeDir, "go.mod"), goModContent, 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user