summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-07-27 23:00:17 +0800
committerruki <[email protected]>2020-07-27 23:00:17 +0800
commit9b894b76ea02f832a915e52b6d1b1d4bd3e66995 (patch)
treefe01c6ce96fd0bec711bb285cf90e2e4955762ca
parent9444d665d8ed9f2a23c265ffe6dacecda2485820 (diff)
support /sourceDependencies for cl
-rw-r--r--xmake/modules/core/project/depend.lua4
-rw-r--r--xmake/modules/core/tools/cl.lua45
-rw-r--r--xmake/modules/private/tools/cl/parse_deps_json.lua56
3 files changed, 97 insertions, 8 deletions
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
index 9c1484943..c0b27c67a 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.cl.parse_deps_json", {alias = "parse_deps_cl_json"})
import("private.tools.rc.parse_deps", {alias = "parse_deps_rc"})
import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"})
@@ -46,6 +47,9 @@ function load(dependfile)
if dependinfo.depfiles_gcc then
_load_depfiles(parse_deps_gcc, dependinfo, dependinfo.depfiles_gcc)
dependinfo.depfiles_gcc = nil
+ elseif dependinfo.depfiles_cl_json then
+ _load_depfiles(parse_deps_cl_json, dependinfo, dependinfo.depfiles_cl_json)
+ dependinfo.depfiles_cl_json = nil
elseif dependinfo.depfiles_cl then
_load_depfiles(parse_deps_cl, dependinfo, dependinfo.depfiles_cl)
dependinfo.depfiles_cl = nil
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 3dfa0bb0f..45a205f20 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -316,6 +316,20 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags)
return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. pcoutputfile, "-Fo" .. pcoutputfile .. ".obj", pcheaderfile)
end
+-- has /sourceDependencies xxx.json @see https://github.com/xmake-io/xmake/issues/868?
+function _has_source_dependencies(self)
+ local has_source_dependencies = _g._HAS_SOURCE_DEPENDENCIES
+ if has_source_dependencies == nil then
+ local source_dependencies_jsonfile = os.tmpfile() .. ".json"
+ if self:has_flags("/sourceDependencies " .. source_dependencies_jsonfile, "cl_sourceDependencies") and os.isfile(source_dependencies_jsonfile) then
+ has_source_dependencies = true
+ end
+ has_source_dependencies = has_source_dependencies or false
+ _g._HAS_SOURCE_DEPENDENCIES = has_source_dependencies
+ end
+ return has_source_dependencies
+end
+
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags, opt)
@@ -342,6 +356,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
end
-- compile it
+ local depfile = nil
local outdata = try
{
function ()
@@ -349,7 +364,12 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- generate includes file
local compflags = flags
if dependinfo then
- compflags = table.join(flags, "-showIncludes")
+ if _has_source_dependencies(self) then
+ depfile = os.tmpfile()
+ compflags = table.join(flags, "/sourceDependencies", depfile)
+ else
+ compflags = table.join(flags, "-showIncludes")
+ end
end
-- use vstool to compile and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528
@@ -372,12 +392,16 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
errors = errs
end
- -- filter includes notes: "Note: including file: xxx.h", @note maybe not english language
local results = ""
- for _, line in ipairs(tostring(errors):split("\n", {plain = true})) do
- line = line:rtrim()
- if not parse_include(line) then
- results = results .. line .. "\r\n"
+ if depfile then
+ results = tostring(errors)
+ else
+ -- filter includes notes: "Note: including file: xxx.h", @note maybe not english language
+ for _, line in ipairs(tostring(errors):split("\n", {plain = true})) do
+ line = line:rtrim()
+ if not parse_include(line) then
+ results = results .. line .. "\r\n"
+ end
end
end
os.raise(results)
@@ -415,8 +439,13 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
}
-- generate the dependent includes
- if dependinfo and outdata then
- dependinfo.depfiles_cl = outdata
+ if dependinfo then
+ if depfile and os.isfile(depfile) then
+ dependinfo.depfiles_cl_json = io.readfile(depfile)
+ os.rm(depfile)
+ elseif outdata then
+ dependinfo.depfiles_cl = outdata
+ end
end
end
diff --git a/xmake/modules/private/tools/cl/parse_deps_json.lua b/xmake/modules/private/tools/cl/parse_deps_json.lua
new file mode 100644
index 000000000..f02da5fe4
--- /dev/null
+++ b/xmake/modules/private/tools/cl/parse_deps_json.lua
@@ -0,0 +1,56 @@
+--!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_json.lua
+--
+
+-- imports
+import("core.project.project")
+import("core.base.hashset")
+import("core.base.json")
+
+-- parse depsfiles from string
+function main(depsdata)
+
+ -- decode json data first
+ depsdata = json.decode(depsdata)
+
+ -- get includes
+ local includes
+ if depsdata and depsdata.Data then
+ includes = depsdata.Data.Includes
+ end
+
+ -- translate it
+ local results = hashset.new()
+ for _, includefile in ipairs(includes) do
+
+ -- 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
+ return results:to_array()
+end
+