-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-scan-deps] Expand response files before the argument adjuster #89950
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
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Alexandre Ganea (aganea) ChangesPreviously, since response (.rsp) files weren't expanded at the very beginning of clang-scan-deps, we only parsed the command-line as provided in the Clang .cdb file. Unfortunately, when using Unreal Engine, arguments are always generated in a .rsp file (ie. After this patch, Full diff: https://github.com/llvm/llvm-project/pull/89950.diff 1 Files Affected:
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17a..7b7f10c4be7421 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
llvm::cl::PrintOptionValues();
+ // Expand response files in advance, so that we can "see" all the arguments
+ // when adjusting below.
+ auto ResponseExpander = expandResponseFiles(std::move(Compilations),
+ llvm::vfs::getRealFileSystem());
+
// The command options are rewritten to run Clang in preprocessor only mode.
auto AdjustingCompilations =
std::make_unique<tooling::ArgumentsAdjustingCompilations>(
- std::move(Compilations));
+ std::move(ResponseExpander));
ResourceDirectoryCache ResourceDirCache;
AdjustingCompilations->appendArgumentsAdjuster(
|
This is missing a test, I will add one. |
This change makes sense to me, but I forget what's the purpose of the whole output path deducing code. Even for |
No, even then we should deduce the output path: llvm-project/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp Lines 378 to 400 in a45eb62
|
The reason of this |
Hmm, that driver code is only executed if the dependency file was requested on the Clang command line, though. In general yes, I'd prefer to solve this wherever we have access to properly parsed command line (or |
@jansvoboda11 PTAL. I've added handling of @sylvain-audi worked around that by adding I'm not sure that's right either, ideally we should pass |
// RUN: rm -rf %t | ||
// RUN: split-file %s %t | ||
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json | ||
// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp |
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 tried playing around with response files and they don't play well with newlines. I think that instead of appending to the response files with echo
, we should use split-file
and create two separate files. That will also be more declarative and will make it obvious that one contains /c
and the other /E
.
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 you elaborate please on "I tried playing around with response files and they don't play well with newlines"?
Things were working on my end (empty lines in .rsp files). Also, Unreal Engine generates .rsp files with each argument on a new line, so if you're seeing any issues there we shall fix them.
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 recall running %clang_cl
with whatever arguments and response files this test generated and seeing Clang's argument parser hit an assertion while working with the expanded arguments.
@jansvoboda11 Do you see any further changes for this PR? Can I land it? |
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.
LGTM, thanks!
Previously, since response (.rsp) files weren't expanded, we only parsed the command-line as provided in the Clang CDB file. Unfortunately, when using Unreal Engine, arguments are always generated in a .rsp file. After this patch, /Fo can be parsed and added to the final command-line. Without this option, the make targets that are emitted are made up from the input file name alone. We have some cases where the same input in the project generates several output files, so we end up with duplicate make targets in the scan-deps emitted dependency file.
Also fix stack-allocated `CommandLine` entries when using a InplaceCompilationDatabase
3d9e71c
to
7b6f573
Compare
Previously, since response (.rsp) files weren't expanded at the very beginning of clang-scan-deps, we only parsed the command-line as provided in the Clang .cdb file. Unfortunately, when using Unreal Engine, arguments are always generated in a .rsp file (ie.
/path/to/clang-cl.exe @/path/to/filename_args.rsp
).After this patch,
/Fo
can be parsed and added to the final command-line. Without this option, the make targets that are emitted are made up from the input file name alone. We have some cases where the same input in the project generates several output files, so we end up with duplicate make targets in the scan-deps emitted dependency file.