-
Notifications
You must be signed in to change notification settings - Fork 102
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
Change working directory of C++ parser #572
base: master
Are you sure you want to change the base?
Conversation
Fixes compilation commands containing relative paths not getting parsed properly.
Reverts functional change of 04826d2 as it's no longer necessary.
It turns out there's a bug I didn't catch: if the build directory doesn't exist, the parsing fails, because |
I do not understand this. How is it possible to have a build generated with CMake (which creates directory structures) or logged (in which case the build was executed and should have created the directories) but do not have the "build directory" (what does this refer to?) exist? Is it meaningful to parse a file in such a context? If the directory where the build was executed (is this what "build directory" refers to?) doesn't even exist, how was the build executed? We'll end up having issues with (potentially generated?) files gone missing... In general, I would prefer if we tried not to reimplement things from LLVM too much, unless really needed. We're way behind the upstream and all these reimplements will cause problems when we try supporting newer releases of Ubuntu even. Perhaps we could either create the directory, or give a hard error and have the user reconsider what they messed up with their build system... |
Okay, I tried giving a second read to the patch itself but I am still confused. What do we need the |
It can happen if the build directory is selectively transferred between computers, like what happens on the CI where we zip up just the source files. The build directory (where CMake was invoked) exists here actually, but the compilation directory (
We can have the compilation dependencies all intact with only compilation directories containing none missing, which is what happened on the CI.
Oh, I didn't mean reimplementing it from scratch, just creating a wrapper
Yes, it
I don't think that would work. But even if it worked, I think my "redirecting wrapper class" idea is more straightforward. |
Fixes the previous implementation not working if compilation directories are missing.
Oh, there is CodeCompass/plugins/cpp_reparse/service/src/databasefilesystem.cpp Lines 248 to 261 in 83a6a9a
And in this case, almost none (apart from Clang's own intrinsic headers that install with CodeCompass...) of the directories exist on the server. And the overlay is passed to CodeCompass/plugins/cpp_reparse/service/src/reparser.cpp Lines 174 to 176 in 83a6a9a
|
The reason missing directories never caused an issue with reparse is because it doesn't set the working directory properly. It's using the default value of
|
This name reflects its purpose better.
The reparser needs this information to correctly execute its commands.
The reparser properly supports relative paths now. I had to add a new table to the database ( I decided to scrap the For parsing to fail, a build command needs to have its directory missing and use a relative path. I don't think it's worth going out of our way to recover from this scenario given how unlikely it is. You suggested creating the build directory, but I think the parser shouldn't modify its inputs. |
struct BuildAction; | ||
|
||
#pragma db object | ||
struct BuildDirectory |
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'm not sure why this has to be a brand new table, foreign key, and all that jazz for the storage. BuildAction
already contains string command;
, for example. If "directory"
is just another member of the entries in a compilation database JSON (just like "command"
), then why isn't this reflected in the schema? Every build action MUST have a build directory (it just may or may not exist or point to anything meaningful).
This struct, as it is now, won't do uniqueing of build directories either, because it is the build directory that refers to one build action each. If we want a separate record to only store one directory ("string") exactly once, then it is the buildaction that has to refer into this relation's key.
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 wanted to keep backwards compatibility with existing databases, that's why I didn't want to change BuildAction
's schema. Is that not a priority? In that case you're right, storing it in BuildAction
would make more sense.
Deduplicating the strings is not worth the hassle, in the CodeCompass SQLite database BuildAction
only takes up 0.012% of the space.
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.
We can easily reparse projects, backward-compatibility with existing databases is not a high priority.
The PR should also handle relative paths for the As part of #637, it was discover that in case the |
This PR makes Clang tool invocations use the working directories of each compilation command. This fixes relative paths in arguments not being handled properly (#571), as previously the tool ran in the default working directory of
.
.Callers of
SourceManager::getFile
incppparser
were changed to provide an absolute path.Additionally, inaccurate comments in
SourceManager::getFile
were corrected.