gentests and cltest supports flags.txt (currently just -dbg used)

This commit is contained in:
Li Jie
2024-09-14 18:13:18 +08:00
parent d8838503b2
commit 8e3d76b7ea
2 changed files with 45 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ import (
"os"
"strings"
"github.com/goplus/llgo/cl"
"github.com/goplus/llgo/internal/llgen"
"github.com/goplus/llgo/ssa"
"github.com/goplus/mod"
@@ -41,6 +42,20 @@ func main() {
llgenDir(dir+"/cl/_testdata", "")
}
func isDbgSymEnabled(flagsFile string) bool {
data, err := os.ReadFile(flagsFile)
if err != nil {
return false
}
toks := strings.Split(strings.Join(strings.Split(string(data), "\n"), " "), " ")
for _, tok := range toks {
if tok == "-dbg" {
return true
}
}
return false
}
func llgenDir(dir string, pkgPath ...string) {
fis, err := os.ReadDir(dir)
check(err)
@@ -49,10 +64,17 @@ func llgenDir(dir string, pkgPath ...string) {
if !fi.IsDir() || strings.HasPrefix(name, "_") {
continue
}
testDir := dir + "/" + name
fmt.Fprintln(os.Stderr, "llgen", testDir)
os.Chdir(testDir)
llgen.SmartDoFile("in.go", pkgPath...)
func() {
testDir := dir + "/" + name
fmt.Fprintln(os.Stderr, "llgen", testDir)
os.Chdir(testDir)
dbg := isDbgSymEnabled("flags.txt")
if dbg {
cl.EnableDebugSymbols()
}
defer cl.DisableDebugSymbols()
llgen.SmartDoFile("in.go", pkgPath...)
}()
}
}