This repository has been archived by the owner on Jan 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
portqt4to5.py
executable file
·140 lines (101 loc) · 5.7 KB
/
portqt4to5.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
import os, sys
import subprocess
qt4to5Binary = "~/dev/build/qtbase/llvm/bin/qt4to5"
cmakeBinary = "cmake"
if os.popen("git diff").read():
print "Error: must start with a clean working dir"
sys.exit(1)
# Utility functions
def execCommand(command):
print "RUNNING", command
subprocess.Popen(command, shell=True).wait()
def createCommit(message):
if not os.popen("git diff").read():
return
execCommand("git commit -am \"" + message + "\"")
execCommand("git show --stat")
def setupEnv():
os.mkdir("porting")
os.chdir("porting")
execCommand(cmakeBinary + ' .. -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE')
# Consider running make here to ensure that required generated files get generated (moc and ui files)
os.chdir("..")
if not os.path.exists("porting/compile_commands.json"):
setupEnv()
# Porting functions
def renameMethod(className, oldName, newName):
renameClass = ""
if className:
renameClass = " -rename-class=::" + className
execCommand("git grep -lw " + oldName + " | xargs " + qt4to5Binary + renameClass + " -rename-old=" + oldName + " -rename-new=" + newName + " " + os.getcwd() + " " + os.getcwd() + "/porting")
createCommit("Port uses of " + className + "::" + oldName + " to " + newName)
def portQtEscape():
execCommand("git grep -lw Qt::escape | xargs " + qt4to5Binary + " -port-qt-escape -create-ifdefs " + " " + os.getcwd() + " " + os.getcwd() + "/porting")
createCommit("Port from Qt::escape to QString::toHtmlEscaped")
def portQMetaMethodSignature():
execCommand("git grep -l \"\\.signature()\" | xargs " + qt4to5Binary + " -port-qmetamethod-signature -create-ifdefs " + os.getcwd() + " " + os.getcwd() + "/porting")
createCommit("Port from QMetaMethod::signature to methodSignature")
def replaceQVariantTemplateFunctions():
execCommand("git grep -l qVariantCanConvert | xargs sed -i 's|qVariantCanConvert<\\(\\s*[^>\\]\\+\\)>\\s*(\\s*\\([^)]\\+\\))|\\2.canConvert<\\1>()|'")
execCommand("git grep -l canConvert | xargs sed -i 's| \\.canConvert|.canConvert|'")
execCommand("git grep -l qVariantValue | xargs sed -i 's|qVariantValue<\\(\\s*[^>\\]\\+\\)>\\s*(\\s*\\([^)]\\+\\))|\\2.value<\\1>()|'")
execCommand("git grep -l \" .value\" | xargs sed -i 's| \\.value|.value|'")
createCommit("Port from QVariant free-functions to template methods")
def replaceQObjectTemplateFunctions():
execCommand("git grep -l qFindChild | xargs sed -i 's|qFindChild<\\(\\s*[^>\\]\\+\\)>\\s*(\\s*\\([^)]\\+\\))|\\2->findChild<\\1>()|'")
execCommand("git grep -l findChild | xargs sed -i 's| ->findChild|->findChild|'")
execCommand("git grep -l qFindChildren | xargs sed -i 's|qFindChildren<\\(\\s*[^>\\]\\+\\)>\\s*(\\s*\\([^)]\\+\\))|\\2->findChildren<\\1>()|'")
execCommand("git grep -l findChildren | xargs sed -i 's| ->findChildren|->findChildren|'")
createCommit("Port from QObject free-functions to template methods")
def portAtomics():
execCommand("git grep -lw QAtomicInt | xargs " + qt4to5Binary + " -port-atomics -create-ifdefs " + os.getcwd() + " " + os.getcwd() + "/porting")
createCommit("Port implicit casts of QAtomicInt and QAtomicPointer")
def portViews():
execCommand("git grep -lw dataChanged | xargs " + qt4to5Binary + " -port-qabstractitemview-datachanged -create-ifdefs " + os.getcwd() + " " + os.getcwd() + "/porting")
createCommit("Port QAbstractItemView::dataChanged")
def portEnum(scope, printedScope, oldName, newName):
execCommand("git grep -lw " + oldName + " | xargs " + qt4to5Binary + " -rename-enum=" + scope + " --create-ifdefs -rename-old=" + oldName + " -rename-new=" + printedScope + "::" + newName + " " + os.getcwd() + " " + os.getcwd() + "/porting")
createCommit("Port uses of " + printedScope + "::" + oldName + " to " + newName)
def portQImageText():
execCommand("git grep -l \"text(.\\+0\\s*)\" | xargs " + qt4to5Binary + " -port-qimage-text " + os.getcwd() + " " + os.getcwd() + "/porting")
execCommand("git grep -l \"setText(.\\+0.\\+)\" | xargs " + qt4to5Binary + " -port-qimage-text " + os.getcwd() + " " + os.getcwd() + "/porting")
createCommit("Port uses of QImage::text and QImage::setText.")
## Pre-porting steps. These can be done before porting to Qt 5 (eg port away from deprecated methods).
def portFromQt3Support():
renameMethod("QTransform", "det", "determinant")
renameMethod("QWidget", "setShown", "setVisible")
renameMethod("QWidget", "setIcon", "setWindowIcon")
def portFromQt4Deprecated():
portQImageText()
portViews()
renameMethod("QPaintDevice", "numColors", "colorCount")
renameMethod("QImage", "numColors", "colorCount")
renameMethod("QImage", "setNumColors", "setColorCount")
renameMethod("", "qMemCopy", "memcpy")
renameMethod("QImage", "numBytes", "byteCount")
renameMethod("QDate", "setYMD", "setDate")
renameMethod("QRegion", "unite", "united")
renameMethod("QRect", "unite", "united")
renameMethod("QRegion", "intersect", "intersected")
renameMethod("QRect", "intersect", "intersected")
renameMethod("QFont", "removeSubstitution", "removeSubstitutions")
renameMethod("QHeaderView", "setClickable", "setSectionsClickable")
replaceQVariantTemplateFunctions()
replaceQObjectTemplateFunctions()
## Porting steps
def port4to5():
portQMetaMethodSignature()
#portAtomics()
##Post porting. Porting away from deprecated API
def portFromQt5Deprecated():
portQtEscape()
portEnum("QSsl::SslProtocol", "QSsl", "TlsV1", "TlsV1_0")
renameMethod("QHeaderView", "setResizeMode", "setSectionResizeMode")
renameMethod("QHeaderView", "setMovable", "setSectionsMovable")
renameMethod("QSslCertificate", "alternateSubjectNames", "subjectAlternativeNames")
# These function invokations do the actual porting.
portFromQt3Support()
portFromQt4Deprecated()
port4to5()
portFromQt5Deprecated()