53 lines
1.1 KiB
Lua
53 lines
1.1 KiB
Lua
local M = {}
|
|
|
|
local function stat(p)
|
|
return vim.uv.fs_stat(p)
|
|
end
|
|
|
|
--- Versión NCS más reciente instalada (p.ej. "v3.4.0").
|
|
function M.ncs_version(root)
|
|
local out = {}
|
|
for _, d in ipairs(vim.fn.glob(root .. "/v*", false, true)) do
|
|
if stat(d .. "/zephyr") then
|
|
table.insert(out, vim.fn.fnamemodify(d, ":t"))
|
|
end
|
|
end
|
|
table.sort(out)
|
|
return out[#out]
|
|
end
|
|
|
|
--- Toolchain más reciente: { dir, gcc, mtime }.
|
|
function M.toolchain(root)
|
|
local out = {}
|
|
for _, d in ipairs(vim.fn.glob(root .. "/*", false, true)) do
|
|
local gcc = d .. "/opt/zephyr-sdk/gnu/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc"
|
|
local st = stat(gcc)
|
|
if st then
|
|
table.insert(out, { dir = d, gcc = gcc, mtime = st.mtime.sec })
|
|
end
|
|
end
|
|
table.sort(out, function(a, b)
|
|
return a.mtime > b.mtime
|
|
end)
|
|
return out[1]
|
|
end
|
|
|
|
--- Board desde el CMakeCache si ya existe build; si no, nil.
|
|
function M.board(build_dir)
|
|
local f = io.open(build_dir .. "/CMakeCache.txt", "r")
|
|
if not f then
|
|
return nil
|
|
end
|
|
for line in f:lines() do
|
|
local b = line:match("^BOARD:STRING=(.+)$")
|
|
if b then
|
|
f:close()
|
|
return b
|
|
end
|
|
end
|
|
f:close()
|
|
return nil
|
|
end
|
|
|
|
return M
|