Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit e991194

Browse files
committed
[[ PackageExtensions ]] Load revzip external and remove other shell cmds
1 parent 53a4617 commit e991194

File tree

1 file changed

+97
-37
lines changed

1 file changed

+97
-37
lines changed

util/package_extension.livecodescript

Lines changed: 97 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,32 @@ on doPackage
3636
tCommercialExtension, tLCCompile, tInterfaceFolder
3737
end doPackage
3838

39+
local sExternalsA
40+
private command __EnsureExternal pExternal
41+
if sExternalsA[pExternal] then
42+
exit __EnsureExternal
43+
end if
44+
45+
set the itemdelimiter to slash
46+
47+
if the platform is "MacOS" then
48+
set the externals of the templateStack to specialFolderPath("engine") & slash & pExternal & ".bundle"
49+
else if the platform is "linux" then
50+
set the externals of the templateStack to specialFolderPath("engine") & slash & pExternal & ".so"
51+
else if the platform is "win32" then
52+
set the externals of the templateStack to specialFolderPath("engine") & slash & pExternal & ".dll"
53+
end if
54+
55+
create stack pExternal && "External"
56+
start using it
57+
if the externalCommands of it is empty then
58+
write "cannot load external" && pExternal to stderr
59+
quit 1
60+
else
61+
put true into sExternalsA[pExternal]
62+
end if
63+
end __EnsureExternal
64+
3965
command buildPackageAndExtractExtension pEngine, pProtectifyScript, \
4066
pProtectifyOutput, pGitHash, pExtractDocsScript, pDocsParser, \
4167
pSourceFolder, pSourceFileName, pTargetFolder, \
@@ -61,8 +87,7 @@ command buildPackageAndExtractExtension pEngine, pProtectifyScript, \
6187
end if
6288
put the result into tPackage
6389

64-
extractExtension tPackage, pSourceFolder, pTargetFolder, \
65-
pCommercialExtension
90+
extractExtension tPackage, pSourceFolder, pTargetFolder
6691

6792
quit 0
6893
end buildPackageAndExtractExtension
@@ -166,25 +191,42 @@ private command addFolderToArchiveRecursive pBaseFolder, pFolder, pArchive
166191
end addFolderToArchiveRecursive
167192

168193
private command packageExtension pExtensionName, pSourceFolder, pSourceFileName, pTargetFolder, pRemoveSource, pSupportFiles
169-
write "packaging extension" && pSourceFileName & return to stdout
194+
__EnsureExternal revzip
195+
170196
local tTargetDir, tBuildTarget, tZip
171197
put pExtensionName into tTargetDir
172198
put pTargetFolder & slash & tTargetDir into tBuildTarget
173-
put pSourceFolder & slash & tTargetDir & ".lce" into tZip
199+
put the folder & slash & pSourceFolder & slash & tTargetDir & ".lce" into tZip
200+
201+
write "packaging extension" && pSourceFileName && \
202+
"to" && tZip & return to stdout
203+
204+
if there is a file tZip then
205+
delete file tZip
206+
end if
174207

175208
local tArchive, tError
176209
revZipOpenArchive tZip, "write"
177210
if the result begins with "ziperr" then
178211
put the result into tError
179212
end if
180-
addFolderToArchive pSourceFolder, tZip, pRemoveSource, pSourceFileName, pSupportFiles
181-
if the result begins with "ziperr" then
182-
put the result into tError
213+
214+
if tError is empty then
215+
addFolderToArchive pSourceFolder, tZip, pRemoveSource, \
216+
pSourceFileName, pSupportFiles
217+
218+
if the result begins with "ziperr" then
219+
put the result into tError
220+
end if
183221
end if
184-
revZipCloseArchive tZip
185-
if the result begins with "ziperr" then
186-
put the result into tError
222+
223+
if tError is empty then
224+
revZipCloseArchive tZip
225+
if the result begins with "ziperr" then
226+
put the result into tError
227+
end if
187228
end if
229+
188230
if tError is not empty then
189231
write "zip error when packaging extension" && pSourceFileName & ":" && tError to stderr
190232
quit 3
@@ -212,12 +254,24 @@ private command __EnsurePath pPath
212254
end repeat
213255
end __EnsurePath
214256

