diff options
| author | ruki <[email protected]> | 2020-03-02 22:42:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-03-02 10:17:44 +0800 |
| commit | f33ee9fc657023fc8875f919715342d7066519e5 (patch) | |
| tree | bd1b97f50601810d5b874269dd620f34259666c2 | |
| parent | 2b41fac5b92bc0e5e3c4a848dfd7d9a1435fd20f (diff) | |
improve parse_deps for gcc
| -rw-r--r-- | xmake/modules/core/project/depend.lua | 38 | ||||
| -rw-r--r-- | xmake/modules/private/tools/gcc/parse_deps.lua | 37 |
2 files changed, 46 insertions, 29 deletions
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua index 7c8fa2ca5..70c72b11e 100644 --- a/xmake/modules/core/project/depend.lua +++ b/xmake/modules/core/project/depend.lua @@ -18,13 +18,16 @@ -- @file depend.lua -- --- load depfiles for the given tool style, e.g. gcc, cl, .. -function _load_depfiles(dependinfo, style) +-- imports +import("private.tools.cl.parse_deps", {alias = "parse_deps_cl"}) +import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"}) - -- parse depfiles for gcc - local depfiles = dependinfo["depfiles_" .. style] +-- load depfiles for gcc +function _load_depfiles_gcc(dependinfo) + + local depfiles = dependinfo.depfiles_gcc if depfiles then - local depfiles = import("private.tools." .. style .. ".parse_deps", {anonymous = true})(depfiles) + depfiles = parse_deps_gcc(depfiles) if depfiles then if dependinfo.files then table.join2(dependinfo.files, depfiles) @@ -32,22 +35,39 @@ function _load_depfiles(dependinfo, style) dependinfo.files = depfiles end end - dependinfo["depfiles_" .. style] = nil + dependinfo.depfiles_gcc = nil + end +end + +-- load depfiles for cl +function _load_depfiles_cl(dependinfo) + + local depfiles = dependinfo.depfiles_cl + if depfiles then + depfiles = parse_deps_cl(depfiles) + if depfiles then + if dependinfo.files then + table.join2(dependinfo.files, depfiles) + else + dependinfo.files = depfiles + end + end + dependinfo.depfiles_cl = nil end end -- load dependent info from the given file (.d) function load(dependfile) - if os.isfile(dependfile) then + if os.isfile(dependfile) then -- may be the depend file has been incomplete when if the compilation process is abnormally interrupted local dependinfo = try { function() return io.load(dependfile) end } if dependinfo then -- attempt to load depfiles from the compilers if is_plat("windows") then - _load_depfiles(dependinfo, "cl") + _load_depfiles_cl(dependinfo) else - _load_depfiles(dependinfo, "gcc") + _load_depfiles_gcc(dependinfo) end return dependinfo end diff --git a/xmake/modules/private/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua index 4c672d599..049825e16 100644 --- a/xmake/modules/private/tools/gcc/parse_deps.lua +++ b/xmake/modules/private/tools/gcc/parse_deps.lua @@ -26,21 +26,18 @@ import("core.base.hashset") local space_placeholder = "\001" -- normailize path of a dependecy -function _normailize_dep(dep) - - -- check - dep = dep:trim() - if #dep == 0 then - return nil - end +function _normailize_dep(dep, projectdir) -- tranlate dep path - dep = path.relative(dep, project.directory()) - dep = path.absolute(dep, project.directory()) + 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(os.projectdir()) then - return path.relative(dep, project.directory()) + if dep:startswith(projectdir) then + return path.relative(dep, projectdir) end end @@ -59,16 +56,16 @@ end -- function main(depsdata) - -- parse results + -- we assume there is only one valid line local results = hashset.new() - for _, line in ipairs(depsdata:split("\n", {plain = true})) do - local p = line:find(':', 1, true) - if p then - line = line:sub(p + 1) - line = line:gsub("\\ ", space_placeholder) - for _, includefile in ipairs(line:split(' ', {plain = true})) do - includefile = includefile:gsub(space_placeholder, ' ') - includefile = _normailize_dep(includefile) + local projectdir = os.projectdir() + local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first + line = line:gsub("\\ ", space_placeholder) + for _, includefile in ipairs(line:split(' ', {plain = true})) do -- it will trim all internal spaces without `{strict = true}` + if not includefile:endswith(":") then -- ignore "xxx.o:" prefix + includefile = includefile:gsub(space_placeholder, ' ') + if #includefile > 0 then + includefile = _normailize_dep(includefile, projectdir) if includefile then results:insert(includefile) end |
