Skip to content

Commit c1040d8

Browse files
committed
[ExtractDocs] Extract docs from script libraries
(cherry picked from commit 949ff48) Conflicts: engine/engine.gyp tests/_testlib.livecodescript
1 parent dfd384d commit c1040d8

File tree

6 files changed

+218
-7
lines changed

6 files changed

+218
-7
lines changed

builder/builder_utilities.livecodescript

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ function builderPackagedExtensionsFolder
402402
return the result & slash & "packaged_extensions"
403403
end builderPackagedExtensionsFolder
404404

405+
function builderExtractedDocsFolder
406+
builderFetchEngine "", "macosx"
407+
return the result & slash & "extracted_docs"
408+
end builderExtractedDocsFolder
409+
405410
-- Returns the engine that should be used to build the installer
406411
function builderInstallerEngine pPlatform
407412
local tEngineFolder

builder/docs_builder.livecodescript

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,27 @@ command docsBuilderGenerateDistributedAPI pEdition
22072207

22082208
addToList tDataGridA, tLibrariesA
22092209

2210+
local tExtractedDocsFolder
2211+
put builderExtractedDocsFolder() into tExtractedDocsFolder
2212+
2213+
local tFiles
2214+
put files(tExtractedDocsFolder) into tFiles
2215+
filter tFiles with "*.lcdoc"
2216+
2217+
set the itemDelimiter to "."
2218+
local tFile
2219+
repeat for each line tFile in tFiles
2220+
local tLibA
2221+
put revDocsParseDocFileToLibraryArray(tExtractedDocsFolder & slash & tFile, item -2 of tFile, "LiveCode") into tLibA
2222+
2223+
if tLibA is empty then
2224+
builderLog "error", "Couldn't parse" && item -2 of tFile && "dictionary data for" && pEdition
2225+
exit docsBuilderGenerateDistributedAPI
2226+
end if
2227+
2228+
addToList tLibA, tLibrariesA
2229+
end repeat
2230+
22102231
local tJSON
22112232
put revDocsFormatLibrariesArrayAsJSON(tLibrariesA) into tJSON
22122233

engine/engine.gyp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,88 @@
2121

