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

Commit cd61ee8

Browse files
Merge pull request #1825 from livecode/bugfix-20514
[Bugfix 20514] Extensions: Add a way to launch sample stacks
2 parents 603d14a + 84644fc commit cd61ee8

14 files changed

Lines changed: 1313 additions & 504 deletions

Toolset/libraries/revidedeveloperextensionlibrary.livecodescript

Lines changed: 99 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
script "revIDEDeveloperExtensionLibrary"
22
local sExtensionDetailsA
33

4-
private on __revIDEDeveloperExtensionSendWarning pWarning
4+
private command __revIDEDeveloperExtensionSendWarning pWarning
55
ideMessageSend "ideExtensionLog", "Warning:" && pWarning
66
end __revIDEDeveloperExtensionSendWarning
77

8-
private on __revIDEDeveloperExtensionSendError pError
8+
private command __revIDEDeveloperExtensionSendError pError
99
ideMessageSend "ideExtensionLog", "Error:" && pError
1010
end __revIDEDeveloperExtensionSendError
1111

12-
private on __revIDEDeveloperExtensionLog pLog
12+
private command __revIDEDeveloperExtensionLog pLog
1313
ideMessageSend "ideExtensionLog", pLog
1414
end __revIDEDeveloperExtensionLog
1515

16-
private on __revIDEDeveloperCompilationError pError, pFile
16+
private command __revIDEDeveloperCompilationError pError, pFile
1717
local tLineNo, tChar, tEndChar, tLine
1818
# Parse out the error details to provide more meaningful feedback
1919
repeat for each line tErrLine in pError
@@ -56,7 +56,7 @@ private function __revIDEDeveloperExtensionShouldRecompile pFolder, pFile
5656
return tNeedUpdate is not false
5757
end __revIDEDeveloperExtensionShouldRecompile
5858

59-
private on __revIDEDeveloperExtensionRemoveFolder pFolder
59+
private command __revIDEDeveloperExtensionRemoveFolder pFolder
6060
local tDeveloperExtensionsFolders
6161
put revIDEGetPreference("cDeveloperExtensionsFolders") into tDeveloperExtensionsFolders
6262

@@ -72,7 +72,7 @@ private on __revIDEDeveloperExtensionRemoveFolder pFolder
7272
end if
7373
end __revIDEDeveloperExtensionRemoveFolder
7474

75-
private on __revIDEDeveloperExtensionAddFolder pFolder
75+
private command __revIDEDeveloperExtensionAddFolder pFolder
7676
local tDeveloperExtensionsFolders
7777
put revIDEGetPreference("cDeveloperExtensionsFolders") into tDeveloperExtensionsFolders
7878

@@ -288,6 +288,13 @@ private function __revIDEDeveloperExtensionFetchFolderDetails pFolder, pFile
288288
put tCode into tDetailsA["code"]
289289
end if
290290

291+
local tSamplesFolder, tSamples
292+
put pFolder & slash & "samples" into tSamplesFolder
293+
if there is a folder tSamplesFolder then
294+
put __revIDEDeveloperExtensionListResourcesRecursive(tSamplesFolder, "") into tSamples
295+
put tSamples into tDetailsA["samples"]
296+
end if
297+
291298
# Default script
292299
put revIDEExtensionFetchDefaultScript(pFolder, tDetailsA["id"], false) into tDetailsA["defaultscript"]
293300
if tDetailsA["defaultscript"] is not empty then
@@ -376,10 +383,9 @@ private function __revIDEDeveloperExtensionDetailsFromFile pFolder, pFile, pType
376383
return tDetailsA
377384
end if
378385
union tDetailsA with tMetadataA
379-
put pType into tDetailsA["type"]
386+
put pType into tDetailsA["source_type"]
380387
put tDetailsA into sExtensionDetailsA[pFolder]
381388
return sExtensionDetailsA[pFolder]
382-
383389
end __revIDEDeveloperExtensionDetailsFromFile
384390

385391
on revIDEDeveloperExtensionAddResourceFile pExtensionFolder, pResourcePath, pType
@@ -431,7 +437,16 @@ on revIDEDeveloperExtensionAddResourceFolder pExtensionFolder, pResourceFolder
431437
end if
432438
end revIDEDeveloperExtensionAddResourceFolder
433439

