-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Tooling] Fix misleading progress report when files have multiple compile commands #169640
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
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-clang Author: mitchell (zeyi2) ChangesThis patch fixes an issue in progress reporting where the processed item counter could exceed the total item count, leading to confusing outputs like [22/18]. Full diff: https://github.com/llvm/llvm-project/pull/169640.diff 1 Files Affected:
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 9bae12454d2dc..491294b731e85 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -37,6 +37,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptTable.h"
@@ -96,7 +97,7 @@ static bool ignoreExtraCC1Commands(const driver::Compilation *Compilation) {
OffloadCompilation = true;
if (Jobs.size() > 1) {
- for (auto *A : Actions){
+ for (auto *A : Actions) {
// On MacOSX real actions may end up being wrapped in BindArchAction
if (isa<driver::BindArchAction>(A))
A = *A->input_begin();
@@ -413,8 +414,8 @@ bool ToolInvocation::run() {
Driver->BuildCompilation(llvm::ArrayRef(Argv)));
if (!Compilation)
return false;
- const llvm::opt::ArgStringList *const CC1Args = getCC1Arguments(
- &*Diagnostics, Compilation.get());
+ const llvm::opt::ArgStringList *const CC1Args =
+ getCC1Arguments(&*Diagnostics, Compilation.get());
if (!CC1Args)
return false;
std::unique_ptr<CompilerInvocation> Invocation(
@@ -497,9 +498,7 @@ void ClangTool::appendArgumentsAdjuster(ArgumentsAdjuster Adjuster) {
ArgsAdjuster = combineAdjusters(std::move(ArgsAdjuster), std::move(Adjuster));
}
-void ClangTool::clearArgumentsAdjusters() {
- ArgsAdjuster = nullptr;
-}
+void ClangTool::clearArgumentsAdjusters() { ArgsAdjuster = nullptr; }
static void injectResourceDir(CommandLineArguments &Args, const char *Argv0,
void *MainAddr) {
@@ -555,8 +554,9 @@ int ClangTool::run(ToolAction *Action) {
}
size_t NumOfTotalFiles = AbsolutePaths.size();
- unsigned ProcessedFileCounter = 0;
+ unsigned CurrentFileIndex = 0;
for (llvm::StringRef File : AbsolutePaths) {
+ ++CurrentFileIndex; // Increment file counter once per file.
// Currently implementations of CompilationDatabase::getCompileCommands can
// change the state of the file system (e.g. prepare generated headers), so
// this method needs to run right before we invoke the tool, as the next
@@ -571,6 +571,7 @@ int ClangTool::run(ToolAction *Action) {
FileSkipped = true;
continue;
}
+ unsigned CurrentCommandIndexForFile = 0;
for (CompileCommand &CompileCommand : CompileCommandsForFile) {
// If the 'directory' field of the compilation database is empty, display
// an error and use the working directory instead.
@@ -617,12 +618,16 @@ int ClangTool::run(ToolAction *Action) {
// pass in made-up names here. Make sure this works on other platforms.
injectResourceDir(CommandLine, "clang_tool", &StaticSymbol);
+ ++CurrentCommandIndexForFile;
+
// FIXME: We need a callback mechanism for the tool writer to output a
// customized message for each file.
- if (NumOfTotalFiles > 1)
- llvm::errs() << "[" + std::to_string(++ProcessedFileCounter) + "/" +
- std::to_string(NumOfTotalFiles) +
- "] Processing file " + File
+ if (NumOfTotalFiles > 1 || CompileCommandsForFile.size() > 1)
+ llvm::errs() << "[" + std::to_string(CurrentFileIndex) + "/" +
+ std::to_string(NumOfTotalFiles) + "] (" +
+ std::to_string(CurrentCommandIndexForFile) + "/" +
+ std::to_string(CompileCommandsForFile.size()) +
+ ") Processing file " + File
<< ".\n";
ToolInvocation Invocation(std::move(CommandLine), Action, Files.get(),
PCHContainerOps);
|
|
I believe this patch needs some discussion, for it introduces a new format: I initially considered (and implemented) a solution that does normal printing like
The current patch maintains the O(1) complexity and doesn't violate the API usage, while still reflect the correct progress without misleading users. I understand that this may not be an ideal way of solving this problem. I highly value any thoughts or feedback on this implementation or potential alternative strategies. Thanks in advance. |
It seems that removing |
|
Thanks for feedback! I've changed the printing to: |
|
Friendly ping, please take a look at this small PR when you have a time :) Thanks! |
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 we make any tests for this new format?
If the user can see it - we should be able to cover it, could be test in clang-tidy infrastructure/ (test different scenarios).
|
Looks like there is a path separators issue. I'm trying to fix it, will ping for another review after the fix is done :) |
Fixed now. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
|
I didn't find an immediate maintainer of core tooling files; could you look at git log to see who reviewed/committed in these files. |
|
Hi, Aaron. Could you please review this patch? It fixes a misleading progress report issue in Tooling (e.g. I have addressed previous feedback from vbvictor and zwuis, could you do some furthur reviews? Thanks for your time. |
|
The failed testcase seems unrelated to this PR (again), I'll try rebase onto main later. |
AaronBallman
left a comment
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.
The changes seem pretty reasonable but there's a fair amount of unrelated formatting changes. It'd be easier on reviewers to back those unrelated changes out so we can more easily see just what's been materially modified.
66079d8 to
1df1da5
Compare
Sorry for the noise, I've cleanup the modification in |
AaronBallman
left a comment
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, thank you!
This patch fixes an issue in progress reporting where the processed item counter could exceed the total item count, leading to confusing outputs like [22/18].
Closes #169168