2222
'targets':
2323
[
24+
{
25+
'target_name': 'extract_docs',
26+
'type': 'none',
27+
28+
'all_dependent_settings':
29+
{
30+
'variables':
31+
{
32+
'dist_aux_files':
33+
[
34+
# Gyp will only use a recursive xcopy on Windows if the path ends with '/'
35+
'<(PRODUCT_DIR)/extracted_docs/',
36+
],
37+
},
38+
},
39+
40+
'variables':
41+
{
42+
'conditions':
43+
[
44+
[
45+
'host_os == "linux"',
46+
{
47+
'engine': '<(PRODUCT_DIR)/server-community',
48+
},
49+
],
50+
[
51+
'host_os == "mac"',
52+
{
53+
'engine': '<(PRODUCT_DIR)/server-community',
54+
},
55+
],
56+
[
57+
'host_os == "win"',
58+
{
59+
'engine': '<(PRODUCT_DIR)/server-community.exe',
60+
},
61+
],
62+
],
63+
},
64+
65+
'dependencies':
66+
[
67+
# Requires a working LiveCode engine
68+
'server',
69+
],
70+
71+
'sources':
72+
[
73+
74+
],
75+
76+
'actions':
77+
[
78+
{
79+
'action_name': 'extract_docs_from_stacks',
80+
'message': 'Extracting docs from stacks',
81+
82+
'inputs':
83+
[
84+
'../util/extract-docs.livecodescript',
85+
'../ide-support/revdocsparser.livecodescript',
86+
'<@(_sources)',
87+
],
88+
89+
'outputs':
90+
[
91+
'<(PRODUCT_DIR)/extracted_docs',
92+
],
93+
94+
'action':
95+
[
96+
'<(engine)',
97+
'../util/extract-docs.livecodescript',
98+
'../ide-support/revdocsparser.livecodescript',
99+
'<(PRODUCT_DIR)/extracted_docs',
100+
'<@(_sources)',
101+
],
102+
},
103+
],
104+
},
105+
24106
{
25107
'target_name': 'descriptify_environment_stack',
26108
'type': 'none',
@@ -625,6 +707,7 @@
625707
'kernel-development.gyp:kernel-development',
626708
'encode_environment_stack',
627709
'engine-common.gyp:security-community',
710+
'extract_docs',
628711
],
629712

630713
'sources':

tests/_testlib.livecodescript

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private command _TestWriteOutput pMessage
115115
end if
116116
end _TestWriteOutput
117117

118-
private function _TestGetBuiltExtensionsFolder
118+
private function _TestGetBuildFolder
119119
local tPath, tRepoPath
120120
put specialfolderpath("engine") into tPath
121121
put TestGetEngineRepositoryPath() into tRepoPath
@@ -124,10 +124,14 @@ private function _TestGetBuiltExtensionsFolder
124124
set the itemdelimiter to slash
125125
repeat while tPath is not tRepoPath and tPath is not empty
126126
if there is a folder (tPath & slash & "packaged_extensions") then
127-
return (tPath & slash & "packaged_extensions")
127+
return tPath
128128
end if
129129
delete item -1 of tPath
130-
end repeat
130+
end repeat
131+
end _TestGetBuildFolder
132+
133+
private function _TestGetBuiltExtensionsFolder
134+
return _TestGetBuildFolder() & slash & "packaged_extensions"
131135
end _TestGetBuiltExtensionsFolder
132136

133137
private command _TestLoadExtension pFolder, pPath
@@ -284,7 +288,11 @@ function TestGetIDERepositoryPath
284288
return item 1 to -3 of the filename of me & slash & "ide"
285289
end TestGetIDERepositoryPath
286290

287-
on TestLoadExtension pName
291+
function TestGetExtractedDocsFolder
292+
return _TestGetBuildFolder() & slash & "extracted_docs"
293+
end TestGetExtractedDocsFolder
294+
295+
on TestLoadExtension pName
288296
set the itemdelimiter to "."
289297
local tExtensionUnzipFolder
290298
put pName into tExtensionUnzipFolder

tests/lcs/docs/validate-dictionary.livecodescript

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,52 @@ on TestDocsValidateDictionary
3939
put TestGetEngineRepositoryPath() & "/docs" into tDocsPath
4040
put revDocsParseDictionaryToLibraryArray(tDocsPath) into tDocsArray
4141

42+
__TestDocsLibraryArray tDocsArray
43+
end TestDocsValidateDictionary
44+
45+
on TestDocsValidateExtractedLibraries
46+
local tExtractedDocsFolder
47+
put TestGetExtractedDocsFolder() into tExtractedDocsFolder
48+
49+
TestAssert "extracted docs folder exists", there is a folder tExtractedDocsFolder
50+
51+
local tFiles
52+
put files(tExtractedDocsFolder) into tFiles
53+
54+
TestAssert "some files are in the extracted docs folder", tFiles is not empty
55+
56+
filter tFiles with "*.lcdoc"
57+
58+
TestAssert "some lcdoc files are in the extracted docs folder", tFiles is not empty
59+
60+
set the itemDelimiter to "."
61+
62+
local tFile
63+
repeat for each line tFile in tFiles
64+
local tDocsPath, tDocsArray
65+
put tExtractedDocsFolder & slash & tFile into tDocsPath
66+
67+
put revDocsParseDocFileToLibraryArray(tDocsPath, item -2 of tFile, "LiveCode") into tDocsArray
68+
69+
TestAssert "type of" && tFile && "is library", tDocsArray["type"] is "library"
70+
TestAssert "name of" && tFile && "is not empty", tDocsArray["name"] is not empty
71+
TestAssert "display name of" && tFile && "is not empty", tDocsArray["display name"] is not empty
72+
TestAssert "author name of" && tFile && "is not empty", tDocsArray["author"] is not empty
73+
TestAssert "description of" && tFile && "is not empty", tDocsArray["description"] is not empty
74+
75+
__TestDocsLibraryArray tDocsArray["doc"]
76+
end repeat
77+
end TestDocsValidateExtractedLibraries
78+
79+
command __TestDocsLibraryArray pLibrary
4280
local tElement
4381

4482
local tReferences
45-
repeat for each element tElement in tDocsArray
83+
repeat for each element tElement in pLibrary
4684
put true into tReferences[tElement["type"]][tElement["display name"]]
4785
end repeat
4886

49-
repeat for each element tElement in tDocsArray
87+
repeat for each element tElement in pLibrary
5088
local tValue
5189
local tIndex
5290

@@ -240,7 +278,7 @@ on TestDocsValidateDictionary
240278
-- * test for ambiguous links
241279

242280
end repeat
243-
end TestDocsValidateDictionary
281+
end __TestDocsLibraryArray
244282

245283
command SplitParam @pParam
246284
-- find type

util/extract-docs.livecodescript

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!
2+
3+
send "extractDocs" to me
4+
5+
on extractDocs
6+
7+
local tDocsParser
8+
local tOutputDir
9+
10+
local tArgs
11+
put the commandArguments into tArgs
12+
put tArgs[2] into tDocsParser
13+
put tArgs[3] into tOutputDir
14+
15+
try
16+
start using stack tDocsParser
17+
catch tError
18+
write "Error: could not load docs parser:" && tDocsParser & return & tError & return to stderr
19+
quit 1
20+
end try
21+
22+
if there is not a folder tOutputDir then
23+
create folder tOutputDir
24+
end if
25+
26+
if there is not a folder tOutputDir then
27+
write "Error: could not create output directory: " & tOutputDir & return to stderr
28+
quit 2
29+
end if
30+
31+
local tArg
32+
repeat with tArg = 4 to the number of elements of tArgs
33+
34+
if there is not a stack tArgs[tArg] then
35+
write "Error: stack not found: " & tArgs[tArg] & return to stderr
36+
quit 3
37+
end if
38+
39+
local tDocs
40+
put revDocsGenerateDocsFileFromText(the script of stack tArgs[tArg],the long id of stack tArgs[tArg]) into tDocs
41+
42+
put textEncode(tDocs, "UTF-8") into tDocs
43+
44+
replace numToByte(13) with numToByte(10) in tDocs
45+
46+
put tDocs into url ("binfile:" & tOutputDir & "/" & tolower(the short name of stack tArgs[tArg]) & ".lcdoc")
47+
end repeat
48+
49+
quit 0
50+
51+
end extractDocs
52+
53+
on errorDialog tError
54+
write "Error:" && tError to stderr
55+
quit 10
56+
end errorDialog

0 commit comments

Comments
 (0)