-
Notifications
You must be signed in to change notification settings - Fork 125
/
build-config.lua
234 lines (213 loc) · 7.02 KB
/
build-config.lua
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
-- Common settings for ctex-kit development repo, used by l3build script
supportdir = supportdir or "../support"
gitverfiles = gitverfiles or unpackfiles
unpackexe = unpackexe or "luatex"
typesetexe = typesetexe or "xelatex"
makeindexexe = makeindexexe or "zhmakeindex"
makeindexopts = makeindexopts or "-q"
checkopts = checkopts or "-halt-on-error"
typesetopts = typesetopts or "-halt-on-error"
binaryfiles = binaryfiles or {"*.pdf", "*.zip", "*.luc", "*.tec", "*.tfm", "*.tar.bz2"}
kpse.set_program_name("kpsewhich")
local lookup = kpse.lookup
local md5sum = require("md5").sum
function file_md5 (file)
local f = io.open(file, "rb")
if f then
local data = f:read("*all")
f:close()
return data and md5sum(data)
end
end
typesetruns = typesetruns or 5
typeset = function (file,dir,exe)
local dir = dir or "."
local name = jobname(file)
local path_name = dir .. "/" .. name
local aux, bbl = path_name .. ".aux", path_name .. ".bbl"
local glo, idx, hd = path_name .. ".glo", path_name .. ".idx", path_name .. ".hd"
local aux_md5, bbl_md5, glo_md5, idx_md5, hd_md5
local prev_aux_md5, prev_bbl_md5, prev_glo_md5, prev_idx_md5, prev_hd_md5
local errorlevel
local cnt = 0
local typeset_flag = true
while typeset_flag and cnt < typesetruns do
cnt = cnt + 1
errorlevel = tex(file,dir,exe)
if errorlevel ~= 0 then return errorlevel end
errorlevel = biber(name,dir)
+ bibtex(name,dir)
+ makeindex(name,dir,".glo",".gls",".glg",glossarystyle)
+ makeindex(name,dir,".idx",".ind",".ilg",indexstyle)
if errorlevel ~= 0 then return errorlevel end
prev_aux_md5, prev_bbl_md5 = aux_md5, bbl_md5
prev_glo_md5, prev_idx_md5, prev_hd_md5 = glo_md5, idx_md5, hd_md5
aux_md5, bbl_md5 = file_md5(aux), file_md5(bbl)
glo_md5, idx_md5, hd_md5 = file_md5(glo), file_md5(idx), file_md5(hd)
typeset_flag = aux_md5 ~= prev_aux_md5 or bbl_md5 ~= prev_bbl_md5
or glo_md5 ~= prev_glo_md5
or idx_md5 ~= prev_idx_md5
or hd_md5 ~= prev_hd_md5
end
return 0
end
dtxchecksum = require(lookup("dtxchecksum.lua", {path=supportdir})).checksum
function checksum()
if not is_unpacked then unpack() end
unpack = null_function
for _,i in ipairs(typesetsuppfiles) do
cp(i, supportdir, localdir)
end
for _,glob in ipairs(typesetfiles) do
for _,f in ipairs(filelist(".", glob)) do
if f:sub(-4) == ".dtx" then
dtxchecksum(f, localdir)
end
end
end
end
target_list = target_list or { }
target_list.checksum = { desc = "Adjust \\CheckSum{...}", func = checksum }
shellescape = os.type == "windows"
and function (s) return s end
or function (s)
s = s:gsub([[\]], [[\\]])
s = s:gsub([[%$]], [[\$]])
return s
end
git_id_info = { }
function extract_git_version()
mkdir(supportdir)
for _,i in ipairs(gitverfiles) do
for _,j in ipairs({currentdir,supportdir}) do
for _,k in ipairs(filelist(j, i)) do
local idfile = normalize_path(supportdir .. "/" .. jobname(k) .. ".id")
local file = normalize_path(j .. "/" .. k)
local cmdline = shellescape([[git log -1 --pretty=format:"$Id: ]]
.. k .. [[ %h %ai %an <%ae> $" ]] .. file)
local f = assert(io.popen(cmdline, "r"))
local id = f:read("*all")
f:close()
git_id_info[k] = id
f = assert(io.open(idfile, "wb"))
f:write(id, "\n")
f:close()
end
end
end
end
function expand_git_version()
local sourcedir = tdsdir .. "/source/" .. moduledir
local texdir = tdsdir .. "/tex/" .. moduledir
for _,i in ipairs(gitverfiles) do
for _,j in ipairs({sourcedir,texdir}) do
for _,k in ipairs(filelist(j, i)) do
replace_git_id(j, k)
end
end
end
end
function replace_git_id (path, file)
local f = assert(io.open(path .. "/" .. file, "rb"))
local s = f:read("*all")
f:close()
local id = assert(git_id_info[file])
local s, n = s:gsub([[(\GetIdInfo)%b$$]], "%1" .. id)
if n > 0 then
f = assert(io.open(path .. "/" .. file, "wb"))
f:write(s)
f:close()
cp(file, path, ctandir .. "/" .. ctanpkg)
end
end
function update_tag(file, content, tagname, tagdate)
local content, date = content, tagdate:gsub("%-", "/")
if file:match("%.dtx$") then
content = content:gsub("({\\ExplFileDate})%b{}", "%1{" .. tagname .."}")
content = content:gsub("(%[)%d%d%d%d/%d%d/%d%d v%S+", "%1" .. date .. " v" .. tagname)
end
return content
end
null_function = function() return 0 end
local insert = table.insert
local os_remove = os.remove
function saveall(names)
local lvts = names and { } or filelist(testfiledir, "*" .. lvtext)
if names then
local uniq = { }
local glob = "*%s*" .. lvtext
for _,i in ipairs(names) do
for _,j in ipairs(filelist(testfiledir, glob:format(i))) do
if not uniq[j] then
uniq[j] = true
insert(lvts, j)
end
end
end
end
if next(lvts) then
checkinit()
checkinit = null_function
local stdfile = testfiledir .. "/%s" .. tlgext
local extfile = testfiledir .. "/%s.%s" .. tlgext
local opt_engine = options.engine or checkengines
options.engine = opt_engine
for _, lvt in ipairs(lvts) do
local name = lvt:gsub("%" .. lvtext .."$", "")
save( { name } )
local stdtlg = file_md5(stdfile:format(name))
for _, tex in ipairs(opt_engine) do
if tex ~= stdengine then
local file = extfile:format(name, tex)
if file_md5(file) == stdtlg then
os_remove(file)
end
end
end
end
end
end
target_list.saveall = { desc = "Saves all test validation log", func = saveall }
doc_prehook = doc_prehook or null_function
doc_posthook = doc_posthook or null_function
unhooked_doc = doc
doc = function (...)
doc_prehook()
checksum()
local retval = unhooked_doc(...)
doc_posthook()
return retval
end
target_list.doc.func = doc
unpack_prehook = unpack_prehook or null_function
unpack_posthook = unpack_posthook or null_function
unhooked_bundleunpack = bundleunpack
bundleunpack = function (...)
extract_git_version()
unpack_prehook()
local retval = unhooked_bundleunpack(...)
is_unpacked = true
unpack_posthook()
return retval
end
target_list.bundleunpack.func = bundleunpack
install_files_prehook = install_files_prehook or null_function
install_files_posthook = install_files_posthook or null_function
unhooked_install_files = install_files
install_files = function (...)
install_files_bool = true
install_files_prehook()
local retval = unhooked_install_files(...)
install_files_posthook()
return retval
end
copyctan_prehook = copyctan_prehook or null_function
copyctan_posthook = copyctan_posthook or null_function
unhooked_copyctan = copyctan
copyctan = function (...)
copyctan_prehook()
local retval = unhooked_copyctan(...)
expand_git_version()
copyctan_posthook()
return retval
end