-
Notifications
You must be signed in to change notification settings - Fork 461
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
Try to make exename portable. Refactor searchForIncludePath. #5185
base: main
Are you sure you want to change the base?
Conversation
5d6bb23
to
8f2c3b6
Compare
8106355
to
6ceaed7
Compare
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.
See comments
bool ParserOptions::searchForIncludePath(const char *&includePathOut, | ||
std::vector<cstring> userSpecifiedPaths, | ||
const std::vector<cstring> &userSpecifiedPaths, | ||
const char *exename) { |
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 exename
be converted to std::filesystem::path
while 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.
This would break downstream use of that function, figured I should do that in a separate PR. Ditto for all the cstring typing of variables that should be a path.
bool ParserOptions::searchForIncludePath(const char *&includePathOut, | ||
std::vector<cstring> userSpecifiedPaths, | ||
const std::vector<cstring> &userSpecifiedPaths, |
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.
Change to vector of std::filesystem::path
?
const char *separator = cwd[cwdLen - 1] == '/' ? "" : "/"; | ||
std::filesystem::path getExecutablePath(const std::filesystem::path &suggestedPath) { | ||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) | ||
// Find the path of the executable. We use a number of techniques that may fail or work on |
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.
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.
Figured we shouldn't depend on external dependencies for a utility like this. Particularly boost which we want to get rid of. Let me take a look at whereami
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.
Yes. Though there is bunch of domain knowledge here :(
3d7dbe3
to
6b18259
Compare
The Ubuntu failure is unrelated, should be fixed with #5177. |
I just realized that Now let's take a look into How it could be wrong without } else if (getenv("_")) {
strncpy(buffer, getenv("_"), sizeof(buffer));
buffer[sizeof(buffer) - 1] = 0;
} else { This means if we'd execute This is exactly what was in described in #3812 And the problem is that include paths could be silently dependent on the enclosing shell, etc. |
The new version should address most of these. I believe the |
I'd remove it. Together with caching it could produce wrong results. Caching should be removed as well, this way we always stuck to incorrect answer if it happen to appear first. |
Some context: #5185 (comment) At least cashing was removed in the new implementation? Unless you see caching somewhere else. |
I used to see problems with "old" version. Yes, indeed caching was removed which is good. |
} | ||
|
||
} // namespace | ||
|
||
bool ParserOptions::searchForIncludePath(const char *&includePathOut, |
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.
This functions should really get a better interface overall, the output const char *
argument that is heap-allocated is quite ugly. But I agree with doing it in a separate PR.
lib/exename.h
Outdated
* argv0 if provided and nothing better can be found */ | ||
/// Return the full path to the binary being executed. | ||
/// @returns std::nullopt if unable to determine the path. | ||
std::filesystem::path getExecutablePath(const std::filesystem::path &suggestedPath = ""); |
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.
nitpick: I would also explicitly separate the no-argument overload (let it call the normal one with empty path in the .cpp
, but let this ugly detail be hidden).
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.
So you want two functions or require always a suggested path?
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.
I suggest to have two overloads.
std::filesystem::path getExecutablePath(const std::filesystem::path &suggestedPath);
std::filesystem::path getExecutablePath();
The reason is that it is not obvious what the empty value for suggested path means (I'd say it is not natural "none" value of paths as it is not even a valid path).
If nothing else works, it is better than nothing, but I agree it should not be cached -- only a result that is definitively correct (eg, comes from /proc filesystem or syscall) should be cached. |
a305221
to
d1105a4
Compare
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Fixes #3812.
Ran into this while working on a PR. Turns out exename doesn't seem to properly work. Maybe this approach works better? Still trying to figure out the right approach for
getExecutablePath
.Also use
std::filesystem::path
to set the include path instead of char manipulation.This change preserves all APIs, still marking as breaking in case there are some differences in behavior.