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

Commit 6ddf47b

Browse files
Merge pull request #1903 from livecode/bugfix-module_versioning
[[ Bug 20929 ]] Output to module.<module_version>.lcm when compiling
2 parents 283ad3c + 00c5829 commit 6ddf47b

4 files changed

Lines changed: 176 additions & 225 deletions

File tree

Toolset/libraries/revidedeveloperextensionlibrary.livecodescript

Lines changed: 49 additions & 20 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
@@ -751,7 +753,8 @@ private command __revIDEDeveloperCompileModule pFile, pSupportFiles, pTargetFold
751753

752754
__revIDEDeveloperExtensionLog it
753755

754-
if there is not a file (pTargetFolder & slash & "module.lcm") then
756+
if there is not a file \
757+
(pTargetFolder & slash & revIDEExtensionBytecodeFilename(true)) then
755758
return "failed to compile module"
756759
end if
757760

@@ -782,6 +785,18 @@ private command __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @
782785
return "Error: missing file" && tFullPath
783786
end if
784787

788+
local tManifestFile
789+
put pFolder & slash & "manifest.xml" into tManifestFile
790+
791+
if tDetailsA["source_type"] is "lcs" then
792+
revIDEExtensionGenerateManifestForLCSExtension \
793+
tDetailsA["source_file"], pFolder
794+
end if
795+
796+
if there is no file tManifestFile then
797+
return "Error: missing manifest" && tManifestFile
798+
end if
799+
785800
local tTargetFolder
786801
if pTargetFolder is empty then
787802
put pFolder into tTargetFolder
@@ -899,9 +914,15 @@ private command __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @
899914
local tSupportFiles
900915
put tDetailsA["support_files"] into tSupportFiles
901916

917+
local tModuleFiles
918+
if tDetailsA["source_type"] is "lcb" then
919+
put files(pFolder) into tModuleFiles
920+
filter tModuleFiles with regex pattern "^module(\.[0-9]+)?\.lcm$"
921+
end if
922+
902923
if tError is empty then
903924
put __revIDEDeveloperExtensionAddSpecifiedFilesToPackage(\
904-
tFullPath, tSupportFiles, pFolder, tArchive, pFolder & slash & "module.lcm", \
925+
tFullPath, tSupportFiles, pFolder, tArchive, tModuleFiles, \
905926
tIcon, tRetinaIcon, tGuide, tDocs, tResources, tCode, \
906927
tSamples, tInterfaceFile, tDefaultScript, tEditors) \
907928
into tError
@@ -925,7 +946,7 @@ private command __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @
925946
end __revIDEDeveloperExtensionBuildPackage
926947

927948
private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage \
928-
pSource, pSupportFiles, pFolder, pArchive, pModule, pIcon, \
949+
pSource, pSupportFiles, pFolder, pArchive, pModuleFiles, pIcon, \
929950
pRetinaIcon, pGuide, pDocs, pResourcesFolder, pCodeFolder, \
930951
pSamplesFolder, pInterfaceFile, pDefaultScript, pEditors
931952

@@ -940,20 +961,28 @@ private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage \
940961
end if
941962

942963
# Add support files into package
943-
repeat for each line tSupport in pSupportFiles
944-
put pFolder & slash & tSupport into tSupport
945-
revZipAddItemWithFile pArchive, item -1 of tSupport, tSupport
964+
if tError is empty then
965+
repeat for each line tSupport in pSupportFiles
966+
put pFolder & slash & tSupport into tSupport
967+
revZipAddItemWithFile pArchive, item -1 of tSupport, tSupport
946968

947-
if the result begins with "ziperr" then
948-
put "couldn't add support file" && tSupport into tError
949-
end if
950-
end repeat
951-
952-
# Add module into package
953-
revZipAddItemWithFile pArchive, "module.lcm", pModule
969+
if the result begins with "ziperr" then
970+
put "couldn't add support file" && tSupport into tError
971+
exit repeat
972+
end if
973+
end repeat
974+
end if
954975

955-
if the result begins with "ziperr" then
956-
put "couldn't add module" into tError
976+
# Add modules into package
977+
if tError is empty then
978+
repeat for each line tModuleFile in pModuleFiles
979+
put pFolder & slash & tModuleFile into tModuleFile
980+
revZipAddItemWithFile pArchive, item -1 of tModuleFile, tModuleFile
981+
if the result begins with "ziperr" then
982+
put "couldn't add module" && tModuleFile into tError
983+
exit repeat
984+
end if
985+
end repeat
957986
end if
958987

959988
# Add manifest into package

Toolset/libraries/revideextensionlibrary.livecodescript

