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

Commit 00c5829

Browse files
committed
[[ Bug 20929 ]] Output to module.<module_version>.lcm when compiling
- Add support for packages containing multiple module versions - Output to filename with module version when compiling - Check for versioned bytecode file when loading extensions
1 parent a32b33d commit 00c5829

4 files changed

Lines changed: 106 additions & 228 deletions

File tree

Toolset/libraries/revidedeveloperextensionlibrary.livecodescript

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private function __revIDEDeveloperExtensionShouldRecompile pFolder, pFile
3737
put pFolder & slash & pFile into tCompileInputs[1]
3838

3939
put pFolder & slash & "manifest.xml" into tCompileOutputs[1]
40-
put pFolder & slash & "module.lcm" into tCompileOutputs[2]
40+
put pFolder & slash & revIDEExtensionBytecodeFilename(true) into tCompileOutputs[2]
4141

4242
put revIDEIsFilesetStale(tCompileInputs, tCompileOutputs, false, tError) \
4343
into tNeedUpdate
@@ -366,7 +366,7 @@ private function __revIDEDeveloperExtensionDetailsFromFile pFolder, pFile, pSupp
366366
if not __revIDEDeveloperExtensionShouldRecompile(pFolder, pFile) then
367367

368368
__revIDEDeveloperExtensionLog "Skipping recompilation of" && \
369-
pFolder & slash & "module.lcm - module is up to date"
369+
pFolder & slash & pFile && "- module is up to date"
370370
# The stored info is up to date.
371371
if sExtensionDetailsA[pFolder] is not empty then
372372
union tDetailsA with sExtensionDetailsA[pFolder]
@@ -474,8 +474,9 @@ command revIDEDeveloperExtensionTest pPath
474474
exit revIDEDeveloperExtensionTest
475475
end if
476476

477-
if tDetailsA["source_type"] is "lcb" and \
478-
there is not a file (pPath & slash & "module.lcm") then
477+
if tDetailsA["source_type"] is "lcb" \
478+
and there is not a file \
479+
(pPath & slash & revIDEExtensionBytecodeFilename(true)) then
479480
__revIDEDeveloperExtensionSendError "No compiled module in" && pPath
480481
exit revIDEDeveloperExtensionTest
481482
end if
@@ -624,7 +625,8 @@ on revIDEDeveloperExtensionInstall pFolder
624625
local tPackage
625626
__revIDEDeveloperExtensionBuildPackage pFolder, "", tPackage
626627
revIDEExtensionInstall tPackage
627-
put pFolder & slash & "module.lcm" into sInstalledExtension
628+
put pFolder & slash & revIDEExtensionBytecodeFilename(true) \
629+
into sInstalledExtension
628630
end revIDEDeveloperExtensionInstall
629631

630632
on revIDEDeveloperExtensionUninstall pPath
@@ -744,7 +746,8 @@ private command __revIDEDeveloperCompileModule pFile, pSupportFiles, pTargetFold
744746

745747
__revIDEDeveloperExtensionLog it
746748

747-
if there is not a file (pTargetFolder & slash & "module.lcm") then
749+
if there is not a file \
750+
(pTargetFolder & slash & revIDEExtensionBytecodeFilename(true)) then
748751
return "failed to compile module"
749752
end if
750753

@@ -904,14 +907,15 @@ private command __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @
904907
local tSupportFiles
905908
put tDetailsA["support_files"] into tSupportFiles
906909

907-
local tModuleFile
910+
local tModuleFiles
908911
if tDetailsA["source_type"] is "lcb" then
909-
put pFolder & slash & "module.lcm" into tModuleFile
912+
put files(pFolder) into tModuleFiles
913+
filter tModuleFiles with regex pattern "^module(\.[0-9]+)?\.lcm$"
910914
end if
911915

912916
if tError is empty then
913917
put __revIDEDeveloperExtensionAddSpecifiedFilesToPackage(\
914-
tFullPath, tSupportFiles, pFolder, tArchive, tModuleFile, \
918+
tFullPath, tSupportFiles, pFolder, tArchive, tModuleFiles, \
915919
tIcon, tRetinaIcon, tGuide, tDocs, tResources, tCode, \
916920
tSamples, tInterfaceFile, tDefaultScript, tEditors) \
917921
into tError
@@ -935,7 +939,7 @@ private command __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @
935939
end __revIDEDeveloperExtensionBuildPackage
936940

937941
private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage \
938-
pSource, pSupportFiles, pFolder, pArchive, pModuleFile, pIcon, \
942+
pSource, pSupportFiles, pFolder, pArchive, pModuleFiles, pIcon, \
939943
pRetinaIcon, pGuide, pDocs, pResourcesFolder, pCodeFolder, \
940944
pSamplesFolder, pInterfaceFile, pDefaultScript, pEditors
941945

