Compare commits
3
Commits
10bbc83992
...
a7ea9189f6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7ea9189f6 | ||
|
|
a3b3c9e3c9 | ||
|
|
5fed6bfd28 |
No files matched your search
@@ -37,6 +37,20 @@ function M.setup(_)
|
||||
cmd("HegoBuildConfig", function()
|
||||
H.build_from_config()
|
||||
end, {})
|
||||
cmd("HegoTerminal", function()
|
||||
H.terminal()
|
||||
end, {})
|
||||
cmd("HegoToolchain", function()
|
||||
H.toolchain_pick()
|
||||
end, {})
|
||||
cmd("HegoSDK", function()
|
||||
H.sdk_pick()
|
||||
end, {})
|
||||
|
||||
-- Con argumentos: :HegoTerminal v3.4.1
|
||||
vim.api.nvim_create_user_command("HegoTerminalAt", function(args)
|
||||
require("hego.toolchain").terminal(require("hego").options, args.args)
|
||||
end, { nargs = 1 })
|
||||
end
|
||||
|
||||
return M
|
||||
+4
-3
@@ -57,8 +57,10 @@ local CONFIRM = {
|
||||
.. "AP-Protect / readback protection.\n¿Seguir?",
|
||||
}
|
||||
|
||||
--- OJO: el primer token DEBE ser "west". `toolchain-manager launch`
|
||||
--- interpreta el primer argumento tras "--" como el comando a lanzar.
|
||||
local function argv(opts, sn, mode)
|
||||
local a = { "flash", "-d", opts.build_dir, "--dev-id", sn }
|
||||
local a = { "west", "flash", "-d", opts.build_dir, "--dev-id", sn }
|
||||
if MODES[mode].flag then
|
||||
table.insert(a, MODES[mode].flag)
|
||||
end
|
||||
@@ -113,7 +115,7 @@ function M.run(opts, mode)
|
||||
end
|
||||
|
||||
--- Plan B: recuperar la placa sin pasar por west ni por sysbuild.
|
||||
--- Útil si `west flash --recover` se atraganta con el multi-dominio.
|
||||
--- No va envuelto en el toolchain, es nrfutil a pelo.
|
||||
function M.device_recover(opts)
|
||||
local devs = M.devices()
|
||||
if #devs == 0 then
|
||||
@@ -130,7 +132,6 @@ function M.device_recover(opts)
|
||||
local exec = require("hego.exec")
|
||||
|
||||
local function go(sn)
|
||||
-- Ojo: esto NO va envuelto en el toolchain, es nrfutil a pelo.
|
||||
exec.run_async({ "nrfutil", "device", "recover", "--serial-number", sn }, {
|
||||
title = "hego://device-recover",
|
||||
cwd = vim.fn.getcwd(),
|
||||
|
||||
@@ -11,6 +11,7 @@ M.defaults = {
|
||||
sysbuild = true,
|
||||
overlays = {},
|
||||
extra_cmake = {},
|
||||
terminal_shell = "zsh",
|
||||
keys = {
|
||||
build = "<leader>nb",
|
||||
pristine = "<leader>np",
|
||||
@@ -23,6 +24,11 @@ M.defaults = {
|
||||
config = "<leader>nc",
|
||||
build_config = "<leader>nB",
|
||||
monitor = "<leader>nt",
|
||||
terminal = "<leader>nT",
|
||||
toolchain = "<leader>nl",
|
||||
toolchain_install = "<leader>ni",
|
||||
toolchain_search = "<leader>nN",
|
||||
sdk = "<leader>ns",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -74,6 +80,27 @@ function M.monitor()
|
||||
return require("hego.monitor").run(M.options)
|
||||
end
|
||||
|
||||
--- Terminal con el entorno NCS activo.
|
||||
function M.terminal(version)
|
||||
return require("hego.toolchain").terminal(M.options, version)
|
||||
end
|
||||
|
||||
function M.toolchain_pick()
|
||||
return require("hego.toolchain").pick(M.options)
|
||||
end
|
||||
|
||||
function M.toolchain_install()
|
||||
return require("hego.toolchain").install_prompt(M.options)
|
||||
end
|
||||
|
||||
function M.toolchain_search()
|
||||
return require("hego.toolchain").search_pick(M.options)
|
||||
end
|
||||
|
||||
function M.sdk_pick()
|
||||
return require("hego.sdk").pick(M.options)
|
||||
end
|
||||
|
||||
function M.edit_config()
|
||||
local Config = require("hego.config")
|
||||
|
||||
|
||||
@@ -37,6 +37,21 @@ function M.setup(opts)
|
||||
vim.keymap.set("n", k.monitor, function()
|
||||
H.monitor()
|
||||
end, { desc = "NCS: Monitor serie" })
|
||||
vim.keymap.set("n", k.terminal, function()
|
||||
H.terminal()
|
||||
end, { desc = "NCS: Terminal (entorno NCS)" })
|
||||
vim.keymap.set("n", k.toolchain, function()
|
||||
H.toolchain_pick()
|
||||
end, { desc = "NCS: Toolchains" })
|
||||
vim.keymap.set("n", k.toolchain_install, function()
|
||||
H.toolchain_install()
|
||||
end, { desc = "NCS: Instalar toolchain" })
|
||||
vim.keymap.set("n", k.toolchain_search, function()
|
||||
H.toolchain_search()
|
||||
end, { desc = "NCS: Buscar toolchains" })
|
||||
vim.keymap.set("n", k.sdk, function()
|
||||
H.sdk_pick()
|
||||
end, { desc = "NCS: SDK manager" })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,102 @@
|
||||
local M = {}
|
||||
|
||||
local function sdk(args, title)
|
||||
local exec = require("hego.exec")
|
||||
local cmd = vim.list_extend({ "nrfutil", "sdk-manager" }, args)
|
||||
return exec.run_async(cmd, {
|
||||
title = title or "hego://sdk-manager",
|
||||
cwd = vim.fn.getcwd(),
|
||||
})
|
||||
end
|
||||
|
||||
--- Salida de `sdk-manager list` (nrfutil 8.2.1):
|
||||
--- SDK Type SDK Version SDK Status Toolchain Status
|
||||
--- nrf v3.4.1 Not installed Installed
|
||||
function M.list()
|
||||
local out = vim.fn.system({ "nrfutil", "sdk-manager", "list" })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
local sdks = {}
|
||||
for _, line in ipairs(vim.split(out, "\n", { plain = true })) do
|
||||
local typ, version, status, tc =
|
||||
line:match("^(%S+)%s+(v[%d%.]+)%s+(Not installed|Installed)%s+(Not installed|Installed)%s*$")
|
||||
if typ and version then
|
||||
table.insert(sdks, {
|
||||
type = typ,
|
||||
version = version,
|
||||
installed = status == "Installed",
|
||||
toolchain = tc == "Installed",
|
||||
})
|
||||
end
|
||||
end
|
||||
return sdks
|
||||
end
|
||||
|
||||
function M.search()
|
||||
sdk({ "search" }, "hego://sdk-search")
|
||||
end
|
||||
|
||||
--- `install` toma la versión POSICIONAL (verificado: <VERSION>, con 'v').
|
||||
function M.install(version)
|
||||
version = version and vim.trim(version) or ""
|
||||
if version == "" then
|
||||
return
|
||||
end
|
||||
sdk({ "install", version }, "hego://sdk-install")
|
||||
end
|
||||
|
||||
function M.install_prompt(opts)
|
||||
vim.ui.input({
|
||||
prompt = "Versión de SDK a instalar (p.ej. v3.4.1): ",
|
||||
default = opts.ncs_version or "",
|
||||
}, function(input)
|
||||
if input and vim.trim(input) ~= "" then
|
||||
M.install(vim.trim(input))
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--- <leader>ns: picker con el estado real de SDKs y toolchains.
|
||||
function M.pick(opts)
|
||||
local sdks = M.list()
|
||||
|
||||
if #sdks == 0 then
|
||||
-- Sin parseo posible: cae al modo volcado.
|
||||
return sdk({ "list" }, "hego://sdk-list")
|
||||
end
|
||||
|
||||
vim.ui.select(sdks, {
|
||||
prompt = "SDK (fuente)",
|
||||
format_item = function(s)
|
||||
return string.format(
|
||||
"%s %-8s sdk:%-14s toolchain:%s",
|
||||
s.type,
|
||||
s.version,
|
||||
s.installed and "installed" or "not installed",
|
||||
s.toolchain and "installed" or "not installed"
|
||||
)
|
||||
end,
|
||||
}, function(choice)
|
||||
if not choice then
|
||||
return
|
||||
end
|
||||
|
||||
if choice.installed then
|
||||
vim.notify("[hego] SDK " .. choice.version .. " ya instalado", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
local ok = vim.fn.confirm(
|
||||
("Instalar el SDK %s (árbol de fuentes, ~15 GB).\n¿Seguir?"):format(choice.version),
|
||||
"&Sí\n&No",
|
||||
2
|
||||
)
|
||||
if ok == 1 then
|
||||
M.install(choice.version)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,60 @@
|
||||
local M = {}
|
||||
|
||||
-- Imágenes de sysbuild que no son la aplicación.
|
||||
local SKIP = {
|
||||
mcuboot = true,
|
||||
matter_factory_data = true,
|
||||
}
|
||||
|
||||
--- Directorio del image de la app (sysbuild), o build_dir si no hay sysbuild.
|
||||
function M.image_dir(opts)
|
||||
for _, p in ipairs(vim.fn.glob(opts.build_dir .. "/*/CMakeCache.txt", false, true)) do
|
||||
local dir = vim.fn.fnamemodify(p, ":h")
|
||||
local name = vim.fn.fnamemodify(dir, ":t")
|
||||
if not SKIP[name] then
|
||||
return dir
|
||||
end
|
||||
end
|
||||
if vim.fn.filereadable(opts.build_dir .. "/CMakeCache.txt") == 1 then
|
||||
return opts.build_dir
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Ejecuta un target de CMake del image de la app, en un terminal.
|
||||
function M.run(opts, target, title)
|
||||
local dir = M.image_dir(opts)
|
||||
if not dir then
|
||||
vim.notify("[hego] no hay build configurada; lanza un build primero", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local exec = require("hego.exec")
|
||||
local cmd = exec.ncs(opts, { "cmake", "--build", dir, "--target", target })
|
||||
|
||||
return exec.run_async(cmd, {
|
||||
title = title or ("hego://" .. target),
|
||||
cwd = vim.fn.getcwd(),
|
||||
env = exec.zephyr_env(opts),
|
||||
})
|
||||
end
|
||||
|
||||
--- Picker RAM/ROM para <leader>nm.
|
||||
function M.memory(opts)
|
||||
local items = {
|
||||
{ label = "RAM report", target = "ram_report" },
|
||||
{ label = "ROM report", target = "rom_report" },
|
||||
}
|
||||
vim.ui.select(items, {
|
||||
prompt = "Memory report",
|
||||
format_item = function(i)
|
||||
return i.label
|
||||
end,
|
||||
}, function(choice)
|
||||
if choice then
|
||||
M.run(opts, choice.target, "hego://" .. choice.target)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,186 @@
|
||||
local M = {}
|
||||
|
||||
--- Ejecuta nrfutil tal cual. La gestión de toolchains NO se envuelve en
|
||||
--- `toolchain-manager launch`: el manager se ejecuta a sí mismo.
|
||||
local function nrfutil(args, title)
|
||||
local exec = require("hego.exec")
|
||||
local cmd = vim.list_extend({ "nrfutil" }, args)
|
||||
return exec.run_async(cmd, {
|
||||
title = title or "hego://nrfutil",
|
||||
cwd = vim.fn.getcwd(),
|
||||
})
|
||||
end
|
||||
|
||||
M.nrfutil = nrfutil
|
||||
|
||||
--- Salida de `toolchain-manager list` (nrfutil 8.2.1):
|
||||
--- Version Toolchain
|
||||
--- v3.2.4 /home/unai/ncs/toolchains/2ac5840438
|
||||
--- v3.4.0 /home/unai/ncs/toolchains/fbf7391cab
|
||||
function M.list()
|
||||
local out = vim.fn.system({ "nrfutil", "toolchain-manager", "list" })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
local installed = {}
|
||||
for _, line in ipairs(vim.split(out, "\n", { plain = true })) do
|
||||
local version, dir = line:match("^%s*(v[%d%.]+)%s+(/%S+)")
|
||||
if version and dir then
|
||||
table.insert(installed, { version = version, dir = dir })
|
||||
end
|
||||
end
|
||||
return installed
|
||||
end
|
||||
|
||||
--- Salida de `toolchain-manager search` (nrfutil 8.2.1):
|
||||
--- Version Status
|
||||
--- v3.4.1 Not installed
|
||||
--- v3.4.0 Installed
|
||||
function M.search()
|
||||
local out = vim.fn.system({ "nrfutil", "toolchain-manager", "search" })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
local all = {}
|
||||
for _, line in ipairs(vim.split(out, "\n", { plain = true })) do
|
||||
local version, status = line:match("^%s*(v[%d%.]+)%s+(.+%S)%s*$")
|
||||
if version and status then
|
||||
table.insert(all, {
|
||||
version = version,
|
||||
installed = status:lower():find("^installed") ~= nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
return all
|
||||
end
|
||||
|
||||
--- Comando completo para abrir una shell con el entorno del toolchain.
|
||||
--- ZEPHYR_BASE se inyecta porque `toolchain-manager launch` NO lo exporta.
|
||||
--- Verificado en v3.4.0 Y en v3.4.1: solo expone ZEPHYR_SDK_INSTALL_DIR
|
||||
--- y ZEPHYR_TOOLCHAIN_VARIANT, nunca ZEPHYR_BASE.
|
||||
function M.env_command(opts, version)
|
||||
local cmd = { "env" }
|
||||
|
||||
if opts.ncs_root and version then
|
||||
local zephyr = opts.ncs_root .. "/" .. version .. "/zephyr"
|
||||
if vim.fn.isdirectory(zephyr) == 1 then
|
||||
table.insert(cmd, "ZEPHYR_BASE=" .. zephyr)
|
||||
end
|
||||
end
|
||||
|
||||
vim.list_extend(cmd, { "nrfutil", "toolchain-manager", "launch" })
|
||||
if version then
|
||||
vim.list_extend(cmd, { "--ncs-version", version })
|
||||
end
|
||||
vim.list_extend(cmd, { "--", opts.terminal_shell or "zsh" })
|
||||
return cmd
|
||||
end
|
||||
|
||||
function M.terminal(opts, version)
|
||||
version = version or opts.ncs_version
|
||||
local exec = require("hego.exec")
|
||||
return exec.run_async(M.env_command(opts, version), {
|
||||
title = "hego://terminal" .. (version and ("-" .. version) or ""),
|
||||
cwd = vim.fn.getcwd(),
|
||||
})
|
||||
end
|
||||
|
||||
--- Instala el toolchain de una versión.
|
||||
--- `keep_default` deja el toolchain por defecto como estaba (útil para
|
||||
--- instalar 3.4.1 sin pasar a usarlo todavía).
|
||||
function M.install(opts, version, keep_default)
|
||||
version = version or opts.ncs_version
|
||||
if not version or version == "" then
|
||||
vim.notify("[hego] no sé qué versión de toolchain instalar", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local args = { "toolchain-manager", "install", "--ncs-version", version }
|
||||
if keep_default then
|
||||
table.insert(args, "--keep-old-toolchain-selection")
|
||||
end
|
||||
nrfutil(args, "hego://toolchain-install")
|
||||
end
|
||||
|
||||
function M.install_prompt(opts)
|
||||
vim.ui.input({
|
||||
prompt = "Versión NCS para el toolchain (p.ej. v3.4.1): ",
|
||||
default = opts.ncs_version or "",
|
||||
}, function(input)
|
||||
input = input and vim.trim(input) or ""
|
||||
if input ~= "" then
|
||||
M.install(opts, input)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--- <leader>nN: picker de versiones disponibles; instala la elegida.
|
||||
function M.search_pick(opts)
|
||||
local all = M.search()
|
||||
if #all == 0 then
|
||||
vim.notify("[hego] no pude leer `toolchain-manager search`", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
vim.ui.select(all, {
|
||||
prompt = "Toolchain a instalar",
|
||||
format_item = function(t)
|
||||
return t.version .. (t.installed and " (instalado)" or "")
|
||||
end,
|
||||
}, function(choice)
|
||||
if not choice then
|
||||
return
|
||||
end
|
||||
if choice.installed then
|
||||
vim.notify("[hego] " .. choice.version .. " ya está instalado", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
M.install(opts, choice.version, true) -- no cambia el toolchain por defecto
|
||||
end)
|
||||
end
|
||||
|
||||
--- <leader>nl: picker de toolchains instalados -> elegir acción.
|
||||
function M.pick(opts)
|
||||
local installed = M.list()
|
||||
if #installed == 0 then
|
||||
vim.notify("[hego] ningún toolchain detectado", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
vim.ui.select(installed, {
|
||||
prompt = "Toolchain",
|
||||
format_item = function(t)
|
||||
return t.version .. " " .. t.dir
|
||||
end,
|
||||
}, function(choice)
|
||||
if not choice then
|
||||
return
|
||||
end
|
||||
|
||||
local actions = {
|
||||
{ label = "Terminal con este toolchain", act = "terminal" },
|
||||
{ label = "Build con este toolchain", act = "build" },
|
||||
}
|
||||
vim.ui.select(actions, {
|
||||
prompt = choice.version,
|
||||
format_item = function(a)
|
||||
return a.label
|
||||
end,
|
||||
}, function(a)
|
||||
if not a then
|
||||
return
|
||||
end
|
||||
if a.act == "terminal" then
|
||||
M.terminal(opts, choice.version)
|
||||
elseif a.act == "build" then
|
||||
-- Sobrescribe la versión solo para este build, sin tocar la config.
|
||||
local o = vim.tbl_deep_extend("force", opts, { ncs_version = choice.version })
|
||||
require("hego.west").build(o, false)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user