File: check_header.py

package info (click to toggle)
quantlib 1.40-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 41,768 kB
  • sloc: cpp: 398,987; makefile: 6,574; python: 214; sh: 150; lisp: 86
file content (32 lines) | stat: -rwxr-xr-x 844 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python -u

import multiprocessing as mp
import os
import sys
import shutil


def check(header):
    cxx = os.environ.get("CXX", "g++")
    source_file = header + ".cpp"
    shutil.copy(header, source_file)
    object_file = header + ".o"
    command = f"{cxx} -std=c++17 -c -Wno-unknown-pragmas -Wall -Werror -I. {source_file} -o {object_file}"
    print(command, file=sys.stderr)
    code = os.system(command)
    try:
        os.remove(source_file)
        os.remove(object_file)
    except:
        pass
    if code != 0:
        print(f"Errors while checking {header}", file=sys.stderr)
        return 1
    return 0


if __name__ == "__main__":
    headers = [line.strip() for line in sys.stdin.readlines()]
    with mp.Pool(processes=mp.cpu_count()) as pool:
        errors = sum(pool.map(check, headers))
    sys.exit(errors)