-
Notifications
You must be signed in to change notification settings - Fork 462
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
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.
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>
Co-authored-by: Vladimír Štill <git@vstill.eu> Signed-off-by: Fabian Ruffy <5960321+fruffy@users.noreply.github.com>
Co-authored-by: Vladimír Štill <git@vstill.eu> Signed-off-by: Fabian Ruffy <5960321+fruffy@users.noreply.github.com>
Co-authored-by: Vladimír Štill <git@vstill.eu> Signed-off-by: Fabian Ruffy <5960321+fruffy@users.noreply.github.com>
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.