-
-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathbuild-config.lua
More file actions
267 lines (242 loc) · 7.89 KB
/
build-config.lua
File metadata and controls
267 lines (242 loc) · 7.89 KB
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
-- Common settings for LaTeX2e development repo
-- The LaTeX2e kernel is needed by everything except 'base'
-- There is an over-ride for that case
checkdeps = checkdeps or {maindir .. "/base"}
typesetdeps = typesetdeps or
{
maindir .. "/base",
maindir .. "/required/graphics",
maindir .. "/required/tools"
}
unpackdeps = unpackdeps or {maindir .. "/base"}
-- We really need 4 on most files (toc + references + index (which needs two runs))
typesetruns = 4
-- Set up the check system to work in 'stand-alone' mode
-- This relies on a format being built by the 'base' dependency
asciiengines = asciiengines or {"etex", "pdftex"}
checkengines = checkengines or {"pdftex", "xetex", "luatex"}
checkruns = checkruns or 2
checksuppfiles = checksuppfiles or
{
"color.cfg",
"etex.sty",
"graphics.cfg",
"test209.tex",
"test2e.tex",
"regression-test.tex",
"lipsum.ltd.tex",
"lipsum.sty",
"*.fd",
"*.txt",
"load-unicode-xetex-classes.tex",
"lualibs*.lua",
"fontloader*.lua",
"luaotfload*.lua",
"fixup_mathaxis.lua",
}
tagfiles = tagfiles or {"*.dtx","*.ins","*.tex","README.md"}
typesetsuppfiles = typesetsuppfiles or
{"color.cfg", "graphics.cfg", "ltxdoc.cfg", "ltxguide.cfg"}
-- Ensure the local format file is used
function tex(file,dir,mode)
dir = dir or "."
mode = mode or "nonstopmode"
return runcmd(
'pdftex -fmt=pdflatex -interaction=' .. mode .. ' -jobname="' ..
string.match(file,"^[^.]*") .. '" "\\input ' .. file .. '"',
dir,{"TEXINPUTS","TEXFORMATS","LUAINPUTS"})
end
-- Build TDS-style zips
packtdszip = true
-- Global searching is disabled when unpacking and checking
if checksearch == nil then
checksearch = false
end
if unpacksearch == nil then
unpacksearch = false
end
-- Allow for 'dev' release
--
-- See https://docs.github.com/en/actions/learn-github-actions/environment-variables
-- for the meaning of the environment variables, but tl;dr: GITHUB_REF_TYPE says
-- if we have a tag or a branch, GITHUB_REF_NAME has the corresponding name.
-- If either one of them isn't set, we look at the current git HEAD.
do
local gh_type = os.getenv'GITHUB_REF_TYPE'
local name = os.getenv'GITHUB_REF_NAME'
if gh_type == 'tag' and name then
main_branch = not string.match(name, '^dev-')
else
if gh_type ~= 'branch' or not name then
local f = io.popen'git rev-parse --abbrev-ref HEAD'
name = f:read'*a':sub(1,-2)
assert(f:close())
end
main_branch = string.match(name, '^main')
end
if not main_branch then
tdsroot = "latex-dev"
print("Creating/installing dev-version in " .. tdsroot)
ctanpkg = ctanpkg or ""
ctanpkg = ctanpkg .. "-dev"
ctanzip = ctanpkg
end
end
local match = string.match
local gsub = string.gsub
tag_format = "LaTeX2e"
-- Deal with the two forms of copyright line:
-- we use two small functions for this
-- Format used by base, cyrillic, tools
local function update_tag_ltx(file,content,tag)
local year = os.date("%Y")
if match(content,"%% Copyright %(C%) %d%d%d%d%-%d%d%d%d\n") then
content = gsub(content,
"Copyright %(C%) (%d%d%d%d)%-%d%d%d%d\n",
"Copyright (C) %1-" .. year .. "\n")
elseif match(content,"%% Copyright %(C%) %d%d%d%d\n") then
local oldyear = match(content,"%% Copyright %(C%) (%d%d%d%d)\n")
if not year ~= oldyear then
content = gsub(content,
"Copyright %(C%) %d%d%d%d\n",
"Copyright (C) " .. oldyear .. "-" .. year .. "\n")
end
end
return content
end
-- Form used by amsmath, graphics (and similar to LaTeX3)
local function update_tag_l3(file,content,tag)
local year = os.date("%Y")
if match(content,
"Copyright %(C%) %d%d%d%d%-%d%d%d%d [^\n]*LaTeX") then
content = gsub(content,
"Copyright %(C%) (%d%d%d%d)%-%d%d%d%d ([^\n]*LaTeX)",
"Copyright (C) %1-" .. year .. " %2")
elseif match(content,"Copyright %(C%) %d%d%d%d [^\n]*LaTeX") then
local oldyear = match(content,"Copyright %(C%) (%d%d%d%d) ([^\n]*LaTeX)")
if year ~= oldyear then
content = gsub(content,
"Copyright %(C%) %d%d%d%d LaTeX",
"Copyright (C) " .. oldyear .. "-" .. year .. " LaTeX")
end
end
return content
end
function update_tag(file,content,tagname,tagdate)
-- Set up the patch/pre-release string
local iso = "%d%d%d%d%-%d%d%-%d%d"
local tag, rev = match(tagname,"^(.*):([^:]*)$")
tag = tag or tagname
rev = rev or "0"
if main_branch then
if tonumber(rev) ~= 0 then
tag = tag .. " patch level " .. rev
end
else
tag = tag .. " pre-release " .. rev
end
-- Deal with README.md files: occurs for all formatting
if file == "README.md" then
return gsub(content,
"\nRelease " .. iso .. "[^\n]*\n",
"\nRelease " .. tag .. "\n")
end
-- Special case for ltvers.dtx: only in base but 'quick'
if file == "ltvers.dtx" then
local tag = match(tagname,"^(.*):([^:]*)$")
content = gsub(content,
"\n {" .. iso .. "}\n",
"\n {" .. tag .. "}\n")
content = gsub(content,
"\\patch@level{%-?%d}",
"\\patch@level{" .. rev .. "}")
end
if tag_format == "LaTeX2e" then
return update_tag_ltx(file,content,tag)
else
return update_tag_l3(file,content,tag)
end
end
use_std_format = false
-- Need to build format files
function fmt(engines,dest)
local fmtsearch = false
local function mkfmt(engine)
-- Use .ini files if available
local ini = string.gsub(engine,"tex","") .. "latex"
-- To support places we are using DVI mode, we have to allow for
-- "etex" -> "elatex" -> "latex" in format building
if ini == "elatex" then
ini = "latex"
end
local cmd = engine
if engine == "luatex" then cmd = "luahbtex" end
print("Building format for " .. engine)
local errorlevel = os.execute(
os_setenv .. " TEXINPUTS=" .. unpackdir .. os_pathsep .. localdir
.. os_pathsep .. texmfdir .. "//" .. (fmtsearch and os_pathsep or "")
.. os_concat ..
os_setenv .. " LUAINPUTS=" .. unpackdir .. os_pathsep .. localdir
.. os_pathsep .. texmfdir .. "//" .. (fmtsearch and os_pathsep or "")
.. os_concat .. cmd .. " -etex -ini -output-directory=" .. unpackdir
.. " " .. ini .. ".ini"
.. (options["quiet"] and (" > " .. os_null) or ""))
if errorlevel ~= 0 then return errorlevel end
cp(ini .. ".fmt",unpackdir,dest)
return 0
end
if dest ~= typesetdir and
(not options["config"] or options["config"][1] ~= "config-TU") then
if not use_std_format then
cp("fonttext.cfg",supportdir,unpackdir)
end
end
-- Zap the custom hyphen.cfg when typesetting
if dest == typesetdir then
rm(localdir,"hyphen.cfg")
fmtsearch = true
end
local errorlevel
for _,engine in pairs(engines) do
errorlevel = mkfmt(engine)
if errorlevel ~= 0 then return errorlevel end
end
return 0
end
function checkinit_hook()
local engines = options.engine
if not engines then
local target = options.target
if target == 'check' or target == 'bundlecheck' then
engines = checkengines
elseif target == 'save' then
engines = {stdengine}
else
error'Unexpected target in call to checkinit_hook'
end
end
return fmt(engines,testdir)
end
function docinit_hook() return fmt({"pdftex"},typesetdir) end
-- Shorten second run
function typeset(file,dir)
dir = dir or "."
local errorlevel = tex(file,dir)
if errorlevel ~= 0 then
return errorlevel
end
local name = jobname(file)
errorlevel = biber(name,dir) + bibtex(name,dir)
if errorlevel ~= 0 then
return errorlevel
end
for i = 2,typesetruns - 1 do
-- we have to run tex first then then index otherwise the index isn't run on the second last run!
errorlevel =
tex(file,dir,"batchmode") +
makeindex(name,dir,".glo",".gls",".glg",glossarystyle) +
makeindex(name,dir,".idx",".ind",".ilg",indexstyle)
if errorlevel ~= 0 then return errorlevel end
end
return tex(file,dir)
end