Skip to content

Commit 1995579

Browse files
authored
Merge pull request #2200 from hzeller/feature-20240613-no-update-no-tty
clang-tidy-cached: don't output progress updates if not isatty()
2 parents 23cda0c + 77ba798 commit 1995579

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

.github/bin/run-clang-tidy-cached.cc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,28 @@ class ClangTidyRunner {
153153
const fs::path &project_cache_dir() const { return project_cache_dir_; }
154154

155155
// Given a work-queue in/out-file, process it. Using system() for portability.
156+
// Empties work_queue.
156157
void RunClangTidyOn(ContentAddressedStore &output_store,
157-
std::list<filepath_contenthash_t> work_queue) {
158-
if (work_queue.empty()) return;
158+
std::list<filepath_contenthash_t> *work_queue) {
159+
if (work_queue->empty()) return;
159160
const int kJobs = std::thread::hardware_concurrency();
160-
std::cerr << work_queue.size() << " files to process...";
161+
std::cerr << work_queue->size() << " files to process...";
162+
163+
const bool print_progress = isatty(STDERR_FILENO);
164+
if (!print_progress) std::cerr << "\n";
161165

162166
std::mutex queue_access_lock;
163167
auto clang_tidy_runner = [&]() {
164168
for (;;) {
165169
filepath_contenthash_t work;
166170
{
167171
const std::lock_guard<std::mutex> lock(queue_access_lock);
168-
if (work_queue.empty()) return;
169-
fprintf(stderr, "%5d\b\b\b\b\b", static_cast<int>(work_queue.size()));
170-
work = work_queue.front();
171-
work_queue.pop_front();
172+
if (work_queue->empty()) return;
173+
if (print_progress) {
174+
fprintf(stderr, "%5d\b\b\b\b\b", (int)(work_queue->size()));
175+
}
176+
work = work_queue->front();
177+
work_queue->pop_front();
172178
}
173179
const fs::path final_out = output_store.PathFor(work);
174180
const std::string tmp_out = final_out.string() + ".tmp";
@@ -196,7 +202,9 @@ class ClangTidyRunner {
196202
workers.emplace_back(clang_tidy_runner); // NOLINT
197203
}
198204
for (auto &t : workers) t.join();
199-
fprintf(stderr, " \n"); // Clean out progress counter.
205+
if (print_progress) {
206+
fprintf(stderr, " \n"); // Clean out progress counter.
207+
}
200208
}
201209

202210
private:
@@ -365,7 +373,7 @@ int main(int argc, char *argv[]) {
365373

366374
FileGatherer cc_file_gatherer(store, kSearchDir);
367375
auto work_list = cc_file_gatherer.BuildWorkList(build_env_latest_change);
368-
runner.RunClangTidyOn(store, work_list);
376+
runner.RunClangTidyOn(store, &work_list);
369377
auto checks_seen =
370378
cc_file_gatherer.CreateReport(runner.project_cache_dir(), kTidySymlink);
371379

0 commit comments

Comments
 (0)