@@ -13,6 +13,52 @@ on extensionFinalize
1313 end if
1414end 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
1763on 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
11891238private 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
12221280end __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 & " "
16351696end 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
18261887end revIDEExtensionFileData
18271888
@@ -1890,3 +1951,55 @@ command revIDEExtensionIconFromType pType, pID, @rIconName, @rIconPath
18901951 break
18911952 end switch
18921953end 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