diff options
| author | ruki <[email protected]> | 2020-12-24 00:35:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-24 00:35:32 +0800 |
| commit | 243ddec82d865010efcc35d0989c5fdffb0dff84 (patch) | |
| tree | 0e4c44ea58779b43347a784569a0bec447313d12 | |
| parent | b64f0d5aa9b93b03505acaf050edb6bd422f2aa7 (diff) | |
improve parse header deps
| -rw-r--r-- | tests/projects/other/parse_headerdeps/.gitignore | 8 | ||||
| -rw-r--r-- | tests/projects/other/parse_headerdeps/common/test1.hpp | 9 | ||||
| -rw-r--r-- | tests/projects/other/parse_headerdeps/src/test1.cpp | 8 | ||||
| -rw-r--r-- | tests/projects/other/parse_headerdeps/src/xmake.lua | 12 | ||||
| -rw-r--r-- | xmake/modules/private/tools/cl/parse_deps.lua | 72 | ||||
| -rw-r--r-- | xmake/modules/private/tools/cl/parse_deps_json.lua | 68 | ||||
| -rw-r--r-- | xmake/modules/private/tools/gcc/parse_deps.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/tools/rc/parse_deps.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/qt/install/windows.lua | 4 |
9 files changed, 161 insertions, 34 deletions
diff --git a/tests/projects/other/parse_headerdeps/.gitignore b/tests/projects/other/parse_headerdeps/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/parse_headerdeps/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/parse_headerdeps/common/test1.hpp b/tests/projects/other/parse_headerdeps/common/test1.hpp new file mode 100644 index 000000000..9a4973522 --- /dev/null +++ b/tests/projects/other/parse_headerdeps/common/test1.hpp @@ -0,0 +1,9 @@ +// ../common/test1.hpp +#include <iostream> + +void f() +{ + std::cout << "f()" << std::endl; +} + + diff --git a/tests/projects/other/parse_headerdeps/src/test1.cpp b/tests/projects/other/parse_headerdeps/src/test1.cpp new file mode 100644 index 000000000..46c4224d3 --- /dev/null +++ b/tests/projects/other/parse_headerdeps/src/test1.cpp @@ -0,0 +1,8 @@ +// test1.cpp +#include "common/test1.hpp" + +int main(int argc, char** argv) +{ + f(); + return 0; +} diff --git a/tests/projects/other/parse_headerdeps/src/xmake.lua b/tests/projects/other/parse_headerdeps/src/xmake.lua new file mode 100644 index 000000000..3b5cae909 --- /dev/null +++ b/tests/projects/other/parse_headerdeps/src/xmake.lua @@ -0,0 +1,12 @@ +-- xmake.lua +-- global +add_rules('mode.debug', 'mode.release') + +set_version('0.1.0') + +set_kind('binary') +add_includedirs('..') +set_warnings('all') +--set_languages('cxx20') +target('test1') + add_files('test1.cpp') 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 diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua index 4401bd024..9a19e454d 100644 --- a/xmake/rules/qt/install/windows.lua +++ b/xmake/rules/qt/install/windows.lua @@ -55,8 +55,8 @@ function main(target, opt) local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()}) if msvc then local vcvars = msvc:config("vcvars") - if vcvars and vcvars.VSInstallDir then - envs = {VCINSTALLDIR = path.join(vcvars.VSInstallDir, "VC")} + if vcvars and vcvars.VCInstallDir then + envs = {VCINSTALLDIR = vcvars.VCInstallDir} end end |
