I'd like to get actual targets of dependencies in the output instead of fixed "clang-scan-deps dependency" string. My primary motivation is ease of testing the tool despite non-deterministic order of targets in its output but I assume this might be useful in general.
Details
Diff Detail
Event Timeline
Instead of basing the new -MT name off the output, can you base it on the name of the input filename instead to simplify this logic?
clang/tools/clang-scan-deps/ClangScanDeps.cpp | ||
---|---|---|
265 | Nit: Doesn't need zero initialization. |
Why "We need at least one -MT equivalent for the generator to work."?
See DependencyFileGenerator::attachToPreprocessor for the current logic.
I can but I'd like to eventually use something more robust as this will be incorrect if there's -o specified in the compilation command.
clang/tools/clang-scan-deps/ClangScanDeps.cpp | ||
---|---|---|
190 | Ooops, wrong default. |
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp | ||
---|---|---|
118–119 | Now that Targets can remain empty before DependencyPrinterConsumer::printDependencies is called (https://reviews.llvm.org/D67308) I can remove this. |
You can use the number of the compilation database entry as unique ID that won't collide.
LGTM, but please: add a CHECK somewhere that a CompilationComandIdx is actually emitted as a prefix (I don't see one now).
Thanks for doing that! But it looks odd to attach the dependencies to the output file.
clang -MD -c foo.c -o foo.o
will attach the headers/dependencies to foo.c. foo.c includes the headers. It does not attach the headers to foo.o
It will work for make-like build systems, but it looks odd.
That's a good point. I didn't think about headers and modules at all. Would you be fine with me addressing this in a separate patch?
I realized there was an issue with adding the -o /dev/null to arguemnts in case when there was a -MD flag as Driver later adds -MT with the last -o value in case there's no -MT or -MQ. That means that for headers the target would always be /dev/null.
@dexonsmith pointed out that we could just conditionally add -MT in the adjustment. Also, we can use build directory instead of CDB index.
Abandoned in favor of: https://reviews.llvm.org/D67475
...which is both cleaner and uses appropriate target value for header file dependencies.
Now that Targets can remain empty before DependencyPrinterConsumer::printDependencies is called (https://reviews.llvm.org/D67308) I can remove this.