summaryrefslogtreecommitdiff
path: root/xmake/modules/core/tools/dmd.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-10 00:39:24 +0800
committerruki <[email protected]>2023-03-10 00:39:24 +0800
commit1124eff255f79d5774ea7ee72de745703817724b (patch)
tree725cf276948b03d5738aba6f8431aa24f1df47c5 /xmake/modules/core/tools/dmd.lua
parentd5147e92e4642e94e27ff38628b5ce5a7d45fcba (diff)
support makedeps for dlang #3455
Diffstat (limited to 'xmake/modules/core/tools/dmd.lua')
-rw-r--r--xmake/modules/core/tools/dmd.lua75
1 files changed, 72 insertions, 3 deletions
diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua
index 9e3001aeb..99e872390 100644
--- a/xmake/modules/core/tools/dmd.lua
+++ b/xmake/modules/core/tools/dmd.lua
@@ -182,8 +182,77 @@ function compargv(self, sourcefile, objectfile, flags)
end
-- compile the source file
-function compile(self, sourcefile, objectfile, dependinfo, flags)
+function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
+
+ -- ensure the object directory
os.mkdir(path.directory(objectfile))
- os.runv(compargv(self, sourcefile, objectfile, flags))
-end
+ -- compile it
+ opt = opt or {}
+ local depfile = dependinfo and os.tmpfile() or nil
+ try
+ {
+ function ()
+
+ -- generate includes file
+ local compflags = flags
+ if depfile then
+ compflags = table.join(compflags, "-makedeps=" .. depfile)
+ end
+
+ -- do compile
+ local program, argv = compargv(self, sourcefile, objectfile, compflags)
+ os.iorunv(program, argv, {envs = self:runenvs()})
+ end,
+ catch
+ {
+ function (errors)
+
+ -- try removing the old object file for forcing to rebuild this source file
+ os.tryrm(objectfile)
+
+ -- 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 compiling 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)
+
+ -- generate the dependent includes
+ if depfile and os.isfile(depfile) then
+ if dependinfo then
+ -- it use makefile/gcc compatiable format
+ dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"})
+ end
+
+ -- remove the temporary dependent file
+ os.tryrm(depfile)
+ end
+ end
+ }
+ }
+end