2018-10-24 13:20:27 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-05-10 10:06:48 +00:00
|
|
|
# Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import typing
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_commandline():
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
parser = ArgumentParser(description="Calculate the conversion rate to cmake.")
|
|
|
|
parser.add_argument("--debug", dest="debug", action="store_true", help="Turn on debug output")
|
|
|
|
parser.add_argument(
|
|
|
|
"source_directory",
|
|
|
|
metavar="<Source Directory>",
|
|
|
|
type=str,
|
|
|
|
help="The Qt module source directory",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"binary_directory",
|
2022-06-10 14:41:59 +00:00
|
|
|
metavar="<CMake build directory>",
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
type=str,
|
|
|
|
help="The CMake build directory (might be empty)",
|
|
|
|
)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
def calculate_baseline(source_directory: str, *, debug: bool = False) -> int:
|
2018-10-24 13:20:27 +00:00
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f'Scanning "{source_directory}" for qmake-based tests.')
|
|
|
|
result = subprocess.run(
|
|
|
|
'/usr/bin/git grep -E "^\\s*CONFIG\\s*\\+?=.*\\btestcase\\b" | sort -u | wc -l',
|
|
|
|
shell=True,
|
|
|
|
capture_output=True,
|
|
|
|
cwd=source_directory,
|
|
|
|
)
|
2018-10-24 13:20:27 +00:00
|
|
|
return int(result.stdout)
|
|
|
|
|
|
|
|
|
|
|
|
def build(source_directory: str, binary_directory: str, *, debug=False) -> None:
|
|
|
|
abs_source = os.path.abspath(source_directory)
|
|
|
|
if not os.path.isdir(binary_directory):
|
|
|
|
os.makedirs(binary_directory)
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
if not os.path.exists(os.path.join(binary_directory, "CMakeCache.txt")):
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f'Running cmake in "{binary_directory}"')
|
|
|
|
result = subprocess.run(["/usr/bin/cmake", "-GNinja", abs_source], cwd=binary_directory)
|
2018-10-24 13:20:27 +00:00
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f"CMake return code: {result.returncode}.")
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
assert result.returncode == 0
|
|
|
|
|
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f'Running ninja in "{binary_directory}".')
|
|
|
|
result = subprocess.run("/usr/bin/ninja", cwd=binary_directory)
|
2018-10-24 13:20:27 +00:00
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f"Ninja return code: {result.returncode}.")
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
assert result.returncode == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test(binary_directory: str, *, debug=False) -> typing.Tuple[int, int]:
|
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f'Running ctest in "{binary_directory}".')
|
|
|
|
result = subprocess.run(
|
|
|
|
'/usr/bin/ctest -j 250 | grep "tests passed, "',
|
|
|
|
shell=True,
|
|
|
|
capture_output=True,
|
|
|
|
cwd=binary_directory,
|
|
|
|
)
|
|
|
|
summary = result.stdout.decode("utf-8").replace("\n", "")
|
2018-10-24 13:20:27 +00:00
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f"Test summary: {summary} ({result.returncode}).")
|
2018-10-24 13:20:27 +00:00
|
|
|
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
matches = re.fullmatch(r"\d+% tests passed, (\d+) tests failed out of (\d+)", summary)
|
2018-10-24 13:20:27 +00:00
|
|
|
if matches:
|
|
|
|
if debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f"Matches: failed {matches.group(1)}, total {matches.group(2)}.")
|
|
|
|
return (int(matches.group(2)), int(matches.group(2)) - int(matches.group(1)))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
return (0, 0)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
|
|
|
args = _parse_commandline()
|
|
|
|
|
|
|
|
base_line = calculate_baseline(args.source_directory, debug=args.debug)
|
|
|
|
if base_line <= 0:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f"Could not find the qmake baseline in {args.source_directory}.")
|
2018-10-24 13:20:27 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
if args.debug:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f"qmake baseline: {base_line} test binaries.")
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
cmake_total = 0
|
|
|
|
cmake_success = 0
|
|
|
|
try:
|
|
|
|
build(args.source_directory, args.binary_directory, debug=args.debug)
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
(cmake_total, cmake_success) = test(args.binary_directory, debug=args.debug)
|
2018-10-24 13:20:27 +00:00
|
|
|
finally:
|
|
|
|
if cmake_total == 0:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print("\n\n\nCould not calculate the cmake state.")
|
2018-10-24 13:20:27 +00:00
|
|
|
return 2
|
|
|
|
else:
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
print(f"\n\n\nCMake test conversion rate: {cmake_total/base_line:.2f}.")
|
|
|
|
print(f"CMake test success rate : {cmake_success/base_line:.2f}.")
|
2018-10-24 13:20:27 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-09-16 22:11:17 +00:00
|
|
|
if __name__ == "__main__":
|
2018-10-24 13:20:27 +00:00
|
|
|
main()
|