215-
private command extractExtension pZip, pExtensionName, pSourceFolder, pTargetFolder
216-
local tTargetDir, tBuildTarget, tError
217-
put pExtensionName into tTargetDir
218-
put pTargetFolder & slash & tTargetDir into tBuildTarget
257+
private command extractExtension pZip, pSourceFolder, pTargetFolder
258+
__EnsureExternal revzip
259+
260+
local tTargetDir, tBuildTarget, tError, tName
261+
set the itemdelimiter to slash
262+
put item -1 of pZip into tName
263+
set the itemdelimiter to "."
264+
put item 1 to -2 of tName into tName
265+
266+
put pTargetFolder & slash & tName into tBuildTarget
267+
268+
write "extracting extension" && pZip && \
269+
"to" && tBuildTarget & return to stdout
270+
271+
if there is not a folder tBuildTarget then
272+
create folder tBuildTarget
273+
end if
219274

220-
create folder tBuildTarget
221275
# Extract the icon,docs and executable module into the folder
222276
revZipOpenArchive pZip, "read"
223277
if the result begins with "ziperr" then
@@ -226,14 +280,16 @@ private command extractExtension pZip, pExtensionName, pSourceFolder, pTargetFol
226280

227281
# Work out the root of the zip
228282
local tZipItems, tZipRoot
229-
put revZipEnumerateItems(pZip) into tZipItems
230-
if the result begins with "ziperr" then
231-
put the result into tError
232-
end if
233-
if the last char of line 1 of tZipItems is "/" then
234-
put line 1 of tZipItems into tZipRoot
235-
else
236-
put empty into tZipRoot
283+
if tError is empty then
284+
put revZipEnumerateItems(pZip) into tZipItems
285+
if the result begins with "ziperr" then
286+
put the result into tError
287+
end if
288+
if the last char of line 1 of tZipItems is "/" then
289+
put line 1 of tZipItems into tZipRoot
290+
else
291+
put empty into tZipRoot
292+
end if
237293
end if
238294

239295
# Extract all the files
@@ -248,12 +304,15 @@ private command extractExtension pZip, pExtensionName, pSourceFolder, pTargetFol
248304
end if
249305
end repeat
250306

251-
revZipCloseArchive pZip
252-
if the result begins with "ziperr" then
253-
put the result into tError
307+
if tError is empty then
308+
revZipCloseArchive pZip
309+
if the result begins with "ziperr" then
310+
put the result into tError
311+
end if
254312
end if
313+
255314
if tError is not empty then
256-
write "zip error when extracting extension" && pExtensionName & ":" && tError to stderr
315+
write "zip error when extracting extension" && tName & ":" && tError to stderr
257316
quit 3
258317
end if
259318
end extractExtension
@@ -314,18 +373,19 @@ command packageBuilderExtension pSourceFolder, pSourceFileName, pTargetFolder, p
314373
end if
315374

316375
# Extract an e.g. "module foo.bar.baz" line from an LCB source file
317-
local tExtractNameShell, tExtensionName
318-
put "sed -nEe 's,^([[:space:]]*<name>(.*)</name>[[:space:]]*)$,\2,p' <" \
319-
&& q(pSourceFolder & slash & "manifest.xml") into tExtractNameShell
320-
321-
write "extracting extension name from manifest" & return to stdout
322-
put word 1 to -1 of shell(tExtractNameShell) into tExtensionName
323-
if the result is not 0 then
324-
write "subprocess error when extracting name from" && pSourceFileName & ":" && it to stderr
376+
write "extracting extension name from manifest" & return to stdout
377+
local tManifest, tName
378+
put url("binfile:" & pSourceFolder & slash & "manifest.xml") \
379+
into tManifest
380+
381+
put textDecode(tManifest, "utf-8") into tManifest
382+
if not matchText(tManifest, " *<name>(.*)</name> *", tName) then
383+
write "could not find name in manifest" && \
384+
pSourceFolder & slash & "manifest.xml" to stderr
325385
quit 3
326-
end if
386+
end if
327387

328-
packageExtension tExtensionName, pSourceFolder, pSourceFileName, \
388+
packageExtension tName, pSourceFolder, pSourceFileName, \
329389
pTargetFolder, pRemoveSource, tSupportFiles
330390
return the result
331391
end packageBuilderExtension

0 commit comments

Comments
 (0)