diff options
| author | ruki <[email protected]> | 2020-06-18 00:53:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-17 23:23:59 +0800 |
| commit | 44f12faeef61cfc28339b8dcbaf8b7ee0abfa054 (patch) | |
| tree | ff10edad74f955c9cc0a035bc74ac109332fcf53 | |
| parent | 0a9c848f7a31acd027dea5b4a5b91d60516eddea (diff) | |
support deps for rc
| -rw-r--r-- | xmake/core/base/colors.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/project/depend.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rc.lua | 40 | ||||
| -rw-r--r-- | xmake/modules/private/tools/rc/parse_deps.lua | 54 |
4 files changed, 73 insertions, 27 deletions
diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua index 4aa4dcc12..df78f6552 100644 --- a/xmake/core/base/colors.lua +++ b/xmake/core/base/colors.lua @@ -425,8 +425,6 @@ function colors.translate(str, opt) end return result end) - - -- ok return str end diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua index 20b63e7e6..9c1484943 100644 --- a/xmake/modules/core/project/depend.lua +++ b/xmake/modules/core/project/depend.lua @@ -20,6 +20,7 @@ -- imports import("private.tools.cl.parse_deps", {alias = "parse_deps_cl"}) +import("private.tools.rc.parse_deps", {alias = "parse_deps_rc"}) import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"}) -- load depfiles @@ -48,6 +49,9 @@ function load(dependfile) elseif dependinfo.depfiles_cl then _load_depfiles(parse_deps_cl, dependinfo, dependinfo.depfiles_cl) dependinfo.depfiles_cl = nil + elseif dependinfo.depfiles_rc then + _load_depfiles(parse_deps_rc, dependinfo, dependinfo.depfiles_rc) + dependinfo.depfiles_rc = nil end return dependinfo end diff --git a/xmake/modules/core/tools/rc.lua b/xmake/modules/core/tools/rc.lua index 12c94fa5f..cdaaa6b49 100644 --- a/xmake/modules/core/tools/rc.lua +++ b/xmake/modules/core/tools/rc.lua @@ -44,12 +44,12 @@ function nf_includedir(self, dir) end -- make the compile arguments list -function _compargv1(self, sourcefile, objectfile, flags) +function compargv(self, sourcefile, objectfile, flags) return self:program(), table.join(flags, "-Fo" .. objectfile, sourcefile) end -- compile the source file -function _compile1(self, sourcefile, objectfile, dependinfo, flags) +function compile(self, sourcefile, objectfile, dependinfo, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) @@ -59,7 +59,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) { function () -- @note we need not uses vstool.iorunv to enable unicode output for rc.exe - local outdata, errdata = os.iorunv(_compargv1(self, sourcefile, objectfile, flags)) + local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags)) return (outdata or "") .. (errdata or "") end, catch @@ -79,34 +79,24 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) finally { function (ok, warnings) - - -- print some warnings if warnings and #warnings > 0 and option.get("verbose") then cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) end end } } -end - --- make the compile arguments list -function compargv(self, sourcefiles, objectfile, flags) - - -- only support single source file now - assert(type(sourcefiles) ~= "table", "'object:sources' not support!") - -- for only single source file - return _compargv1(self, sourcefiles, objectfile, flags) + -- parse includes + local sourcedata = io.readfile(sourcefile) + if sourcedata then + local depfiles_rc + local sourcedir = path.directory(sourcefile) + for headerfile in sourcedata:gmatch("#include%s+[\"<](.-)[\">]") do + depfiles_rc = (depfiles_rc or "") .. "\n" .. path.join(sourcedir, headerfile) + end + if dependinfo then + dependinfo.depfiles_rc = depfiles_rc + end + end end --- compile the source file -function compile(self, sourcefiles, objectfile, dependinfo, flags) - - -- only support single source file now - assert(type(sourcefiles) ~= "table", "'object:sources' not support!") - - -- for only single source file - _compile1(self, sourcefiles, objectfile, dependinfo, flags) -end - - diff --git a/xmake/modules/private/tools/rc/parse_deps.lua b/xmake/modules/private/tools/rc/parse_deps.lua new file mode 100644 index 000000000..0b0ea2495 --- /dev/null +++ b/xmake/modules/private/tools/rc/parse_deps.lua @@ -0,0 +1,54 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file parse_deps.lua +-- + +-- imports +import("core.project.project") +import("core.base.hashset") + +-- normailize path of a dependecy +function _normailize_dep(dep, projectdir) + + -- tranlate dep path + if path.is_absolute(dep) then + dep = path.translate(dep) + else + dep = path.absolute(dep, projectdir) + end + + -- save it if belong to the project + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) + end +end + +-- parse depsfiles from string +function main(depsdata) + local results = hashset.new() + local projectdir = os.projectdir() + for _, includefile in ipairs(depsdata:split('\n', {plain = true})) do + if #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) + if includefile then + results:insert(includefile) + end + end + end + return results:to_array() +end |
