-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vcpkg] Fix the case of current_path() before use on Windows. #13537
Conversation
This is a better solution than that I tried in microsoft#13144 -- rather than trying to cannoicalize the path completely, which would destroy symlinks etc; this form calls FindFirstFile on each path element to get the real case from the filesystem. Fixes microsoft#13105. (Note the wrong case in the CWD in the prompt, but the correct case in all the output:) PS C:\DeV\vcPKG> .\vcpkg.exe install curl Computing installation plan... The following packages will be built and installed: curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows * zlib[core]:x86-windows Additional packages (*) will be modified to complete this operation. Detecting compiler hash for triplet x86-windows... Starting package 1/2: zlib:x86-windows Building package zlib[core]:x86-windows... Using cached binary package: C:\Users\billy\AppData\Local\vcpkg/archives\c6\c61dd1bcc23348934c55f4ced77f1e4b0f353394.zipBuilding package zlib[core]:x86-windows... done Installing package zlib[core]:x86-windows... Installing package zlib[core]:x86-windows... done Elapsed time for package zlib:x86-windows: 62.26 ms Starting package 2/2: curl:x86-windows Building package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... Could not locate cached archive: C:\Users\billy\AppData\Local\vcpkg/archives\9f\9fa16d473c9539e9ea7ab3922eff46618f3a4c4b.zip -- Downloading https://github.com/curl/curl/archive/9d954e49bce3706a9a2efb119ecd05767f0f2a9e.tar.gz... -- Extracting source C:/Dev/vcpkg/downloads/curl-curl-9d954e49bce3706a9a2efb119ecd05767f0f2a9e.tar.gz -- Applying patch 0002_fix_uwp.patch -- Applying patch 0004_nghttp2_staticlib.patch -- Applying patch 0005_remove_imp_suffix.patch -- Applying patch 0006_fix_tool_depends.patch -- Applying patch 0007_disable_tool_export_curl_target.patch -- Applying patch 0009_fix_openssl_config.patch -- Applying patch 0010_fix_othertests_cmake.patch -- Applying patch 0011_fix_static_build.patch -- Using source at C:/Dev/vcpkg/buildtrees/curl/src/767f0f2a9e-91d24adee1.clean -- Configuring x86-windows -- Building x86-windows-dbg -- Building x86-windows-rel -- Installing: C:/Dev/vcpkg/packages/curl_x86-windows/share/curl/curl-config -- Installing: C:/Dev/vcpkg/packages/curl_x86-windows/share/curl/vcpkg-cmake-wrapper.cmake -- Installing: C:/Dev/vcpkg/packages/curl_x86-windows/share/curl/copyright -- Performing post-build validation -- Performing post-build validation done Stored binary cache: C:\Users\billy\AppData\Local\vcpkg/archives\9f\9fa16d473c9539e9ea7ab3922eff46618f3a4c4b.zip Building package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... done Installing package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... Installing package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... done Elapsed time for package curl:x86-windows: 1.299 min Total elapsed time: 1.33 min The package curl:x86-windows provides CMake targets: find_package(CURL CONFIG REQUIRED) target_link_libraries(main PRIVATE CURL::libcurl) PS C:\DeV\vcPKG>
return true; | ||
} | ||
|
||
struct FindFirstOp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth making this non-movable and non-copiable to ensure older compilers don't miscompile this.
toolsrc/src/vcpkg/base/files.cpp
Outdated
return GetLastError(); | ||
} | ||
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 0; | |
return ERROR_SUCCESS; |
@@ -1197,4 +1267,105 @@ namespace vcpkg::Files | |||
#endif // ^^^ windows | |||
#endif // ^^^ std::experimental::filesystem | |||
} | |||
|
|||
#ifdef _WIN32 | |||
fs::path win32_fix_path_case(const fs::path& source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider banning relative paths: they're almost certainly a bug given the coding style of vcpkg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relative paths are possible if the user supplies one on the command line. It's not difficult to support them so this component should, even though most of the time the input will be absolute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In those cases, we would combine with the "relative-to" path (original_cwd) before washing it through this function.
Alternatively: this function could take an assumed-already-normalized root to fix relative to and return an absolute path. This could also save overall fs operations when resolving multiple subdirectories from a single root.
toolsrc/src/vcpkg/base/files.cpp
Outdated
in_progress.append(first, next_slash); | ||
FindFirstOp this_find; | ||
unsigned long last_error = this_find.find_first(in_progress.c_str()); | ||
if (last_error == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (last_error == 0) | |
if (last_error == ERROR_SUCCESS) |
VCPKG_LINE_INFO, "Attempt to fix case of a path containing wildcards: %s", fs::u8string(source)); | ||
} | ||
|
||
std::wstring in_progress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::wstring in_progress; | |
std::wstring in_progress; | |
in_progress.reserve(native.size()); |
CHECK(win32_fix_path_case(L"\\??\\c:\\WiNdOws") == L"\\??\\c:\\WiNdOws"); | ||
CHECK(win32_fix_path_case(L"\\\\?\\c:\\WiNdOws") == L"\\\\?\\c:\\WiNdOws"); | ||
CHECK(win32_fix_path_case(L"\\\\.\\c:\\WiNdOws") == L"\\\\.\\c:\\WiNdOws"); | ||
CHECK(win32_fix_path_case(L"c:\\/\\/Nonexistent\\/path/here") == L"C:\\Nonexistent\\path\\here"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: add a test case for ///server/name
to indicate expected behavior.
@@ -1197,4 +1267,105 @@ namespace vcpkg::Files | |||
#endif // ^^^ windows | |||
#endif // ^^^ std::experimental::filesystem | |||
} | |||
|
|||
#ifdef _WIN32 | |||
fs::path win32_fix_path_case(const fs::path& source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anywhere we load a path from an environment variable, we need to call this function. I know there are a few cases of this in binarycaching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you push a commit fixing up those cases into this branch?
Co-authored-by: ras0219 <[email protected]>
[vcpkg] Fix the case of current_path() before use on Windows. (microsoft#13537)
…oft#13537) * Fix the case of current_path() before use on Windows. This is a better solution than that I tried in microsoft#13144 -- rather than trying to cannoicalize the path completely, which would destroy symlinks etc; this form calls FindFirstFile on each path element to get the real case from the filesystem. Fixes microsoft#13105. (Note the wrong case in the CWD in the prompt, but the correct case in all the output:) PS C:\DeV\vcPKG> .\vcpkg.exe install curl Computing installation plan... The following packages will be built and installed: curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows * zlib[core]:x86-windows Additional packages (*) will be modified to complete this operation. Detecting compiler hash for triplet x86-windows... Starting package 1/2: zlib:x86-windows Building package zlib[core]:x86-windows... Using cached binary package: C:\Users\billy\AppData\Local\vcpkg/archives\c6\c61dd1bcc23348934c55f4ced77f1e4b0f353394.zipBuilding package zlib[core]:x86-windows... done Installing package zlib[core]:x86-windows... Installing package zlib[core]:x86-windows... done Elapsed time for package zlib:x86-windows: 62.26 ms Starting package 2/2: curl:x86-windows Building package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... Could not locate cached archive: C:\Users\billy\AppData\Local\vcpkg/archives\9f\9fa16d473c9539e9ea7ab3922eff46618f3a4c4b.zip -- Downloading https://github.com/curl/curl/archive/9d954e49bce3706a9a2efb119ecd05767f0f2a9e.tar.gz... -- Extracting source C:/Dev/vcpkg/downloads/curl-curl-9d954e49bce3706a9a2efb119ecd05767f0f2a9e.tar.gz -- Applying patch 0002_fix_uwp.patch -- Applying patch 0004_nghttp2_staticlib.patch -- Applying patch 0005_remove_imp_suffix.patch -- Applying patch 0006_fix_tool_depends.patch -- Applying patch 0007_disable_tool_export_curl_target.patch -- Applying patch 0009_fix_openssl_config.patch -- Applying patch 0010_fix_othertests_cmake.patch -- Applying patch 0011_fix_static_build.patch -- Using source at C:/Dev/vcpkg/buildtrees/curl/src/767f0f2a9e-91d24adee1.clean -- Configuring x86-windows -- Building x86-windows-dbg -- Building x86-windows-rel -- Installing: C:/Dev/vcpkg/packages/curl_x86-windows/share/curl/curl-config -- Installing: C:/Dev/vcpkg/packages/curl_x86-windows/share/curl/vcpkg-cmake-wrapper.cmake -- Installing: C:/Dev/vcpkg/packages/curl_x86-windows/share/curl/copyright -- Performing post-build validation -- Performing post-build validation done Stored binary cache: C:\Users\billy\AppData\Local\vcpkg/archives\9f\9fa16d473c9539e9ea7ab3922eff46618f3a4c4b.zip Building package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... done Installing package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... Installing package curl[core,non-http,schannel,ssl,sspi,winssl]:x86-windows... done Elapsed time for package curl:x86-windows: 1.299 min Total elapsed time: 1.33 min The package curl:x86-windows provides CMake targets: find_package(CURL CONFIG REQUIRED) target_link_libraries(main PRIVATE CURL::libcurl) PS C:\DeV\vcPKG> * Fix *nix builds. * PR feedback. * Update toolsrc/src/vcpkg/base/files.cpp Co-authored-by: ras0219 <[email protected]>
This is a better solution than that I tried in #13144 -- rather than trying to cannoicalize the path completely, which would destroy symlinks etc; this form calls FindFirstFile on each path element to get the real case from the filesystem.
Fixes #13105.
(Note the wrong case in the CWD in the prompt, but the correct case in all the output:)