Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/qmlformat.py: Move Qt version detection into separate function #4650

Merged
merged 1 commit into from
Jan 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions tools/qmlformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@
"""


def find_qt_version():
moc_executable = shutil.which("moc")
if not moc_executable:
return None

moc_version = subprocess.check_output((moc_executable, "-v")).strip()
matchobj = re.search("moc ([0-9]*)\\.([0-9]*)\\.[0-9]*", str(moc_version))
if not matchobj:
return None

return (int(matchobj.group(1)), int(matchobj.group(2)))


def main(argv=None):
qmlformat_executable = shutil.which("qmlformat")
if not qmlformat_executable:
# verify if qmlformat is available on this machine
moc_executable = shutil.which("moc")
if moc_executable:
moc_version = subprocess.check_output(
(moc_executable, "-v")
).strip()
v = re.search("moc ([0-9]*)\\.([0-9]*)\\.[0-9]*", str(moc_version))
if v:
version = (int(v.group(1)), int(v.group(2)))
if version < (5, 15):
# Succeed if a Qt Version < 5.15 is used without qmlformat
return 0
qt_version = find_qt_version()
if qt_version is None or qt_version < (5, 15):
# Succeed if a Qt Version < 5.15 is used without qmlformat
return 0

print(QMLFORMAT_MISSING_MESSAGE.strip(), file=sys.stderr)
return 1

Expand Down