diff options
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 86 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 35 | ||||
| -rw-r--r-- | xmake/modules/private/tools/gcc/parse_deps.lua | 79 | ||||
| -rw-r--r-- | xmake/modules/private/tools/nvcc/parse_deps.lua | 21 |
4 files changed, 145 insertions, 76 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 7e888090f..8396c1746 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -24,6 +24,7 @@ import("core.project.config") import("core.project.project") import("core.language.language") import("detect.tools.find_ccache") +import("private.tools.gcc.parse_deps") -- init it function init(self) @@ -327,60 +328,6 @@ function link(self, objectfiles, targetkind, targetfile, flags) os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) end --- get include deps --- --- strcpy.o: src/tbox/libc/string/strcpy.c src/tbox/libc/string/string.h \ --- src/tbox/libc/string/prefix.h src/tbox/libc/string/../prefix.h \ --- src/tbox/libc/string/../../prefix.h \ --- src/tbox/libc/string/../../prefix/prefix.h \ --- src/tbox/libc/string/../../prefix/config.h \ --- src/tbox/libc/string/../../prefix/../config.h \ --- build/iphoneos/x86_64/release/tbox.config.h \ --- -function _get_include_deps(outdata) - - -- translate it - local results = {} - local uniques = {} - local spacech = false - for _, line in ipairs(outdata:split("\n")) do - local p = line:find(':', 1, true) - if p then - line = line:sub(p + 1) - end - if line:endswith('\\') then - line = line:sub(1, -2) - end - line = line:trim() - spacech = false - if line:find(' ', 1, true) then - line = line:gsub("\\ ", "__spacechar__") - spacech = true - end - for _, includefile in ipairs(line:split("%s+")) do - if spacech then - includefile = includefile:gsub("__spacechar__", " ") - end - includefile = includefile:trim() - if #includefile > 0 then - - -- get the relative - includefile = path.relative(includefile, project.directory()) - - -- save it if belong to the project - if path.absolute(includefile):startswith(os.projectdir()) then - - -- insert it and filter repeat - if not uniques[includefile] then - table.insert(results, includefile) - uniques[includefile] = true - end - end - end - end - end - return results -end -- make the complie arguments list for the precompiled header function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags) @@ -496,11 +443,6 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) end end - -- remove the temporary dependent file - if depfile then - os.tryrm(depfile) - end - -- raise compiling errors raise(#lines > 0 and table.concat(lines, "\n") or "") end @@ -508,7 +450,6 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) finally { function (ok, outdata, errdata) - -- show warnings? if ok and errdata and #errdata > 0 and (option.get("diagnosis") or option.get("warning")) then local lines = errdata:split('\n') @@ -517,21 +458,22 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) cprint("${color.warning}%s", warnings) end end + + -- generate the dependent includes + if depfile and os.isfile(depfile) then + local depdata = io.readfile(depfile) + if dependinfo and self:kind() ~= "as" and depdata then + local files = dependinfo.files or {} + table.join2(files, parse_deps(depdata)) + dependinfo.files = table.unique(files) + end + + -- remove the temporary dependent file + os.tryrm(depfile) + end end } } - - -- generate the dependent includes - if depfile and os.isfile(depfile) then - local depdata = io.readfile(depfile) - if dependinfo and self:kind() ~= "as" and depdata then - dependinfo.files = dependinfo.files or {} - table.join2(dependinfo.files, _get_include_deps(depdata)) - end - - -- remove the temporary dependent file - os.tryrm(depfile) - end end -- make the complie arguments list diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 77cb4ce48..066e86cc9 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -24,6 +24,7 @@ import("core.project.config") import("core.project.project") import("core.language.language") import("detect.tools.find_ccache") +import("private.tools.nvcc.parse_deps") -- init it function init(self) @@ -58,7 +59,7 @@ function nf_symbol(self, level) -- the maps local maps = { - debug = "-g" + debug = "-g -G" } -- make it @@ -127,8 +128,8 @@ end function nf_optimize(self, level) -- the maps - local maps = - { + local maps = + { none = "-O0" , fast = "-O1" , faster = "-O2" @@ -138,7 +139,7 @@ function nf_optimize(self, level) } -- make it - return maps[level] + return maps[level] end -- make the language flag @@ -281,9 +282,22 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) os.mkdir(path.directory(objectfile)) -- compile it + local depfile = dependinfo and os.tmpfile() or nil try { function () + -- support `-M -MF depfile.d`? + if depfile and _g._HAS_M_MF == nil then + _g._HAS_M_MF = self:has_flags({"-M", "-MF", os.nuldev()}, "cuflags") or false + end + + -- generate includes file + if depfile and _g._HAS_M_MF then + local compflags = table.join(flags, "-M", "-MF", depfile) + -- since -MD is not supported, run nvcc twice + os.iorunv(_compargv1(self, sourcefile, objectfile, compflags)) + end + local outdata, errdata = os.iorunv(_compargv1(self, sourcefile, objectfile, flags)) return (outdata or "") .. (errdata or "") end, @@ -322,6 +336,19 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) if warnings and #warnings > 0 and (option.get("verbose") or option.get("warning")) then cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) end + + -- generate the dependent includes + if depfile and os.isfile(depfile) then + local depdata = io.readfile(depfile) + if dependinfo and self:kind() ~= "as" and depdata then + local files = dependinfo.files or {} + table.join2(files, parse_deps(depdata)) + dependinfo.files = table.unique(files) + end + + -- remove the temporary dependent file + os.tryrm(depfile) + end end } } diff --git a/xmake/modules/private/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua new file mode 100644 index 000000000..4e9b42140 --- /dev/null +++ b/xmake/modules/private/tools/gcc/parse_deps.lua @@ -0,0 +1,79 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.project") + +-- a placeholder for spaces in path +local space_placeholder = "\001" + +-- normailize path of a dependecy +function _normailize_dep(dep) + dep = dep:trim() + if #dep == 0 then + return nil + end + dep = path.relative(dep, project.directory()) + dep = path.absolute(dep, project.directory()) + -- save it if belong to the project + if dep:startswith(os.projectdir()) then + -- get the relative + dep = path.relative(dep, project.directory()) + return dep + end +end + +-- parse deps file (*.d) +-- +-- eg. +-- strcpy.o: src/tbox/libc/string/strcpy.c src/tbox/libc/string/string.h \ +-- src/tbox/libc/string/prefix.h src/tbox/libc/string/../prefix.h \ +-- src/tbox/libc/string/../../prefix.h \ +-- src/tbox/libc/string/../../prefix/prefix.h \ +-- src/tbox/libc/string/../../prefix/config.h \ +-- src/tbox/libc/string/../../prefix/../config.h \ +-- build/iphoneos/x86_64/release/tbox.config.h \ +-- +function main(depsdata) + if not depsdata or #depsdata == 0 then + return {} + end + + local results = {} + + -- translate it + local data = depsdata:gsub("\\\n", "") + + for _, line in ipairs(data:split("\n")) do + local p = line:find(':', 1, true) + if p ~= nil then + line = line:sub(p + 1) + line = line:gsub("\\ ", space_placeholder) + for _, includefile in ipairs(line:split("%s")) do + includefile = includefile:gsub(space_placeholder, " ") + includefile = _normailize_dep(includefile) + if includefile then + table.insert(results, includefile) + end + end + end + end + return table.unique(results) +end
\ No newline at end of file diff --git a/xmake/modules/private/tools/nvcc/parse_deps.lua b/xmake/modules/private/tools/nvcc/parse_deps.lua new file mode 100644 index 000000000..0f9c2504c --- /dev/null +++ b/xmake/modules/private/tools/nvcc/parse_deps.lua @@ -0,0 +1,21 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file parse_deps.lua +-- + +inherit("private.tools.gcc.parse_deps")
\ No newline at end of file |
