diff --git a/buildtools/xmake/main.lua b/buildtools/xmake/main.lua index 6b80a98..7cd7d2b 100644 --- a/buildtools/xmake/main.lua +++ b/buildtools/xmake/main.lua @@ -1,9 +1,7 @@ import("core.base.json") import("core.base.option") - -local function xmake_program() - return os.programfile() or "xmake" -end +import("core.project.project") +import("core.project.config") local function get_d2x_lang() local d2x_json_file = path.join(os.projectdir(), ".d2x.json") @@ -14,61 +12,32 @@ local function get_d2x_lang() return nil end -local function apply_project_config() +function list() + + config.load() local lang = get_d2x_lang() if lang and #lang > 0 then - os.execv(xmake_program(), {"f", "--lang=" .. lang}) + config.set("lang", lang, {force = true}) end -end -local function print_target_files(name) - local target_output = try {function () - return os.iorunv(xmake_program(), {"show", "-t", name, "--json"}) - end} - if not target_output or #target_output == 0 then - return - end - local target_info = try {function () - return json.decode(target_output) - end} - local flag = true + local targets = project.targets() + for name, _ in pairs(targets) do + local files = targets[name]:sourcefiles() + local flag = true - printf(name) - local files = (target_info and target_info.files) or {} - for _, fileinfo in ipairs(files) do - local file = fileinfo.path or fileinfo - file = path.absolute(file) - if flag then - printf("@ " .. file) - flag = false - else - printf(", " .. file) + -- cprintf / print xxx + printf(name) -- target name + for _, file in ipairs(files) do + file = path.absolute(file) + if flag then + --printf(": " .. file) -- avoid C:\ issue on Windows + printf("@ " .. file) + flag = false + else + printf(", " .. file) + end end - end - printf("\n") -end - -function list(target) - if target and #target > 0 then - print_target_files(target) - return - end - - -- if target is nil, list all targets - local target_names_output = try {function () - return os.iorunv(xmake_program(), {"show", "-l", "targets", "--json"}) - end} - if not target_names_output or #target_names_output == 0 then - return - end - local target_names = try {function () - return json.decode(target_names_output) - end} - if not target_names or #target_names == 0 then - return - end - for _, name in ipairs(target_names) do - print_target_files(name) + printf("\n") end end @@ -81,13 +50,16 @@ function main() --print("project file: " .. project.rootfile()) if command == "init" then - apply_project_config() + local lang = get_d2x_lang() + if lang and #lang > 0 then + os.exec("xmake f --lang=" .. lang) + end elseif command == "list" then - list(target) + list() elseif command == "build" then - os.execv(xmake_program(), {"build", target or ""}) + os.exec("xmake build " .. (target or "")) elseif command == "run" then - os.execv(xmake_program(), {"run", target or ""}) + os.exec("xmake run " .. (target or "")) else print("Unknown command: " .. tostring(command)) end