Skip to content

Commit

Permalink
Merge pull request #4650 from Holzhaus/qmlformat-cleanup
Browse files Browse the repository at this point in the history
tools/qmlformat.py: Move Qt version detection into separate function
  • Loading branch information
uklotzde authored Jan 29, 2022
2 parents ca1e324 + 98648eb commit d0449ae
Showing 1 changed file with 18 additions and 12 deletions.
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

0 comments on commit d0449ae

Please sign in to comment.