@@ -950,22 +954,28 @@ private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage \
950954
end if
951955

952956
# Add support files into package
953-
repeat for each line tSupport in pSupportFiles
954-
put pFolder & slash & tSupport into tSupport
955-
revZipAddItemWithFile pArchive, item -1 of tSupport, tSupport
957+
if tError is empty then
958+
repeat for each line tSupport in pSupportFiles
959+
put pFolder & slash & tSupport into tSupport
960+
revZipAddItemWithFile pArchive, item -1 of tSupport, tSupport
956961

957-
if the result begins with "ziperr" then
958-
put "couldn't add support file" && tSupport into tError
959-
end if
960-
end repeat
961-
962-
# Add module into package
963-
if pModuleFile is not empty then
964-
revZipAddItemWithFile pArchive, item -1 of pModuleFile, pModuleFile
962+
if the result begins with "ziperr" then
963+
put "couldn't add support file" && tSupport into tError
964+
exit repeat
965+
end if
966+
end repeat
965967
end if
966968

967-
if the result begins with "ziperr" then
968-
put "couldn't add module" into tError
969+
# Add modules into package
970+
if tError is empty then
971+
repeat for each line tModuleFile in pModuleFiles
972+
put pFolder & slash & tModuleFile into tModuleFile
973+
revZipAddItemWithFile pArchive, item -1 of tModuleFile, tModuleFile
974+
if the result begins with "ziperr" then
975+
put "couldn't add module" && tModuleFile into tError
976+
exit repeat
977+
end if
978+
end repeat
969979
end if
970980

971981
# Add manifest into package

Toolset/libraries/revideextensionlibrary.livecodescript

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,52 @@ on extensionFinalize
1313
end if
1414
end extensionFinalize
1515

16+
local sModuleVersion
17+
private command __EnsureModuleVersion
18+
if sModuleVersion is not empty then
19+
exit __EnsureModuleVersion
20+
end if
21+
local tTempFile, tModule, tFolder
22+
put the tempname into tTempFile
23+
set the itemdelimiter to slash
24+
put item 1 to -2 of tTempFile into tFolder
25+
put "module com.livecode.dummy" into tModule
26+
put return & "end module" after tModule
27+
put tModule into url("file:" & tTempFile)
28+
revIDEExtensionCompile tTempFile, "", tFolder, "module.lcm"
29+
put __CompiledModuleVersion(tFolder & slash & "module.lcm") \
30+
into sModuleVersion
31+
end __EnsureModuleVersion
32+
33+
private function __CompiledModuleVersion pModule
34+
local tBytes
35+
put url("binfile:" & pModule) into tBytes
36+
return byteToNum(byte 4 of tBytes) * 256 + \
37+
byteToNum(byte 3 of tBytes)
38+
end __CompiledModuleVersion
39+
40+
private function __CheckModuleVersion pModule
41+
return __CompiledModuleVersion(pModule) is \
42+
__ModuleVersion()
43+
end __CheckModuleVersion
44+
45+
private function __ModuleVersion
46+
__EnsureModuleVersion
47+
return sModuleVersion
48+
end __ModuleVersion
49+
50+
function revIDEExtensionBytecodeFilename pUseVersion
51+
if pUseVersion is empty then
52+
put true into pUseVersion
53+
end if
54+
55+
if pUseVersion then
56+
return "module." & __ModuleVersion() & ".lcm"
57+
else
58+
return "module.lcm"
59+
end if
60+
end revIDEExtensionBytecodeFilename
61+
1662
# Called at startup. Loads all the extensions ready for use
1763
on revIDEInitialiseExtensions
1864
# Load all the extensions ready for use
@@ -926,8 +972,11 @@ command revIDEExtensionFetchSourceFromFolder pFolder, @rSource, @rSupportFiles,
926972
local tExtFiles, tType
927973
filter tFiles with regex pattern \
928974
__RegexPatternForSource("lcb") into tExtFiles
929-
if there is a file (pFolder & slash & "module.lcm") \
930-
or tExtFiles is not empty then
975+
if tExtFiles is not empty \
976+
or there is a file \
977+
(pFolder & slash & revIDEExtensionBytecodeFilename(true)) \
978+
or there is a file \
979+
(pFolder & slash & revIDEExtensionBytecodeFilename(false)) then
931980
put "lcb" into tType
932981
end if
933982

@@ -1188,10 +1237,16 @@ end __MapCodeLibraryForIDE
11881237