434-
on revIDEDeveloperExtensionTest pPath
440+
local sLoadedExtension
441+
function revIDEDeveloperExtensionCurrentlyTesting
442+
return sLoadedExtension is not empty
443+
end revIDEDeveloperExtensionCurrentlyTesting
444+
445+
command revIDEDeveloperExtensionStopTesting
446+
__ClearTestExtension
447+
end revIDEDeveloperExtensionStopTesting
448+
449+
command revIDEDeveloperExtensionTest pPath
435450
local tDetailsA
436451
put revIDEDeveloperExtension(pPath) into tDetailsA
437452

@@ -446,14 +461,25 @@ on revIDEDeveloperExtensionTest pPath
446461
exit revIDEDeveloperExtensionTest
447462
end if
448463

449-
if there is not a file (pPath & slash & "module.lcm") then
464+
if tDetailsA["source_type"] is "lcb" and \
465+
there is not a file (pPath & slash & "module.lcm") then
450466
__revIDEDeveloperExtensionSendError "No compiled module in" && pPath
451467
exit revIDEDeveloperExtensionTest
452468
end if
453469

454-
__revIDEDeveloperExtensionLog "Launching in Test Window"
470+
__ClearTestExtension
471+
472+
revIDEExtensionLoad tDetailsA["source_type"], tDetailsA["name"], pPath, \
473+
tDetailsA["version"], "installed", "", false, tDetailsA["file"]
455474

456-
__revIDEDeveloperExtensionLaunchTestStack pPath, tDetailsA
475+
local tResult
476+
put the result into tResult
477+
if tResult is not empty then
478+
__revIDEDeveloperExtensionSendError tResult
479+
exit revIDEDeveloperExtensionTest
480+
end if
481+
482+
__LaunchTestExtension pPath, tDetailsA
457483
end revIDEDeveloperExtensionTest
458484

459485
private function __testStackRects
@@ -487,14 +513,10 @@ private function __testStackScript
487513
return tScript
488514
end __testStackScript
489515

490-
private on __revIDEDeveloperExtensionLaunchTestStack pPath, pDetailsA
516+
private command __revIDEDeveloperExtensionLaunchTestStack pPath, pDetailsA
491517
local tRectsA
492518
put __testStackRects() into tRectsA
493519

494-
if there is a stack "LiveCode Extension Test Window" then
495-
revIDEDeveloperExtensionClearTestStack
496-
end if
497-
498520
revIDEDeveloperExtensionCreateTestStack pPath, tRectsA, pDetailsA
499521
end __revIDEDeveloperExtensionLaunchTestStack
500522

@@ -507,16 +529,7 @@ on revIDEDeveloperExtensionCreateTestStack pPath, pRectsA, pDetailsA
507529
end revIDEDeveloperExtensionCreateTestStack
508530

509531
on __revIDEDeveloperExtensionDoCreateTestStack pPath, tRectsA, pDetailsA
510-
revIDEExtensionLoad pDetailsA["type"], pDetailsA["name"], pPath, \
511-
pDetailsA["version"], "installed", "", false, pDetailsA["file"]
512-
513-
local tResult
514-
put the result into tResult
515-
if tResult is not empty then
516-
__revIDEDeveloperExtensionSendError tResult
517-
exit __revIDEDeveloperExtensionDoCreateTestStack
518-
end if
519-
532+
__revIDEDeveloperExtensionLog "Launching in Test Window"
520533
if there is a stack (pPath & slash & "test.livecode") then
521534
go stack (pPath & slash & "test.livecode")
522535
else
@@ -547,21 +560,43 @@ on __revIDEDeveloperExtensionDoCreateTestStack pPath, tRectsA, pDetailsA
547560
set the rect of widget 1 of stack "LiveCode Extension Test Window" to tRectsA["wrect"]
548561
end if
549562

550-
set the cCurExtension of stack "LiveCode Extension Test Window" to pDetailsA["name"]
551563
unlock screen
552564
end __revIDEDeveloperExtensionDoCreateTestStack
553565

