local M = {} --- Config del formulario -> argumentos de `west build`. local function config_args(cfg) local a = {} if cfg.board then vim.list_extend(a, { "--board", cfg.board }) end if cfg.sysbuild == "yes" then table.insert(a, "--sysbuild") elseif cfg.sysbuild == "no" then table.insert(a, "--no-sysbuild") -- verificar nombre exacto en tu west end table.insert(a, "--") table.insert(a, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON") local function multi(flag, list) if list and #list > 0 then table.insert(a, flag .. "=" .. table.concat(list, ";")) end end multi("-DCONF_FILE", cfg.conf_files) multi("-DEXTRA_CONF_FILE", cfg.extra_conf_files) multi("-DDTC_OVERLAY_FILE", cfg.overlays) multi("-DEXTRA_DTC_OVERLAY_FILE", cfg.extra_overlays) multi("-DSNIPPET", cfg.snippets) if cfg.optimization == "size" then table.insert(a, "-DCONFIG_SIZE_OPTIMIZATIONS=y") elseif cfg.optimization == "speed" then table.insert(a, "-DCONFIG_SPEED_OPTIMIZATIONS=y") elseif cfg.optimization == "debug" then table.insert(a, "-DCONFIG_DEBUG_OPTIMIZATIONS=y") end if cfg.debug_thread_info then table.insert(a, "-DCONFIG_DEBUG_THREAD_INFO=y") end for _, e in ipairs(cfg.extra_cmake or {}) do table.insert(a, e) end return a end --- Config del spec del plugin (one-liner) -> config del formulario. local function from_opts(opts) return { board = opts.board, conf_files = opts.conf_file and { opts.conf_file } or {}, overlays = opts.overlays or {}, extra_cmake = opts.extra_cmake or {}, build_dir = opts.build_dir or "build", sysbuild = (opts.sysbuild == false) and "no" or "default", } end function M.build(opts, pristine, cfg) cfg = cfg or from_opts(opts) if cfg.generate_only then vim.notify("[hego] 'Generate only' todavía no está cableado (pendiente de verificar)", vim.log.levels.WARN) end local a = { "build", "-d", cfg.build_dir or opts.build_dir, vim.fn.getcwd(), } if pristine then table.insert(a, "--pristine") end vim.list_extend(a, config_args(cfg)) local exec = require("hego.exec") local cmd = exec.ncs(opts, vim.list_extend({ "west" }, a)) return exec.run_async(cmd, { title = "hego://build", cwd = vim.fn.getcwd(), env = exec.zephyr_env(opts), on_exit = function(obj) if obj.code == 0 then require("hego.lsp").link(cfg) end end, }) end return M