1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
--[[
File l3build-manifest.lua Copyright (C) 2017-2018 The LaTeX3 Project
It may be distributed and/or modified under the conditions of the
LaTeX Project Public License (LPPL), either version 1.3c of this
license or (at your option) any later version. The latest version
of this license is in the file
http://www.latex-project.org/lppl.txt
This file is part of the "l3build bundle" (The Work in LPPL)
and all files in that bundle must be distributed together.
-----------------------------------------------------------------------
The development version of the bundle can be found at
https://github.com/latex3/l3build
for those people who are interested.
--]]
--[[
L3BUILD MANIFEST
================
If desired this entire function can be replaced; if not, it uses a number of
auxiliary functions which are included in this file.
Additional setup can be performed by replacing the functions lists in the file
`l3build-manifest-setup.lua`.
--]]
manifest = manifest or function()
-- build list of ctan files
ctanfiles = {}
for _,f in ipairs(filelist(ctandir.."/"..ctanpkg,"*.*")) do
ctanfiles[f] = true
end
tdsfiles = {}
for _,subdir in ipairs({"/doc/","/source/","/tex/"}) do
for _,f in ipairs(filelist(tdsdir..subdir..moduledir,"*.*")) do
tdsfiles[f] = true
end
end
local manifest_entries = manifest_setup()
for ii,_ in ipairs(manifest_entries) do
manifest_entries[ii] = manifest_build_list(manifest_entries[ii])
end
manifest_write(manifest_entries)
printline = "Manifest written to " .. manifestfile
print((printline:gsub(".","*"))) print(printline) print((printline:gsub(".","*")))
end
--[[
Internal Manifest functions: build_list
---------------------------------------
--]]
manifest_build_list = function(entry)
if not(entry.subheading) then
entry = manifest_build_init(entry)
-- build list of excluded files
for _,glob_list in ipairs(entry.exclude) do
for _,this_glob in ipairs(glob_list) do
for _,this_file in ipairs(filelist(maindir,this_glob)) do
entry.excludes[this_file] = true
end
end
end
-- build list of matched files
for _,glob_list in ipairs(entry.files) do
for _,this_glob in ipairs(glob_list) do
local these_files = filelist(entry.dir,this_glob)
these_files = manifest_sort_within_match(these_files)
for _,this_file in ipairs(these_files) do
entry = manifest_build_file(entry,this_file)
end
entry.files_ordered = manifest_sort_within_group(entry.files_ordered)
end
end
end
return entry
end
manifest_build_init = function(entry)
-- currently these aren't customisable; I guess they could be?
local manifest_group_defaults = {
skipfiledescription = false ,
rename = false ,
dir = maindir ,
exclude = {excludefiles} ,
flag = true ,
}
-- internal data added to each group in the table that needs to be initialised
local manifest_group_init = {
N = 0 , -- # matched files
ND = 0 , -- # descriptions
matches = {} ,
excludes = {} ,
files_ordered = {} ,
descr = {} ,
Nchar_file = 4 , -- TODO: generalise
Nchar_descr = 11 , -- TODO: generalise
}
-- copy default options to each group if necessary
for kk,ll in pairs(manifest_group_defaults) do
if entry[kk] == nil then
entry[kk] = ll
end
-- can't use "entry[kk] = entry[kk] or ll" because false/nil are indistinguishable!
end
-- initialisation for internal data
for kk,ll in pairs(manifest_group_init) do
entry[kk] = ll
end
-- allow nested tables by requiring two levels of nesting
if type(entry.files[1])=="string" then
entry.files = {entry.files}
end
if type(entry.exclude[1])=="string" then
entry.exclude = {entry.exclude}
end
return entry
end
manifest_build_file = function(entry,this_file)
if entry.rename then
this_file = this_file:gsub(entry.rename[1],entry.rename[2])
end
if not entry.excludes[this_file] then
entry.N = entry.N+1
if not(entry.matches[this_file]) then
entry.matches[this_file] = true -- store the file name
entry.files_ordered[entry.N] = this_file -- store the file order
entry.Nchar_file = math.max(entry.Nchar_file,this_file:len())
end
if not(entry.skipfiledescription) then
local ff = assert(io.open(entry.dir .. "/" .. this_file, "r"))
this_descr = manifest_extract_filedesc(ff,this_file)
ff:close()
if this_descr and this_descr ~= "" then
entry.descr[this_file] = this_descr
entry.ND = entry.ND+1
entry.Nchar_descr = math.max(entry.Nchar_descr,this_descr:len())
end
end
end
return entry
end
--[[
Internal Manifest functions: write
----------------------------------
--]]
manifest_write = function(manifest_entries)
local f = assert(io.open(manifestfile, "w"))
manifest_write_opening(f)
for ii,vv in ipairs(manifest_entries) do
if manifest_entries[ii].subheading then
manifest_write_subheading(f,manifest_entries[ii].subheading,manifest_entries[ii].description)
elseif manifest_entries[ii].N > 0 then
manifest_write_group(f,manifest_entries[ii])
end
end
f:close()
end
manifest_write_group = function(f,entry)
manifest_write_group_heading(f,entry.name,entry.description)
if entry.ND > 0 then
for ii,file in ipairs(entry.files_ordered) do
local descr = entry.descr[file] or ""
local param = {
dir = entry.dir ,
count = ii ,
filemaxchar = entry.Nchar_file ,
descmaxchar = entry.Nchar_descr ,
ctanfile = ctanfiles[file] ,
tdsfile = tdsfiles[file] ,
flag = false ,
}
if entry.flag then
param.flag = " "
if tdsfiles[file] and not(ctanfiles[file]) then
param.flag = "† "
elseif ctanfiles[file] then
param.flag = "‡ "
end
end
if ii == 1 then
-- header of table
-- TODO: generalise
local p = {}
for k,v in pairs(param) do p[k] = v end
p.count = -1
p.flag = p.flag and "Flag"
manifest_write_group_file_descr(f,"File","Description",p)
p.flag = p.flag and "--- "
manifest_write_group_file_descr(f,"---","---",p)
end
manifest_write_group_file_descr(f,file,descr,param)
end
else
for ii,file in ipairs(entry.files_ordered) do
local param = {
dir = entry.dir ,
count = ii ,
filemaxchar = entry.Nchar_file ,
ctanfile = ctanfiles[file] ,
tdsfile = tdsfiles[file] ,
}
if entry.flag then
param.flag = ""
if tdsfiles[file] and not(ctanfiles[file]) then
param.flag = "†"
elseif ctanfiles[file] then
param.flag = "‡"
end
end
manifest_write_group_file(f,file,param)
end
end
end
|