From d5721f1aaafe7e80751329d6c4c6aaa0a26d74ac Mon Sep 17 00:00:00 2001 From: Bryce Hutchings <5100250+brycehutchings@users.noreply.github.com> Date: Thu, 11 Feb 2021 10:29:54 -0800 Subject: [PATCH] Remove canonicalization in Windows loader (#239) * Remove canonicalization in Windows loader * Add change fragment * Remove submodule --- changes/sdk/pr.239.gh.OpenXR-SDK-Source.md | 1 + src/common/filesystem_utils.cpp | 27 ++++++++-------------- src/loader/CMakeLists.txt | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) create mode 100644 changes/sdk/pr.239.gh.OpenXR-SDK-Source.md diff --git a/changes/sdk/pr.239.gh.OpenXR-SDK-Source.md b/changes/sdk/pr.239.gh.OpenXR-SDK-Source.md new file mode 100644 index 000000000..2ce44f406 --- /dev/null +++ b/changes/sdk/pr.239.gh.OpenXR-SDK-Source.md @@ -0,0 +1 @@ +Loader: Fix loader failing to load on Windows 7 due to pathcch dependency. \ No newline at end of file diff --git a/src/common/filesystem_utils.cpp b/src/common/filesystem_utils.cpp index af3d1402a..3b0685de3 100644 --- a/src/common/filesystem_utils.cpp +++ b/src/common/filesystem_utils.cpp @@ -75,10 +75,6 @@ #include #endif -#if defined(XR_USE_PLATFORM_WIN32) -#include -#endif - #if defined(XR_USE_PLATFORM_WIN32) #define PATH_SEPARATOR ';' #define DIRECTORY_SYMBOL '\\' @@ -121,14 +117,10 @@ bool FileSysUtilsGetAbsolutePath(const std::string& path, std::string& absolute) bool FileSysUtilsGetCanonicalPath(const std::string& path, std::string& canonical) { #if defined(XR_USE_PLATFORM_WIN32) - // std::filesystem::canonical fails on UWP and must be avoided. This alternative will not - // follow symbolic links but symbolic links are not needed on Windows since the loader uses - // the registry as a form of indirection instead. - wchar_t canonical_wide_path[MAX_PATH]; - if (FAILED(PathCchCanonicalize(canonical_wide_path, MAX_PATH, utf8_to_wide(path).c_str()))) { - return false; - } - canonical = wide_to_utf8(canonical_wide_path); + // std::filesystem::canonical fails on UWP and must be avoided. Further, PathCchCanonicalize is not available on Windows 7 and + // PathCanonicalizeW is not available on UWP. However, symbolic links are not important on Windows since the loader uses the + // registry for indirection instead, and so this function can be a no-op on Windows. + canonical = path; #else canonical = FS_PREFIX::canonical(path).string(); #endif @@ -218,12 +210,11 @@ bool FileSysUtilsGetAbsolutePath(const std::string& path, std::string& absolute) } bool FileSysUtilsGetCanonicalPath(const std::string& path, std::string& absolute) { - wchar_t tmp_path[MAX_PATH]; - if (SUCCEEDED(PathCchCanonicalize(tmp_path, MAX_PATH, utf8_to_wide(path).c_str()))) { - absolute = wide_to_utf8(tmp_path); - return true; - } - return false; + // PathCchCanonicalize is not available on Windows 7 and PathCanonicalizeW is not available on UWP. However, symbolic links are + // not important on Windows since the loader uses the registry for indirection instead, and so this function can be a no-op on + // Windows. + absolute = path; + return true; } bool FileSysUtilsCombinePaths(const std::string& parent, const std::string& child, std::string& combined) { diff --git a/src/loader/CMakeLists.txt b/src/loader/CMakeLists.txt index 50e166b77..cfc208ea5 100644 --- a/src/loader/CMakeLists.txt +++ b/src/loader/CMakeLists.txt @@ -193,7 +193,7 @@ elseif(WIN32) target_compile_options(openxr_loader PRIVATE /wd6386) endif() - target_link_libraries(openxr_loader PUBLIC advapi32 pathcch) + target_link_libraries(openxr_loader PUBLIC advapi32) # Need to copy DLL to client directories so clients can easily load it. if(DYNAMIC_LOADER AND (CMAKE_GENERATOR MATCHES "^Visual Studio.*"))