-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[Support] Resolve symlinks in getMainExecutable()
on Windows
#76304
Conversation
This makes the Windows implementation for `getMainExecutable()` behave the same as its Linux counterpart, in regards to symlinks. Previously, when using `cmake ... -DLLVM_USE_SYMLINKS=ON`, calling this function wouldn't resolve to the "real", non-symlinked path.
@llvm/pr-subscribers-platform-windows Author: Alexandre Ganea (aganea) ChangesThis makes the Windows implementation for Full diff: https://github.com/llvm/llvm-project/pull/76304.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 168a63bb2d969d..6b50309be94d77 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -154,7 +154,10 @@ std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
return "";
llvm::sys::path::make_preferred(PathNameUTF8);
- return std::string(PathNameUTF8.data());
+
+ SmallString<256> RealPath;
+ sys::fs::real_path(PathNameUTF8, RealPath);
+ return (std::string)RealPath;
}
UniqueID file_status::getUniqueID() const {
|
@llvm/pr-subscribers-llvm-support Author: Alexandre Ganea (aganea) ChangesThis makes the Windows implementation for Full diff: https://github.com/llvm/llvm-project/pull/76304.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 168a63bb2d969d..6b50309be94d77 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -154,7 +154,10 @@ std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
return "";
llvm::sys::path::make_preferred(PathNameUTF8);
- return std::string(PathNameUTF8.data());
+
+ SmallString<256> RealPath;
+ sys::fs::real_path(PathNameUTF8, RealPath);
+ return (std::string)RealPath;
}
UniqueID file_status::getUniqueID() const {
|
Seems reasonable at first glance. How should this behave with |
Since we're using
|
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.
As suggested.
…() failed The commit f11b056 (llvm#76304) breaks `clang` and other tools if they are used from a RAMDrive. `GetFinalPathNameByHandleW()` may return 0 and GetLastError 0x28. This patch fixes that issue. Note `real_path()` uses `openFileForRead()` but it reports the error only if failed to open a file. Getting `RealPath` is optional functionality. BTW, `sys::fs::real_path()` resolves not only symlinks, but also network drives and virtual drives created by the `subst` tool. It may break an automation. It is better to detect symlinks and resolve only symlinks.
…() failed (#87749) The commit f11b056 (#76304) breaks `clang` and other tools if they are used from a RAMDrive. `GetFinalPathNameByHandleW()` may return 0 and GetLastError 0x28. This patch fixes that issue. Note `real_path()` uses `openFileForRead()` but it reports the error only if failed to open a file. Getting `RealPath` is optional functionality. BTW, `sys::fs::real_path()` resolves not only symlinks, but also network drives and virtual drives created by the `subst` tool. It may break an automation. It is better to detect symlinks and resolve only symlinks.
This has the unfortunate consequence that if you have llvm-config in a path with spaces and call it with the short path, the paths it will emit will contain spaces, when they didn't before. That is, before:
But now:
It's not too much of a problem with |
@glandium It is a bit unfortunate but it seems the previous behavior was "by chance". Do you happen to know what happens on Linux under the same conditions? (path with spaces or symlink without spaces pointing to a path with spaces) I could send a PR to add |
It probably has the "contains spaces" problem on Linux. I guess |
How did you actually found this? What was your usage of llvm-config? |
It's not really relevant, but it's in the Firefox build system, using |
llvm-config output not handling spaces is actually #28117 |
If any of the printed paths by `llvm-config` contains quotes, spaces, backslashes or dollar sign characters, these paths will be quoted and the corresponding characters will be escaped. Following discussion in llvm#76304 Fixes llvm#28117
If any of the printed paths by `llvm-config` contains quotes, spaces, backslashes or dollar sign characters, these paths will be quoted and the corresponding characters will be escaped. Following discussion in llvm#76304 Fixes llvm#28117
This makes the Windows implementation for
getMainExecutable()
behave the same as its Linux counterpart, in regards to symlinks. Previously, when usingcmake ... -DLLVM_USE_SYMLINKS=ON
, calling this function wouldn't resolve to the "real", non-symlinked path.