@@ -153,22 +153,28 @@ class ClangTidyRunner {
153
153
const fs::path &project_cache_dir () const { return project_cache_dir_; }
154
154
155
155
// Given a work-queue in/out-file, process it. Using system() for portability.
156
+ // Empties work_queue.
156
157
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 ;
159
160
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 " ;
161
165
162
166
std::mutex queue_access_lock;
163
167
auto clang_tidy_runner = [&]() {
164
168
for (;;) {
165
169
filepath_contenthash_t work;
166
170
{
167
171
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 ();
172
178
}
173
179
const fs::path final_out = output_store.PathFor (work);
174
180
const std::string tmp_out = final_out.string () + " .tmp" ;
@@ -196,7 +202,9 @@ class ClangTidyRunner {
196
202
workers.emplace_back (clang_tidy_runner); // NOLINT
197
203
}
198
204
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
+ }
200
208
}
201
209
202
210
private:
@@ -365,7 +373,7 @@ int main(int argc, char *argv[]) {
365
373
366
374
FileGatherer cc_file_gatherer (store, kSearchDir );
367
375
auto work_list = cc_file_gatherer.BuildWorkList (build_env_latest_change);
368
- runner.RunClangTidyOn (store, work_list);
376
+ runner.RunClangTidyOn (store, & work_list);
369
377
auto checks_seen =
370
378
cc_file_gatherer.CreateReport (runner.project_cache_dir (), kTidySymlink );
371
379
0 commit comments