summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-01 17:23:46 +0800
committerruki <[email protected]>2020-03-01 17:23:46 +0800
commita9bba11b49235dac9982cc2f632b65339cd17130 (patch)
tree8cfda00774b823519e750f03c1556265083a7641
parent99461db2fae34632c83417667c8955c3361e7751 (diff)
improve to save depfiles for cl
-rw-r--r--xmake/modules/core/project/depend.lua37
-rw-r--r--xmake/modules/core/tools/cl.lua72
-rw-r--r--xmake/modules/core/tools/nvcc.lua1
-rw-r--r--xmake/modules/private/tools/cl/parse_deps.lua52
-rw-r--r--xmake/modules/private/tools/cl/parse_include.lua59
-rw-r--r--xmake/modules/private/tools/gcc/parse_deps.lua33
-rw-r--r--xmake/modules/private/tools/nvcc/parse_deps.lua21
7 files changed, 147 insertions, 128 deletions
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
index aaa2c13a7..7c8fa2ca5 100644
--- a/xmake/modules/core/project/depend.lua
+++ b/xmake/modules/core/project/depend.lua
@@ -18,8 +18,23 @@
-- @file depend.lua
--
--- imports
-import("private.tools.gcc.parse_deps")
+-- load depfiles for the given tool style, e.g. gcc, cl, ..
+function _load_depfiles(dependinfo, style)
+
+ -- parse depfiles for gcc
+ local depfiles = dependinfo["depfiles_" .. style]
+ if depfiles then
+ local depfiles = import("private.tools." .. style .. ".parse_deps", {anonymous = true})(depfiles)
+ if depfiles then
+ if dependinfo.files then
+ table.join2(dependinfo.files, depfiles)
+ else
+ dependinfo.files = depfiles
+ end
+ end
+ dependinfo["depfiles_" .. style] = nil
+ end
+end
-- load dependent info from the given file (.d)
function load(dependfile)
@@ -28,19 +43,11 @@ function load(dependfile)
-- 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
-
- -- parse depfiles for gcc
- local depfiles_gcc = dependinfo.depfiles_gcc
- if depfiles_gcc then
- local depfiles = parse_deps.from_str(depfiles_gcc)
- if depfiles then
- if dependinfo.files then
- table.join2(dependinfo.files, depfiles)
- else
- dependinfo.files = depfiles
- end
- end
- dependinfo.depfiles_gcc = nil
+ -- attempt to load depfiles from the compilers
+ if is_plat("windows") then
+ _load_depfiles(dependinfo, "cl")
+ else
+ _load_depfiles(dependinfo, "gcc")
end
return dependinfo
end
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index eddfe0260..9ff2ffce3 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.project.project")
import("core.language.language")
import("private.tools.vstool")
+import("private.tools.cl.parse_include")
-- init it
function init(self)
@@ -290,72 +291,6 @@ function add_sourceflags(self, sourcefile, fileconfig, target, targetkind)
end
end
--- contain: "Note: including file: "?
---
--- @note we cannot get better solution to distinguish between `includes` and `error infos`
---
-function _include_note(self, line)
-
- -- init notes
- --
- -- TODO zh-tw, zh-hk, jp, ...
- --
- _g.notes = _g.notes or
- {
- "Note: including file: "
- , "注意: 包含文件: "
- }
-
- -- contain notes?
- for idx, note in ipairs(_g.notes) do
-
- -- dump line bytes
- --[[
- print(line)
- line:gsub(".", function (ch) print(string.byte(ch)) end)
- --]]
-
- if line:startswith(note) then
- -- optimization: move this note to head
- if idx ~= 1 then
- table.insert(_g.notes, 1, note)
- end
- return line:sub(#note):trim()
- end
- end
-end
-
--- get include deps
-function _include_deps(self, outdata)
-
- -- translate it
- local results = {}
- local uniques = {}
- for _, line in ipairs(outdata:split("\n", {plain = true})) do
-
- -- get includefile
- local includefile = _include_note(self, line:trim())
- if includefile then
-
- -- get the relative
- includefile = path.relative(includefile, project.directory())
- includefile = path.absolute(includefile)
-
- -- save it if belong to the project
- if includefile:startswith(os.projectdir()) then
-
- -- insert it and filter repeat
- includefile = path.relative(includefile, project.directory())
- if not uniques[includefile] then
- table.insert(results, includefile)
- uniques[includefile] = true
- end
- end
- end
- end
- return results
-end
-
-- make the compile arguments list for the precompiled header
function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags)
@@ -434,7 +369,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags)
local results = ""
for _, line in ipairs(tostring(errors):split("\n", {plain = true})) do
line = line:rtrim()
- if not _include_note(self, line) then
+ if not parse_include(line) then
results = results .. line .. "\r\n"
end
end
@@ -471,8 +406,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags)
-- generate the dependent includes
if dependinfo and outdata then
- dependinfo.files = dependinfo.files or {}
- table.join2(dependinfo.files, _include_deps(self, outdata))
+ dependinfo.depfiles_cl = outdata
end
end
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index 304075b0b..be951c2a9 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -25,7 +25,6 @@ import("core.project.project")
import("core.platform.platform")
import("core.language.language")
import("private.tools.ccache")
-import("private.tools.nvcc.parse_deps")
-- init it
function init(self)
diff --git a/xmake/modules/private/tools/cl/parse_deps.lua b/xmake/modules/private/tools/cl/parse_deps.lua
new file mode 100644
index 000000000..79c80e4b7
--- /dev/null
+++ b/xmake/modules/private/tools/cl/parse_deps.lua
@@ -0,0 +1,52 @@
+--!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")
+import("parse_include")
+
+-- parse depsfiles from string
+function main(depsdata)
+
+ -- translate it
+ local results = hashset.new()
+ for _, line in ipairs(depsdata:split("\n", {plain = true})) do
+
+ -- get includefile
+ local includefile = parse_include(line:trim())
+ if includefile then
+
+ -- get the relative
+ includefile = path.relative(includefile, project.directory())
+ includefile = path.absolute(includefile)
+
+ -- save it if belong to the project
+ if includefile:startswith(os.projectdir()) then
+
+ -- insert it and filter repeat
+ includefile = path.relative(includefile, project.directory())
+ results:insert(includefile)
+ end
+ end
+ end
+ return results:to_array()
+end
+
diff --git a/xmake/modules/private/tools/cl/parse_include.lua b/xmake/modules/private/tools/cl/parse_include.lua
new file mode 100644
index 000000000..373aa0fdf
--- /dev/null
+++ b/xmake/modules/private/tools/cl/parse_include.lua
@@ -0,0 +1,59 @@
+--!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_include.lua
+--
+
+-- imports
+import("core.project.project")
+import("core.base.hashset")
+
+-- contain: "Note: including file: "?
+--
+-- @note we cannot get better solution to distinguish between `includes` and `error infos`
+--
+function main(line)
+
+ -- init notes
+ --
+ -- TODO zh-tw, zh-hk, jp, ...
+ --
+ _g.notes = _g.notes or
+ {
+ "Note: including file: "
+ , "注意: 包含文件: "
+ }
+
+ -- contain notes?
+ for idx, note in ipairs(_g.notes) do
+
+ -- dump line bytes
+ --[[
+ print(line)
+ line:gsub(".", function (ch) print(string.byte(ch)) end)
+ --]]
+
+ if line:startswith(note) then
+ -- optimization: move this note to head
+ if idx ~= 1 then
+ table.insert(_g.notes, 1, note)
+ end
+ return line:sub(#note):trim()
+ end
+ end
+end
+
diff --git a/xmake/modules/private/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua
index 001e2dea9..19ae51cbf 100644
--- a/xmake/modules/private/tools/gcc/parse_deps.lua
+++ b/xmake/modules/private/tools/gcc/parse_deps.lua
@@ -45,7 +45,17 @@ function _normailize_dep(dep)
end
-- parse depsfiles from string
-function from_str(depsdata)
+--
+-- 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)
-- parse results
local results = hashset.new()
@@ -65,24 +75,3 @@ function from_str(depsdata)
end
return results:to_array()
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(depsfile)
-
- -- get deps string
- local str = io.readfile(depsfile, {continuation = "\\"})
- if not str or #str == 0 then
- return {}
- end
- return from_str(str)
-end
diff --git a/xmake/modules/private/tools/nvcc/parse_deps.lua b/xmake/modules/private/tools/nvcc/parse_deps.lua
deleted file mode 100644
index 7c477d47f..000000000
--- a/xmake/modules/private/tools/nvcc/parse_deps.lua
+++ /dev/null
@@ -1,21 +0,0 @@
---!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 OpportunityLiu
--- @file parse_deps.lua
---
-
-inherit("private.tools.gcc.parse_deps") \ No newline at end of file