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 /xmake/modules/private/tools/cl/parse_deps_json.lua | |
| parent | b64f0d5aa9b93b03505acaf050edb6bd422f2aa7 (diff) | |
improve parse header deps
Diffstat (limited to 'xmake/modules/private/tools/cl/parse_deps_json.lua')
| -rw-r--r-- | xmake/modules/private/tools/cl/parse_deps_json.lua | 68 |
1 files changed, 58 insertions, 10 deletions
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 |