566+
private command __LaunchTestExtension pPath, pDetailsA
567+
-- Only launch a test window if a widget
568+
if pDetailsA["type"] is "widget" then
569+
__revIDEDeveloperExtensionLaunchTestStack pPath, pDetailsA
570+
else
571+
__revIDEDeveloperExtensionLog "Loaded library" && sLoadedExtension
572+
end if
573+
put pDetailsA["name"] into sLoadedExtension
574+
ideMessageSend "ideExtensionStatusChanged"
575+
end __LaunchTestExtension
576+
577+
private command __ClearTestExtension
578+
if there is a stack "LiveCode Extension Test Window" then
579+
__revIDEDeveloperExtensionDoClearTestStack
580+
else
581+
__UnloadTestExtension
582+
end if
583+
ideMessageSend "ideExtensionStatusChanged"
584+
end __ClearTestExtension
585+
586+
private command __UnloadTestExtension
587+
if sLoadedExtension is not empty then
588+
__revIDEDeveloperExtensionUnload sLoadedExtension
589+
__revIDEDeveloperExtensionLog "Unloading" && sLoadedExtension
590+
put empty into sLoadedExtension
591+
end if
592+
end __UnloadTestExtension
593+
554594
on __revIDEDeveloperExtensionDoClearTestStack
555595
repeat while there is a widget 1 of stack "LiveCode Extension Test Window"
556596
delete widget 1 of stack "LiveCode Extension Test Window"
557597
end repeat
558-
local tExtension
559-
put the cCurExtension of stack "LiveCode Extension Test Window" into tExtension
560598
delete stack "LiveCode Extension Test Window"
561-
if tExtension is not empty then
562-
__revIDEDeveloperExtensionUnload tExtension
563-
__revIDEDeveloperExtensionLog "Unloading..."
564-
end if
599+
__UnloadTestExtension
565600
end __revIDEDeveloperExtensionDoClearTestStack
566601

567602
local sInstalledExtension
@@ -575,7 +610,7 @@ end __revIDEDeveloperExtensionUnload
575610
on revIDEDeveloperExtensionInstall pFolder
576611
local tPackage
577612
__revIDEDeveloperExtensionBuildPackage pFolder, "", tPackage
578-
revIDEInstallExtension tPackage
613+
revIDEExtensionInstall tPackage
579614
put pFolder & slash & "module.lcm" into sInstalledExtension
580615
end revIDEDeveloperExtensionInstall
581616

@@ -588,7 +623,7 @@ on revIDEDeveloperExtensionUninstall pPath
588623
exit revIDEDeveloperExtensionUninstall
589624
end if
590625

591-
revIDEUninstallExtension tDetailsA["name"]
626+
revIDEExtensionUninstall tDetailsA["name"]
592627

593628
end revIDEDeveloperExtensionUninstall
594629

@@ -686,78 +721,15 @@ private function __fetchMetadatum pXmlId, pKey
686721
return textDecode(revXMLNodeContents(pXmlId, tNode), "utf-8")
687722
end __fetchMetadatum
688723

689-
private function shellFormat pArg, pSwitch
690-
local tOutput
691-
692-
if pSwitch is not empty then
693-
put "--" & pSwitch & " " into tOutput
694-
end if
695-
696-
return tOutput & quote & pArg & quote & " "
697-
end shellFormat
698-
699-
private function __revIDEDeveloperExtensionResourcePath
700-
if revEnvironmentIsInstalled() is false then
701-
return revEnvironmentBinariesPath()
702-
else
703-
return revIDESpecialFolderPath("Toolchain")
704-
end if
705-
end __revIDEDeveloperExtensionResourcePath
706-
707-
private function __revIDEDeveloperExtensionCompilerPath
708-
# The actual compile command
709-
if the platform is "win32" then
710-
return __revIDEDeveloperExtensionResourcePath() & slash & "lc-compile.exe"
711-
else
712-
return __revIDEDeveloperExtensionResourcePath() & slash & "lc-compile"
713-
end if
714-
end __revIDEDeveloperExtensionCompilerPath
715-
716724
private command __revIDEDeveloperCompileModule pFile, pTargetFolder
717-
# The manifest is currently always generated from the source
718-
if there is a file (pTargetFolder & slash & "manifest.xml") then
719-
delete file (pTargetFolder & slash & "manifest.xml")
720-
end if
721-
722-
# Build the shell command
723-
local tShellCommand
724-
put shellFormat(__revIDEDeveloperExtensionCompilerPath()) into tShellCommand
725-
726-
# The folder to put the .lci file
727-
put shellFormat(pTargetFolder, "modulepath") after tShellCommand
728-
729-
# The built-in module path
730-
put shellFormat(__revIDEDeveloperExtensionResourcePath() & slash & "modules/lci", "modulepath") after tShellCommand
725+
revIDEExtensionCompile pFile, pTargetFolder
731726