Lines changed: 126 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
@@ -1357,6 +1416,8 @@ private command __revIDELCSExtensionLoad pFullPath, pFolder, pVersion, pStatus,
13571416
__extensionPropertySet tCacheIndex, "author", pAdditionalInfoA["author"]
13581417
__extensionPropertySet tCacheIndex, "title", pAdditionalInfoA["display name"]
13591418
__extensionPropertySet tCacheIndex, "svgicon", pAdditionalInfoA["svgicon"]
1419+
__extensionPropertySet tCacheIndex, "version", pAdditionalInfoA["version"]
1420+
13601421
repeat for each key tKey in pAdditionalInfoA["uses"]
13611422
local tSettingString
13621423
put empty into tSettingString
@@ -1634,7 +1695,11 @@ private function shellFormat pArg, pSwitch
16341695
return tOutput & quote & pArg & quote & " "
16351696
end shellFormat
16361697

1637-
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+
16381703
# The manifest is currently always generated from the source
16391704
if there is a file (pTargetFolder & slash & "manifest.xml") then
16401705
delete file (pTargetFolder & slash & "manifest.xml")
@@ -1657,7 +1722,7 @@ command revIDEExtensionCompile pFile, pSupportFiles, pTargetFolder
16571722
put shellFormat(pTargetFolder & slash & "manifest.xml", "manifest") after tShellCommand
16581723

16591724
# The output
1660-
put shellFormat(pTargetFolder & slash & "module.lcm", "output") after tShellCommand
1725+
put shellFormat(pTargetFolder & slash & pOutputFilename, "output") after tShellCommand
16611726

16621727
# Support files must be dependency-ordered
16631728
repeat for each line tSupport in revIDEExtensionsOrderByDependency(pSupportFiles)
@@ -1810,18 +1875,14 @@ function revIDEExtensionFileData pID
18101875
local tCacheIndex
18111876
put __extensionCacheID("name", pID) into tCacheIndex
18121877

1813-
local tSourceType, tFolder, tSourceFile
1878+
local tSourceType, tFolder, tFile
18141879
put __extensionPropertyGet(tCacheIndex, "install_path") into tFolder
18151880
put __extensionPropertyGet(tCacheIndex, "source_type") into tSourceType
1816-
put __extensionPropertyGet(tCacheIndex, "source_file") into tSourceFile
1881+
put __extensionPropertyGet(tCacheIndex, "file") into tFile
18171882

18181883
local tDataA
18191884
put tSourceType into tDataA["type"]
1820-
if tSourceType is "lcb" then
1821-
put tFolder & slash & "module.lcm" into tDataA["file"]
1822-
else
1823-
put tFolder & slash & tSourceFile into tDataA["file"]
1824-
end if
1885+
put tFolder & slash & tFile into tDataA["file"]
18251886
return tDataA
18261887
end revIDEExtensionFileData
18271888

@@ -1890,3 +1951,55 @@ command revIDEExtensionIconFromType pType, pID, @rIconName, @rIconPath
18901951
break
18911952
end switch
18921953
end revIDEExtensionIconFromType
1954+
1955+
private command addXML @xXML, pDepth, pTag, pContent, pAttributesA
1956+
repeat pDepth
1957+
put space after xXML
1958+
end repeat
1959+
put "<" & pTag after xXML
1960+
repeat for each key tKey in pAttributesA
1961+
put " " & tKey & "=" & quote & pAttributesA[tKey] & quote \
1962+
after xXML
1963+
end repeat
1964+
if pContent is empty then
1965+
put " />" after xXML
1966+
else
1967+
put ">" & pContent & "</" & pTag & ">" after xXML
1968+
end if
1969+
put return after xXML
1970+
end addXML
1971+
1972+
command revIDEExtensionGenerateManifestForLCSExtension pSource, pFolder
1973+
local tDataA
1974+
put __fetchScriptLibraryData(pFolder, pSource) into tDataA
1975+
1976+
local tPackageXML, tAttrA
1977+
repeat for each item tTag in "name,title,author,version,type"
1978+
addXML tPackageXML, 1, tTag, tDataA[tTag]
1979+
end repeat
1980+
1981+
addXML tPackageXML, 1, "license", "community"
1982+
1983+
// TODO: This will only work for loaded lcs libraries
1984+
repeat for each line tRequirement in revSBGetExtensionDependenciesForExtension(tDataA["name"])
1985+
put tRequirement into tAttrA["name"]
1986+
addXML tPackageXML, 1, "requires", "", tAttrA
1987+
put empty into tAttrA
1988+
end repeat
1989+
1990+
repeat for each item tMetadata in "svgicon"
1991+
local tValue
1992+
put tDataA[tMetadata] into tValue
1993+
if tValue is empty then
1994+
next repeat
1995+
end if
1996+
put tMetadata into tAttrA["key"]
1997+
addXML tPackageXML, 1, "metadata", tValue, tAttrA
1998+
put empty into tAttrA
1999+
end repeat
2000+
2001+
local tXML
2002+
put "0.0" into tAttrA["version"]
2003+
addXML tXML, 0, "package", return & tPackageXML, tAttrA
2004+
put textEncode(tXML, "utf-8") into url("binfile:" & pFolder & slash & "manifest.xml")
2005+
end revIDEExtensionGenerateManifestForLCSExtension

0 commit comments

Comments
 (0)