30 from argparse
import ArgumentParser
38 def _parse_commandline():
39 parser = ArgumentParser(description=
"Calculate the conversion rate to cmake.")
40 parser.add_argument(
"--debug", dest=
"debug", action=
"store_true", help=
"Turn on debug output")
43 metavar=
"<Source Directory>",
45 help=
"The Qt module source directory",
49 metavar=
"<CMake build direcotry>",
51 help=
"The CMake build directory (might be empty)",
54 return parser.parse_args()
59 print(f
'Scanning "{source_directory}" for qmake-based tests.')
60 result = subprocess.run(
61 '/usr/bin/git grep -E "^\\s*CONFIG\\s*\\+?=.*\\btestcase\\b" | sort -u | wc -l',
66 return int(result.stdout)
69 def build(source_directory: str, binary_directory: str, *, debug=
False) ->
None:
70 abs_source = os.path.abspath(source_directory)
71 if not os.path.isdir(binary_directory):
72 os.makedirs(binary_directory)
73 if not os.path.exists(os.path.join(binary_directory,
"CMakeCache.txt")):
76 print(f
'Running cmake in "{binary_directory}"')
77 result = subprocess.run([
"/usr/bin/cmake",
"-GNinja", abs_source], cwd=binary_directory)
79 print(f
"CMake return code: {result.returncode}.")
81 assert result.returncode == 0
84 print(f
'Running ninja in "{binary_directory}".')
85 result = subprocess.run(
"/usr/bin/ninja", cwd=binary_directory)
87 print(f
"Ninja return code: {result.returncode}.")
89 assert result.returncode == 0
92 def test(binary_directory: str, *, debug=
False) -> typing.Tuple[int, int]:
94 print(f
'Running ctest in "{binary_directory}".')
95 result = subprocess.run(
96 '/usr/bin/ctest -j 250 | grep "tests passed, "',
101 summary = result.stdout.decode(
"utf-8").replace(
"\n",
"")
103 print(f
"Test summary: {summary} ({result.returncode}).")
105 matches = re.fullmatch(
r"\d+% tests passed, (\d+) tests failed out of (\d+)", summary)
108 print(f
"Matches: failed {matches.group(1)}, total {matches.group(2)}.")
109 return (int(matches.group(2)), int(matches.group(2)) - int(matches.group(1)))
115 args = _parse_commandline()
119 print(f
"Could not find the qmake baseline in {args.source_directory}.")
123 print(f
"qmake baseline: {base_line} test binaries.")
128 build(args.source_directory, args.binary_directory, debug=args.debug)
129 (cmake_total, cmake_success) =
test(args.binary_directory, debug=args.debug)
132 print(
"\n\n\nCould not calculate the cmake state.")
135 print(f
"\n\n\nCMake test conversion rate: {cmake_total/base_line:.2f}.")
136 print(f
"CMake test success rate : {cmake_success/base_line:.2f}.")
140 if __name__ ==
"__main__":
None build(str source_directory, str binary_directory, *debug=False)
typing.Tuple[int, int] test(str binary_directory, *debug=False)
int calculate_baseline(str source_directory, *bool debug=False)