summaryrefslogtreecommitdiff
path: root/xmake/modules/private/tools
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-24 00:35:32 +0800
committerruki <[email protected]>2020-12-24 00:35:32 +0800
commit243ddec82d865010efcc35d0989c5fdffb0dff84 (patch)
tree0e4c44ea58779b43347a784569a0bec447313d12 /xmake/modules/private/tools
parentb64f0d5aa9b93b03505acaf050edb6bd422f2aa7 (diff)
improve parse header deps
Diffstat (limited to 'xmake/modules/private/tools')
-rw-r--r--xmake/modules/private/tools/cl/parse_deps.lua72
-rw-r--r--xmake/modules/private/tools/cl/parse_deps_json.lua68
-rw-r--r--xmake/modules/private/tools/gcc/parse_deps.lua8
-rw-r--r--xmake/modules/private/tools/rc/parse_deps.lua6
4 files changed, 122 insertions, 32 deletions
diff --git a/xmake/modules/private/tools/cl/parse_deps.lua b/xmake/modules/private/tools/cl/parse_deps.lua
index 98011534a..5a0cfe27d 100644
--- a/xmake/modules/private/tools/cl/parse_deps.lua
+++ b/xmake/modules/private/tools/cl/parse_deps.lua
@@ -22,27 +22,71 @@
import("core.project.project")
import("core.base.hashset")
import("parse_include")
+import("core.tool.toolchain")
+
+-- get $VCInstallDir
+function _VCInstallDir()
+ local VCInstallDir = _g.VCInstallDir
+ if not VCInstallDir then
+ local msvc = toolchain.load("msvc")
+ if msvc then
+ local vcvars = msvc:config("vcvars")
+ if vcvars and vcvars.VCInstallDir then
+ VCInstallDir = vcvars.VCInstallDir
+ _g.VCInstallDir = VCInstallDir
+ end
+ end
+ end
+ return VCInstallDir
+end
+
+-- get $WindowsSdkDir
+function _WindowsSdkDir()
+ local WindowsSdkDir = _g.WindowsSdkDir
+ if not WindowsSdkDir then
+ local msvc = toolchain.load("msvc")
+ if msvc then
+ local vcvars = msvc:config("vcvars")
+ if vcvars and vcvars.WindowsSdkDir then
+ WindowsSdkDir = vcvars.WindowsSdkDir
+ _g.WindowsSdkDir = WindowsSdkDir
+ end
+ end
+ end
+ return WindowsSdkDir
+end
+
+
+-- normailize path of a dependecy
+function _normailize_dep(dep, projectdir)
+ if path.is_absolute(dep) then
+ dep = path.translate(dep)
+ else
+ dep = path.absolute(dep, projectdir)
+ end
+ local VCInstallDir = _VCInstallDir()
+ local WindowsSdkDir = _WindowsSdkDir()
+ if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then
+ -- we ignore headerfiles in vc install directory
+ return
+ end
+ if dep:startswith(projectdir) then
+ return path.relative(dep, projectdir)
+ else
+ -- we need also check header files outside project
+ -- https://github.com/xmake-io/xmake/issues/1154
+ return dep
+ end
+end
-- 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())
+ includefile = _normailize_dep(includefile, os.projectdir())
+ if includefile then
results:insert(includefile)
end
end
diff --git a/xmake/modules/private/tools/cl/parse_deps_json.lua b/xmake/modules/private/tools/cl/parse_deps_json.lua
index 1d2979268..f274dc382 100644
--- a/xmake/modules/private/tools/cl/parse_deps_json.lua
+++ b/xmake/modules/private/tools/cl/parse_deps_json.lua
@@ -22,6 +22,62 @@
import("core.project.project")
import("core.base.hashset")
import("core.base.json")
+import("core.tool.toolchain")
+
+-- get $VCInstallDir
+function _VCInstallDir()
+ local VCInstallDir = _g.VCInstallDir
+ if not VCInstallDir then
+ local msvc = toolchain.load("msvc")
+ if msvc then
+ local vcvars = msvc:config("vcvars")
+ if vcvars and vcvars.VCInstallDir then
+ VCInstallDir = vcvars.VCInstallDir:lower() -- @note we need lower case for json/deps
+ _g.VCInstallDir = VCInstallDir
+ end
+ end
+ end
+ return VCInstallDir
+end
+
+-- get $WindowsSdkDir
+function _WindowsSdkDir()
+ local WindowsSdkDir = _g.WindowsSdkDir
+ if not WindowsSdkDir then
+ local msvc = toolchain.load("msvc")
+ if msvc then
+ local vcvars = msvc:config("vcvars")
+ if vcvars and vcvars.WindowsSdkDir then
+ WindowsSdkDir = vcvars.WindowsSdkDir:lower() -- @note we need lower case for json/deps
+ _g.WindowsSdkDir = WindowsSdkDir
+ end
+ end
+ end
+ return WindowsSdkDir
+end
+
+-- normailize path of a dependecy
+function _normailize_dep(dep, projectdir)
+ if path.is_absolute(dep) then
+ dep = path.translate(dep)
+ else
+ dep = path.absolute(dep, projectdir)
+ end
+ dep = dep:lower()
+ local VCInstallDir = _VCInstallDir()
+ local WindowsSdkDir = _WindowsSdkDir()
+ if (VCInstallDir and dep:startswith(VCInstallDir)) or (WindowsSdkDir and dep:startswith(WindowsSdkDir)) then
+ -- we ignore headerfiles in vc install directory
+ return
+ end
+ if dep:startswith(projectdir) then
+ return path.relative(dep, projectdir)
+ else
+ -- we need also check header files outside project
+ -- https://github.com/xmake-io/xmake/issues/1154
+ return dep
+ end
+end
-- parse depsfiles from string
function main(depsdata)
@@ -39,16 +95,8 @@ function main(depsdata)
local results = hashset.new()
local projectdir = os.projectdir():lower() -- we need generate lower string, because json values are all lower
for _, includefile in ipairs(includes) do
-
- -- get the absolute path
- if not path.is_absolute(includefile) then
- includefile = path.absolute(includefile, projectdir):lower()
- end
-
- -- save it if belong to the project
- if includefile:startswith(projectdir) then
- -- insert it and filter repeat
- includefile = path.relative(includefile, projectdir)
+ includefile = _normailize_dep(includefile, projectdir)
+ if includefile then
results:insert(includefile)
end
end
diff --git a/xmake/modules/private/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua
index f3f4d76f4..0cb2ad4af 100644
--- a/xmake/modules/private/tools/gcc/parse_deps.lua
+++ b/xmake/modules/private/tools/gcc/parse_deps.lua
@@ -27,17 +27,17 @@ local space_placeholder = "\001"
-- 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)
+ else
+ -- we need also check header files outside project
+ -- https://github.com/xmake-io/xmake/issues/1154
+ return dep
end
end
diff --git a/xmake/modules/private/tools/rc/parse_deps.lua b/xmake/modules/private/tools/rc/parse_deps.lua
index a31ce4588..778f7b03f 100644
--- a/xmake/modules/private/tools/rc/parse_deps.lua
+++ b/xmake/modules/private/tools/rc/parse_deps.lua
@@ -24,17 +24,15 @@ 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)
+ else
+ return deps
end
end