-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[core] Generalize TROOT::GetShardLibDir() also on Windows #20810
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
Open
guitargeek
wants to merge
1
commit into
root-project:master
Choose a base branch
from
guitargeek:getlibdir_windows
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3017,6 +3017,33 @@ const TString& TROOT::GetBinDir() { | |
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Get the library directory in the installation. Static utility function. | ||
| /// | ||
| /// By default, this is just an alias for TROOT::GetSharedLibDir(), which | ||
| /// returns the directory containing the ROOT shared libraries. | ||
| /// | ||
| /// On Windows, the behavior is different. In that case, this function doesn't | ||
| /// return the directory of the **shared libraries** (like `libCore.dll`), but | ||
| /// the **import libraries**, which are used at link time (like `libCore.lib`). | ||
|
|
||
| const TString &TROOT::GetLibDir() | ||
| { | ||
| #if defined(R__WIN32) | ||
| static bool initialized = false; | ||
| static TString rootlibdir; | ||
| if (initialized) | ||
| return rootlibdir; | ||
|
|
||
| initialized = true; | ||
| rootlibdir = "lib"; | ||
| gSystem->PrependPathName(GetRootSys(), rootlibdir); | ||
| return rootlibdir; | ||
| #else | ||
| return TROOT::GetSharedLibDir(); | ||
| #endif | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Get the shared libraries directory in the installation. Static utility function. | ||
| /// | ||
| /// This function inspects the libraries currently loaded in the process to | ||
| /// locate the ROOT Core library. Once found, it extracts and returns the | ||
| /// directory containing that library. If the ROOT Core library was not found, | ||
|
|
@@ -3025,9 +3052,9 @@ const TString& TROOT::GetBinDir() { | |
| /// The result is cached in a static variable so the lookup is only performed | ||
| /// once per process, and the implementation is platform-specific. | ||
| /// | ||
| /// \return The directory path (as a `TString`) containing the ROOT core library. | ||
| /// \return The directory path (as a `TString`) containing the ROOT shared libraries. | ||
|
|
||
| const TString &TROOT::GetLibDir() | ||
| const TString &TROOT::GetSharedLibDir() | ||
| { | ||
| static bool haveLooked = false; | ||
| static TString rootlibdir; | ||
|
|
@@ -3057,9 +3084,35 @@ const TString &TROOT::GetLibDir() | |
|
|
||
| #elif defined(_WIN32) | ||
|
|
||
| // Or Windows, the original hardcoded path is kept for now. | ||
| rootlibdir = "lib"; | ||
| gSystem->PrependPathName(GetRootSys(), rootlibdir); | ||
| HMODULE modules[1024]; | ||
| DWORD needed = 0; | ||
|
|
||
| HANDLE process = GetCurrentProcess(); | ||
| if (EnumProcessModules(process, modules, sizeof(modules), &needed)) { | ||
| const unsigned int count = needed / sizeof(HMODULE); | ||
|
|
||
| for (unsigned int i = 0; i < count; ++i) { | ||
| wchar_t wpath[MAX_PATH]; | ||
| DWORD len = GetModuleFileNameW(modules[i], wpath, MAX_PATH); | ||
| if (!len) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably okay to ignore arbitrary library (for which the path is too long) ... but one of them might be |
||
| continue; | ||
|
|
||
| fs::path p(wpath); | ||
| if (p.filename() == TO_LITERAL(LIB_CORE_NAME)) { | ||
|
|
||
| // Convert UTF-16 to UTF-8 explicitly | ||
| const std::wstring wdir = p.parent_path().wstring(); | ||
|
|
||
| int utf8len = WideCharToMultiByte(CP_UTF8, 0, wdir.c_str(), -1, nullptr, 0, nullptr, nullptr); | ||
|
|
||
| std::string utf8dir(utf8len - 1, '\0'); | ||
| WideCharToMultiByte(CP_UTF8, 0, wdir.c_str(), -1, utf8dir.data(), utf8len, nullptr, nullptr); | ||
|
|
||
| rootlibdir = utf8dir.c_str(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #else | ||
|
|
||
|
|
@@ -3083,17 +3136,6 @@ const TString &TROOT::GetLibDir() | |
| return rootlibdir; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Get the shared libraries directory in the installation. Static utility function. | ||
|
|
||
| const TString& TROOT::GetSharedLibDir() { | ||
| #if defined(R__WIN32) | ||
| return TROOT::GetBinDir(); | ||
| #else | ||
| return TROOT::GetLibDir(); | ||
| #endif | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Get the include directory in the installation. Static utility function. | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we handle and/or warn about the failure case (eg. if there are more than 1024 libraries or any other error)? Right now, it seems that in the failure case the return value is 'empty'.