|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +from __future__ import print_function |
| 4 | + |
| 5 | +import os |
| 6 | +import re |
| 7 | +import select |
| 8 | +import subprocess |
| 9 | +import sys |
| 10 | + |
| 11 | +def find_makefile_dirs(): |
| 12 | + makefile_dirs = [] |
| 13 | + for root, dirs, files in os.walk("."): |
| 14 | + for file in files: |
| 15 | + if file == "Makefile": |
| 16 | + makefile_dirs.append(root) |
| 17 | + return makefile_dirs |
| 18 | + |
| 19 | +_TESTDIR_RELATIVE_REGEX = re.compile(r"^([^/:]+:\d+:)") |
| 20 | + |
| 21 | +def filter_run_line(sub_expr, line): |
| 22 | + return _TESTDIR_RELATIVE_REGEX.sub(sub_expr, line) |
| 23 | + |
| 24 | +def call_make(makefile_dir, extra_args=None): |
| 25 | + command = ["make", "-C", makefile_dir] |
| 26 | + if extra_args: |
| 27 | + command.extend(extra_args) |
| 28 | + |
| 29 | + # Replace the matched no-directory filename with one where the makefile directory is prepended. |
| 30 | + sub_expr = makefile_dir + r"/\1"; |
| 31 | + |
| 32 | + proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 33 | + |
| 34 | + while True: |
| 35 | + reads = [proc.stdout.fileno(), proc.stderr.fileno()] |
| 36 | + select_result = select.select(reads, [], []) |
| 37 | + |
| 38 | + for fd in select_result[0]: |
| 39 | + if fd == proc.stdout.fileno(): |
| 40 | + line = proc.stdout.readline() |
| 41 | + print(filter_run_line(sub_expr, line.rstrip())) |
| 42 | + elif fd == proc.stderr.fileno(): |
| 43 | + line = proc.stderr.readline() |
| 44 | + print(filter_run_line(sub_expr, line.rstrip()), file=sys.stderr) |
| 45 | + |
| 46 | + proc_retval = proc.poll() |
| 47 | + if proc_retval != None: |
| 48 | + # Process stopped. Drain output before finishing up. |
| 49 | + |
| 50 | + # Drain stdout. |
| 51 | + while True: |
| 52 | + line = proc.stdout.readline() |
| 53 | + if line: |
| 54 | + print(filter_run_line(sub_expr, line.rstrip())) |
| 55 | + else: |
| 56 | + break |
| 57 | + |
| 58 | + # Drain stderr. |
| 59 | + while True: |
| 60 | + line = proc.stderr.readline() |
| 61 | + if line: |
| 62 | + print(filter_run_line(sub_expr, line.rstrip()), file=sys.stderr) |
| 63 | + else: |
| 64 | + break |
| 65 | + |
| 66 | + return proc_retval |
| 67 | + |
| 68 | + |
| 69 | +global_retval = 0 |
| 70 | +extra_args = None |
| 71 | + |
| 72 | +if len(sys.argv) > 1: |
| 73 | + if sys.argv[1] == 'clean': |
| 74 | + extra_args = ['clean'] |
| 75 | + |
| 76 | +for makefile_dir in find_makefile_dirs(): |
| 77 | + print("found makefile dir: {}".format(makefile_dir)) |
| 78 | + retval = call_make(makefile_dir, extra_args) |
| 79 | + if retval != 0: |
| 80 | + global_retval = retval |
| 81 | + |
| 82 | +sys.exit(global_retval) |
0 commit comments