From 37f0edd18cb9f2fc95a8dbea1fb165983cf03f39 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 29 Nov 2023 00:37:34 +0800 Subject: improve armlink output --- xmake/modules/core/tools/armlink.lua | 63 ++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/xmake/modules/core/tools/armlink.lua b/xmake/modules/core/tools/armlink.lua index fa8a1510f..939e8e24b 100644 --- a/xmake/modules/core/tools/armlink.lua +++ b/xmake/modules/core/tools/armlink.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.global") +import("core.project.policy") import("utils.progress") function init(self) @@ -64,7 +65,65 @@ end -- link the target file function link(self, objectfiles, targetkind, targetfile, flags) - os.mkdir(path.directory(targetfile)) - os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) + opt = opt or {} + try + { + function () + os.mkdir(path.directory(targetfile)) + local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) + os.runv(program, argv) + end, + catch + { + function (errors) + + -- parse and strip errors + local lines = errors and tostring(errors):split('\n', {plain = true}) or {} + if not option.get("verbose") then + + -- find the start line of error + local start = 0 + for index, line in ipairs(lines) do + if line:find("error:", 1, true) or line:find("错误:", 1, true) then + start = index + break + end + end + + -- get 16 lines of errors + if start > 0 then + lines = table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))) + end + end + + -- raise errors + local results = #lines > 0 and table.concat(lines, "\n") or "" + if not option.get("verbose") then + results = results .. "\n ${yellow}> in ${bright}" .. sourcefile + end + raise(results) + end + }, + finally + { + function (ok, outdata, errdata) + + -- show warnings? + if ok and errdata and #errdata > 0 and policy.build_warnings() then + local lines = errdata:split('\n', {plain = true}) + if #lines > 0 then + if not option.get("diagnosis") then + lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines)) + end + local warnings = table.concat(lines, "\n") + if progress.showing_without_scroll() then + print("") + end + cprint("${color.warning}%s", warnings) + end + end + end + } + } end -- cgit v1.3.1 From eb24a8f8dc6a9347b6af83d1edb7beece17d2956 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 29 Nov 2023 23:58:51 +0800 Subject: improve to print output for armlink --- xmake/modules/core/tools/armlink.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/armlink.lua b/xmake/modules/core/tools/armlink.lua index 939e8e24b..32b87ad35 100644 --- a/xmake/modules/core/tools/armlink.lua +++ b/xmake/modules/core/tools/armlink.lua @@ -71,7 +71,7 @@ function link(self, objectfiles, targetkind, targetfile, flags) function () os.mkdir(path.directory(targetfile)) local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) - os.runv(program, argv) + return os.iorunv(program, argv) end, catch { @@ -122,6 +122,11 @@ function link(self, objectfiles, targetkind, targetfile, flags) cprint("${color.warning}%s", warnings) end end + + -- show echo output? e.g. --map data + if ok and outdata and #outdata > 0 and option.get("diagnosis") then + print(outdata) + end end } } -- cgit v1.3.1 From 63b65a04eaf42b2bed81eefcc03fa519066e8896 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 29 Nov 2023 23:58:57 +0800 Subject: update comment --- xmake/modules/core/tools/armlink.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/modules/core/tools/armlink.lua b/xmake/modules/core/tools/armlink.lua index 32b87ad35..36bc48a58 100644 --- a/xmake/modules/core/tools/armlink.lua +++ b/xmake/modules/core/tools/armlink.lua @@ -124,6 +124,7 @@ function link(self, objectfiles, targetkind, targetfile, flags) end -- show echo output? e.g. --map data + -- @see https://github.com/xmake-io/xmake/issues/4420 if ok and outdata and #outdata > 0 and option.get("diagnosis") then print(outdata) end -- cgit v1.3.1