11891238
private command __LoadExtension pCacheIndex, pSourceType, pSourceFile, pFolder, pStatus, @xError
11901239
if xError is empty then
1240+
local tFileToLoad
11911241
if pSourceType is "lcb" then
11921242
local tResources, tModule, tCode
1243+
put pFolder & slash & revIDEExtensionBytecodeFilename(true) \
1244+
into tModule
1245+
if there is no file tModule then
1246+
put pFolder & slash & revIDEExtensionBytecodeFilename(false) \
1247+
into tModule
1248+
end if
11931249
put pFolder & slash & "resources" into tResources
1194-
put pFolder & slash & "module.lcm" into tModule
11951250
put pFolder & slash & "code" into tCode
11961251
# map code before loading extension
11971252
if there is a folder tCode then
@@ -1203,9 +1258,11 @@ private command __LoadExtension pCacheIndex, pSourceType, pSourceFile, pFolder,
12031258
else
12041259
load extension from file tModule
12051260
end if
1261+
put tModule into tFileToLoad
12061262
else
12071263
set the itemdelimiter to "."
12081264
revInternal__LoadLibrary item 1 of pSourceFile, pFolder & slash & pSourceFile
1265+
put pSourceFile into tFileToLoad
12091266
end if
12101267
if the result is not empty then
12111268
put toUpper(char 1 of the result) & \
@@ -1218,6 +1275,7 @@ private command __LoadExtension pCacheIndex, pSourceType, pSourceFile, pFolder,
12181275

12191276
__extensionPropertySet pCacheIndex, "status", pStatus
12201277
__extensionPropertySet pCacheIndex, "error", xError
1278+
__extensionPropertySet pCacheIndex, "file", tFileToLoad
12211279
__extensionsChanged
12221280
end __LoadExtension
12231281

@@ -1244,7 +1302,8 @@ private command __revIDELCBExtensionLoad pID, pFolder, pVersion, pStatus, \
12441302
-- If we have an error loading, try to recompile the extension
12451303
if pError is not empty then
12461304
if not pIsIDEExtension and pSourceFile is not empty then
1247-
revIDEExtensionCompile pFolder & slash & pSourceFile, tSupportFiles, pFolder
1305+
revIDEExtensionCompile pFolder & slash & pSourceFile, tSupportFiles, pFolder, \
1306+
revIDEExtensionBytecodeFilename(true)
12481307
if the result is empty then
12491308
local tNewError
12501309
__LoadExtension tCacheIndex, "lcb", pSourceFile, pFolder, pStatus, tNewError
@@ -1636,7 +1695,11 @@ private function shellFormat pArg, pSwitch
16361695
return tOutput & quote & pArg & quote & " "
16371696
end shellFormat
16381697

1639-
command revIDEExtensionCompile pFile, pSupportFiles, pTargetFolder
1698+
command revIDEExtensionCompile pFile, pSupportFiles, pTargetFolder, pOutputFilename
1699+
if pOutputFilename is empty then
1700+
put revIDEExtensionBytecodeFilename() into pOutputFilename
1701+
end if
1702+
16401703
# The manifest is currently always generated from the source
16411704
if there is a file (pTargetFolder & slash & "manifest.xml") then
16421705
delete file (pTargetFolder & slash & "manifest.xml")
@@ -1659,7 +1722,7 @@ command revIDEExtensionCompile pFile, pSupportFiles, pTargetFolder
16591722
put shellFormat(pTargetFolder & slash & "manifest.xml", "manifest") after tShellCommand
16601723

16611724
# The output
1662-
put shellFormat(pTargetFolder & slash & "module.lcm", "output") after tShellCommand
1725+
put shellFormat(pTargetFolder & slash & pOutputFilename, "output") after tShellCommand
16631726

16641727
# Support files must be dependency-ordered
16651728
repeat for each line tSupport in revIDEExtensionsOrderByDependency(pSupportFiles)
@@ -1812,18 +1875,14 @@ function revIDEExtensionFileData pID
18121875
local tCacheIndex
18131876
put __extensionCacheID("name", pID) into tCacheIndex
18141877

1815-
local tSourceType, tFolder, tSourceFile
1878+
local tSourceType, tFolder, tFile
18161879
put __extensionPropertyGet(tCacheIndex, "install_path") into tFolder
18171880
put __extensionPropertyGet(tCacheIndex, "source_type") into tSourceType
1818-
put __extensionPropertyGet(tCacheIndex, "source_file") into tSourceFile
1881+
put __extensionPropertyGet(tCacheIndex, "file") into tFile
18191882

18201883
local tDataA
18211884
put tSourceType into tDataA["type"]
1822-
if tSourceType is "lcb" then
1823-
put tFolder & slash & "module.lcm" into tDataA["file"]
1824-
else
1825-
put tFolder & slash & tSourceFile into tDataA["file"]
1826-
end if
1885+
put tFolder & slash & tFile into tDataA["file"]
18271886
return tDataA
18281887
end revIDEExtensionFileData
18291888

0 commit comments

Comments
 (0)