732-
# Installed module path
733-
put shellFormat(revIDESpecialFolderPath("user extensions") & slash & "interface", "modulepath") after tShellCommand
734-
735-
# The manifest target
736-
put shellFormat(pTargetFolder & slash & "manifest.xml", "manifest") after tShellCommand
737-
738-
# The output
739-
put shellFormat(pTargetFolder & slash & "module.lcm", "output") after tShellCommand
740-
741-
# The target .lcb file
742-
put shellFormat(pFile) after tShellCommand
743-
744-
# AL-2015-06-15: [[ Bug 15001 ]] Don't show console window when executing shell command
745-
local tHideConsoleWindows
746-
put the hideConsoleWindows into tHideConsoleWindows
747-
set the hideConsoleWindows to true
748-
749-
local tShellOutput, tShellResult
750-
put shell(tShellCommand) into tShellOutput
751-
put the result into tShellResult
752-
753-
set the hideConsoleWindows to tHideConsoleWindows
754-
755-
if tShellResult is not 0 then
756-
__revIDEDeveloperCompilationError tShellOutput
727+
if the result is not empty then
728+
__revIDEDeveloperCompilationError the result
757729
return "failed to compile module"
758730
end if
759731

760-
__revIDEDeveloperExtensionLog tShellOutput
732+
__revIDEDeveloperExtensionLog it
761733

762734
if there is not a file (pTargetFolder & slash & "module.lcm") then
763735
return "failed to compile module"
@@ -779,7 +751,7 @@ on revIDEDeveloperExtensionBuildPackage pFolder
779751
end if
780752
end revIDEDeveloperExtensionBuildPackage
781753

782-
private on __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuiltLocation
754+
private command __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuiltLocation
783755
local tDetailsA
784756
put revIDEDeveloperExtension(pFolder) into tDetailsA
785757

@@ -880,6 +852,12 @@ private on __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuil
880852
put empty into tCode
881853
end if
882854

855+
local tSamples
856+
put (pFolder & slash & "samples") into tSamples
857+
if there is not a folder tSamples then
858+
put empty into tSamples
859+
end if
860+
883861
# AL-2015-03-18: [[ Bug 15007 ]] Include interface file if present
884862
local tInterfaceFile
885863
if there is a file (pFolder & slash & tTargetName & ".lci") then
@@ -902,7 +880,7 @@ private on __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuil
902880
put __revIDEDeveloperExtensionAddSpecifiedFilesToPackage(\
903881
tFullPath, pFolder, tArchive, pFolder & slash & "module.lcm", \
904882
tIcon, tRetinaIcon, tGuide, tDocs, tResources, tCode, \
905-
tInterfaceFile, tDefaultScript, tEditors) \
883+
tSamples, tInterfaceFile, tDefaultScript, tEditors) \
906884
into tError
907885
end if
908886

@@ -925,8 +903,9 @@ end __revIDEDeveloperExtensionBuildPackage
925903

926904
private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage \
927905
pSource, pFolder, pArchive, pModule, pIcon, pRetinaIcon, pGuide, \
928-
pDocs, pResourcesFolder, pCodeFolder, pInterfaceFile, \
929-
pDefaultScript, pEditors
906+
pDocs, pResourcesFolder, pCodeFolder, pSamplesFolder, \
907+
pInterfaceFile, pDefaultScript, pEditors
908+
930909
local tError
931910

932911
set the itemdelimiter to slash
@@ -1021,6 +1000,19 @@ private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage \
10211000
end repeat
10221001
end if
10231002

1003+
# Add sample stacks
1004+
if tError is empty and pSamplesFolder is not empty then
1005+
local tSamples
1006+
put __revIDEDeveloperExtensionListResourcesRecursive(pSamplesFolder, "") into tSamples
1007+
repeat for each line tLine in tSamples
1008+
revZipAddItemWithFile pArchive, "samples/" & tLine, pSamplesFolder & slash & tLine
1009+
1010+
if the result begins with "ziperr" then
1011+
__revIDEDeveloperExtensionSendWarning "couldn't add sample" && pSamplesFolder & slash & tLine
1012+
end if
1013+
end repeat
1014+
end if
1015+
10241016
# AL-2015-03-18: [[ Bug 15007 ]] Include interface file if present
10251017
if tError is empty and pInterfaceFile is not empty then
10261018
revZipAddItemWithFile pArchive, item -1 of pInterfaceFile, pInterfaceFile

0 commit comments

Comments
 (0)