Skip to content

Commit

Permalink
llcppsymg:multiple dylib path search
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Oct 15, 2024
1 parent ac38b9c commit c73c199
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
22 changes: 13 additions & 9 deletions chore/_xtool/llcppsymg/_cmptest/symbol_test/llgo.expect
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#stdout
=== Test GenDylibPaths ===
=== Test ParseLibConfig ===
Test case: Lua library
Input: -L/opt/homebrew/lib -llua -lm
Output: [/opt/homebrew/lib/liblua.dylib /opt/homebrew/lib/libm.dylib]

Paths: [/opt/homebrew/lib]
Names: [lua m]
Test case: SQLite library
Input: -L/opt/homebrew/opt/sqlite/lib -lsqlite3
Output: [/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib]

Paths: [/opt/homebrew/opt/sqlite/lib]
Names: [sqlite3]
Test case: INIReader library
Input: -L/opt/homebrew/Cellar/inih/58/lib -lINIReader
Output: [/opt/homebrew/Cellar/inih/58/lib/libINIReader.dylib]

Paths: [/opt/homebrew/Cellar/inih/58/lib]
Names: [INIReader]
Test case: Multiple library paths
Input: -L/opt/homebrew/lib -L/usr/lib -llua
Paths: [/opt/homebrew/lib /usr/lib]
Names: [lua]
Test case: No valid library
Input: -L/opt/homebrew/lib
Error: failed to parse pkg-config output: -L/opt/homebrew/lib

Paths: [/opt/homebrew/lib]
Names: []
=== Test GetCommonSymbols ===

Test Case: Lua symbols
Expand Down
20 changes: 10 additions & 10 deletions chore/_xtool/llcppsymg/_cmptest/symbol_test/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
)

func main() {
TestGenDylibPaths()
TestParseLibConfig()
TestGetCommonSymbols()
TestReadExistingSymbolTable()
TestGenSymbolTableData()
}
func TestGenDylibPaths() {
fmt.Println("=== Test GenDylibPaths ===")
func TestParseLibConfig() {
fmt.Println("=== Test ParseLibConfig ===")

testCases := []struct {
name string
Expand All @@ -36,6 +36,10 @@ func TestGenDylibPaths() {
name: "INIReader library",
input: "-L/opt/homebrew/Cellar/inih/58/lib -lINIReader",
},
{
name: "Multiple library paths",
input: "-L/opt/homebrew/lib -L/usr/lib -llua",
},
{
name: "No valid library",
input: "-L/opt/homebrew/lib",
Expand All @@ -46,14 +50,10 @@ func TestGenDylibPaths() {
fmt.Printf("Test case: %s\n", tc.name)
fmt.Printf("Input: %s\n", tc.input)

result, err := symbol.GenDylibPaths(tc.input)
conf := symbol.ParseLibConfig(tc.input)

if err != nil {
fmt.Printf("Error: %v\n", err)
} else {
fmt.Printf("Output: %v\n", result)
}
fmt.Println()
fmt.Println("Paths:", conf.Paths)
fmt.Println("Names:", conf.Names)
}
}
func TestGetCommonSymbols() {
Expand Down
20 changes: 20 additions & 0 deletions chore/_xtool/llcppsymg/symbol/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ import (
"github.com/goplus/llgo/xtool/nm"
)

type LibConfig struct {
Paths []string
Names []string
}

func ParseLibConfig(lib string) *LibConfig {
parts := strings.Fields(lib)
config := &LibConfig{}

for _, part := range parts {
if strings.HasPrefix(part, "-L") {
config.Paths = append(config.Paths, part[2:])
} else if strings.HasPrefix(part, "-l") {
config.Names = append(config.Names, part[2:])
}
}

return config
}

func GenDylibPaths(lib string) ([]string, error) {
parts := strings.Fields(lib)
var libPath, libName string
Expand Down

0 comments on commit c73c199

Please sign in to comment.