diff --git a/lua/hego/targets.lua b/lua/hego/targets.lua new file mode 100644 index 0000000..1a1e2fa --- /dev/null +++ b/lua/hego/targets.lua @@ -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 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