-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathqtprebuild.lua
284 lines (239 loc) · 8 KB
/
qtprebuild.lua
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/local/bin/lua5.1
--
-- Copyright 2023 Milos Tosic. All rights reserved.
-- License: http://www.opensource.org/licenses/BSD-2-Clause
--
-- Based on script from Kyle Hendricks <[email protected]> and
-- Josh Lareau <[email protected]>
-- ----------------------------------------------------------------------------
RTM_QT_FILES = "../.qt"
RTM_QT_FILES_PATH_MOC = "../.qt/qt_moc"
RTM_QT_FILES_PATH_UI = "../.qt/qt_ui"
RTM_QT_FILES_PATH_QRC = "../.qt/qt_qrc"
RTM_QT_FILES_PATH_TS = "../.qt/qt_qm"
local qtDirectory = ""
qtDirectory = arg[3] or qtDirectory
lua_version = _VERSION:match(" (5%.[123])$") or "5.1"
windows = package.config:sub( 1, 1 ) == "\\"
windowsExe = ".exe"
del = "\\"
if not windows then
del = "/"
windowsExe = ""
end
-- Check if a file exists
function file_exists(file)
if file == nil then return false end
local ok, err, code = os.rename(file, file)
if not ok then
if code == 13 then -- Permission denied, but it exists
return true
end
end
return ok, err
end
--
function file_isdir(path)
return file_exists(path.."/")
end
--
function mkdir(_dirname)
local dir = _dirname
if windows then
dir = string.gsub( _dirname, "([/]+)", "\\" )
else
dir = string.gsub( _dirname, "\\\\", "\\" )
end
if not file_isdir(dir) then
if not windows then
os.execute("mkdir -p " .. dir)
else
os.execute("mkdir " .. dir)
end
end
end
--
findLast = function(str, what, plain)
plain = plain or true
local lastMatch = 1
local result = -1
local thisMatch
while lastMatch ~= -1 do
thisMatch = str:find(what, lastMatch, plain)
if thisMatch == nil then
lastMatch = -1
else
result = thisMatch
lastMatch = result + 1
end
end
return result
end
local sourceDir = ""
if arg[2] ~= nil then
local projName = arg[4]
sourceDir = arg[2]:sub(1, findLast(arg[2], projName .. "/") + string.len(projName))
sourceDir = sourceDir .. "src/"
end
function BuildErrorWarningString( line, isError, message, code )
if windows then
return string.format( "qtprebuild.lua(%i): %s %i: %s", line, isError and "error" or "warning", code, message )
else
return string.format( "qtprebuild.lua:%i: %s: %s", line, isError and "error" or "warning", message )
end
end
--Make sure there are at least 2 arguments
if not ( #arg >= 2 ) then
print( BuildErrorWarningString( debug.getinfo(1).currentline, true, "There must be at least 2 arguments supplied", 2 ) ); io.stdout:flush()
return
end
--Checks that the first argument is either "-moc", "-uic", or "-rcc"
if not ( arg[1] == "-moc" or arg[1] == "-uic" or arg[1] == "-rcc" or arg[1] == "-ts" ) then
print( BuildErrorWarningString( debug.getinfo(1).currentline, true, [[The first argument must be "-moc", "-uic", "-rcc" or "-ts"]], 3 ) ); io.stdout:flush()
return
end
--Make sure input file exists
--if not file_exists(arg[2]) then
-- print( BuildErrorWarningString( debug.getinfo(1).currentline, true, [[The supplied input file ]]..arg[2]..[[, does not exist]], 4 ) ); io.stdout:flush()
-- return
--end
qtOutputDirectory = sourceDir .. RTM_QT_FILES
qtMocOutputDirectory = sourceDir .. RTM_QT_FILES_PATH_MOC
qtUIOutputDirectory = sourceDir .. RTM_QT_FILES_PATH_UI
qtQRCOutputDirectory = sourceDir .. RTM_QT_FILES_PATH_QRC
qtTSOutputDirectory = sourceDir .. RTM_QT_FILES_PATH_TS
qtMocPostfix = "_moc"
qtQRCPostfix = "_qrc"
qtUIPostfix = "_ui"
qtTSPostfix = "_ts"
qtMocExe = "moc" .. windowsExe
qtUICExe = "uic" .. windowsExe
qtQRCExe = "rcc" .. windowsExe
qtTSExe = "lrelease" .. windowsExe
if windows then
qtMocExe = qtDirectory..del.."bin"..del..qtMocExe
qtUICExe = qtDirectory..del.."bin"..del..qtUICExe
qtQRCExe = qtDirectory..del.."bin"..del..qtQRCExe
qtTSExe = qtDirectory..del.."bin"..del..qtTSExe
end
mkdir( qtOutputDirectory )
function file_get_time(filepath)
if windows then
local pipe = io.popen('dir /4/tw "'..filepath..'"')
local output = pipe:read"*a"
pipe:close()
return output:match"\n(%d.-:%S*)"
else
local pipe = io.popen("stat -c %Y testfile")
local last_modified = f:read()
pipe:close()
return last_modified
end
end
function file_is_upToDate(outputFileName)
--if file_exists(outputFileModTime) and ( inputFileModTime < outputFileModTime ) then
--print( outputFileName.." is up-to-date, not regenerating" )
--io.stdout:flush()
--return true
--else
--print( outputFileName .. " is out of date, regenerating" )
--end
return false
end
function getFileNameNoExtFromPath( path )
local i = 0
local lastSlash = 0
local lastPeriod = 0
local returnFilename
while true do
i = string.find( path, "/", i+1 )
if i == nil then break end
lastSlash = i
end
i = 0
while true do
i = string.find( path, "%.", i+1 )
if i == nil then break end
lastPeriod = i
end
if lastPeriod < lastSlash then
returnFilename = path:sub( lastSlash + 1 )
else
returnFilename = path:sub( lastSlash + 1, lastPeriod - 1 )
end
return returnFilename
end
getPath=function(str,sep)
sep=sep or'/'
return str:match("(.*"..sep..")")
end
runProgram = function(command)
local result = 1
if lua_version == "5.3" then
local value, type
value, type, result = os.execute(command)
else
result = os.execute(command)
end
if windows then
return result == 0
end
return result
end
if arg[1] == "-moc" then
mkdir( qtMocOutputDirectory )
outputFileName = qtMocOutputDirectory .. del .. getFileNameNoExtFromPath( arg[2] ) .. qtMocPostfix .. ".cpp"
if file_is_upToDate(outputFileName) == true then return end
local fullMOCPath = qtMocExe.." \""..arg[2].. "\" -I \"" .. getPath(arg[2]) .. "\" -o \"" .. outputFileName .."\" -f\"".. arg[4] .. "_pch.h\" -f\"" .. arg[2] .. "\""
if windows then
fullMOCPath = '""'..qtMocExe..'" "'..arg[2].. '" -I "' .. getPath(arg[2]) .. '" -o "' .. outputFileName ..'"' .. " -f".. arg[4] .. "_pch.h -f" .. arg[2] .. '"'
end
if false == runProgram(fullMOCPath) then
print( BuildErrorWarningString( debug.getinfo(1).currentline, true, [[MOC Failed to generate ]]..outputFileName, 5 ) ); io.stdout:flush()
else
--print( "MOC Created "..outputFileName )
io.stdout:flush()
end
elseif arg[1] == "-rcc" then
mkdir( qtQRCOutputDirectory )
outputFileName = qtQRCOutputDirectory .. del .. getFileNameNoExtFromPath( arg[2] ) .. qtQRCPostfix .. ".cpp"
if file_is_upToDate(outputFileName) == true then return end
local fullRCCPath = qtQRCExe.." -name \""..getFileNameNoExtFromPath( arg[2] ).."\" \""..arg[2].."\" -o \""..outputFileName.."\""
if windows then
fullRCCPath = '""'..qtQRCExe..'" -name "'..getFileNameNoExtFromPath( arg[2] )..'" "'..arg[2]..'" -o "'..outputFileName..'""'
end
if false == runProgram(fullRCCPath) then
print( BuildErrorWarningString( debug.getinfo(1).currentline, true, [[RCC Failed to generate ]]..outputFileName, 6 ) ); io.stdout:flush()
else
--print( "RCC Created "..outputFileName )
io.stdout:flush()
end
elseif arg[1] == "-uic" then
mkdir( qtUIOutputDirectory )
outputFileName = qtUIOutputDirectory .. del .. getFileNameNoExtFromPath( arg[2] ) .. qtUIPostfix .. ".h"
if file_is_upToDate(outputFileName) == true then return end
local fullUICPath = qtUICExe.." \""..arg[2].."\" -o \""..outputFileName.."\""
if windows then
fullUICPath = '""'..qtUICExe..'" "'..arg[2]..'" -o "'..outputFileName..'""'
end
if false == runProgram(fullUICPath) then
print( BuildErrorWarningString( debug.getinfo(1).currentline, true, [[UIC Failed to generate ]]..outputFileName, 7 ) ); io.stdout:flush()
else
--print( "UIC Created "..outputFileName )
io.stdout:flush()
end
elseif arg[1] == "-ts" then
mkdir( qtTSOutputDirectory )
outputFileName = qtTSOutputDirectory .. del .. getFileNameNoExtFromPath( arg[2] ) .. qtTSPostfix .. ".qm"
if file_is_upToDate(outputFileName) == true then return end
local fullTSPath = qtTSExe.." \""..arg[2].."\""
if windows then
fullTSPath = '""'..qtTSExe..'" "'..arg[2]
end
if false == runProgram( fullTSPath) then
print( BuildErrorWarningString( debug.getinfo(1).currentline, true, [[UIC Failed to generate ]]..outputFileName, 7 ) ); io.stdout:flush()
else
--print( "UIC Created "..outputFileName )
io.stdout:flush()
end
end