Launch processes described by invocations.
(invocations, verbose, formatter, jobs)
| 351 | |
| 352 | |
| 353 | def execute(invocations, verbose, formatter, jobs): |
| 354 | """ Launch processes described by invocations. """ |
| 355 | exit_code = 0 |
| 356 | if jobs == 1: |
| 357 | for invocation in invocations: |
| 358 | proc = invocation.start(verbose) |
| 359 | print(formatter(proc.get_output()), end = "") |
| 360 | if proc.returncode != 2: |
| 361 | print("\n\033[91mfailure: \033[0m" + proc.source_file) |
| 362 | print(formatter(proc.get_output()), end = "") |
| 363 | exit_code = 1 |
| 364 | else: |
| 365 | print("\033[92msuccess: \033[0m" + proc.source_file) |
| 366 | return exit_code |
| 367 | |
| 368 | pending = [] |
| 369 | while invocations or pending: |
| 370 | # Collect completed IWYU processes and print results. |
| 371 | complete = [proc for proc in pending if proc.poll() is not None] |
| 372 | for proc in complete: |
| 373 | pending.remove(proc) |
| 374 | if proc.returncode != 2: |
| 375 | print("\n\033[91mfailure: \033[0m" + proc.source_file) |
| 376 | print(formatter(proc.get_output()), end = "") |
| 377 | return 1 |
| 378 | else: |
| 379 | print("\033[92msuccess: \033[0m" + proc.source_file) |
| 380 | |
| 381 | # Schedule new processes if there's room. |
| 382 | capacity = jobs - len(pending) |
| 383 | pending.extend(i.start(verbose) for i in invocations[:capacity]) |
| 384 | invocations = invocations[capacity:] |
| 385 | |
| 386 | # Yield CPU. |
| 387 | time.sleep(0.0001) |
| 388 | return exit_code |
| 389 | |
| 390 | |
| 391 | def main(compilation_db_path, source_files, verbose, formatter, jobs, |
no test coverage detected