Skip to content

Commit e4f2c2d

Browse files
committed
Fix version parsing
1 parent 206038a commit e4f2c2d

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

lua/cmake-tools/scanner.lua

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ function scanner.json_encode(obj, indent)
3838
end
3939

4040
function scanner.execute_command(cmd)
41-
local handle = io.popen(cmd .. "2>&1")
41+
local handle = io.popen(cmd .. " 2>&1")
4242
if handle == nil then
4343
return false, -1, ""
4444
end
4545
local result = handle:read("*a")
4646
if result == nil then
4747
result = ""
4848
end
49-
local success, _, exit_code = handle:close()
49+
local success, exit_type, exit_code = handle:close()
50+
-- io.popen's close() returns: true on success, or nil, "exit", code on failure
5051
if success == nil then
51-
success = false
52+
return false, exit_code or -1, result
5253
end
53-
return success, exit_code, result
54+
return true, 0, result
5455
end
5556

5657
function scanner.file_exists(path)
@@ -74,16 +75,18 @@ end
7475

7576
function scanner.get_gcc_version(gcc_path)
7677
local success, exit_code, output = scanner.execute_command('"' .. gcc_path .. '" --version')
77-
if not success or exit_code ~= 0 then
78+
if output == nil then
7879
return nil
7980
end
80-
local version_line = output:match("gcc version ([%d%.]+)")
81-
return version_line
81+
-- Try multiple patterns to match different gcc output formats
82+
local version = output:match("gcc%s+%(GCC%)%s+([%d%.]+)") -- "gcc (GCC) 15.2.1"
83+
or output:match("gcc version ([%d%.]+)") -- "gcc version 11.4.0"
84+
return version
8285
end
8386

8487
function scanner.get_clang_version(clang_path)
85-
local success, exit_code, output = scanner.execute_command('"' .. clang_path .. '" --version')
86-
if not success or exit_code ~= 0 then
88+
local success, exit_code, output = scanner.execute_command('"' .. clang_path .. '" --version ')
89+
if output == nil then
8790
return nil
8891
end
8992
local version_line = output:match("clang version ([%d%.]+)")
@@ -142,7 +145,7 @@ function scanner.scan_for_kits()
142145
local gxx_path = scanner.find_compiler_pair(dir, gcc_path)
143146
if gxx_path then
144147
local kit = {
145-
name = "GCC " .. (gcc_version or "unknown"),
148+
name = "GCC-" .. (gcc_version or "unknown"),
146149
compilers = {
147150
C = gcc_path,
148151
CXX = gxx_path,
@@ -158,7 +161,7 @@ function scanner.scan_for_kits()
158161
local clangxx_path = scanner.find_compiler_pair(dir, clang_path)
159162
if clangxx_path then
160163
local kit = {
161-
name = "Clang " .. (clang_version or "unknown"),
164+
name = "Clang-" .. (clang_version or "unknown"),
162165
compilers = {
163166
C = clang_path,
164167
CXX = clangxx_path,

0 commit comments

Comments
 (0)