forked from stone-zeng/fduthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.lua
executable file
·149 lines (138 loc) · 3.86 KB
/
build.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
#!/usr/bin/env texlua
-- Build script for fduthesis.
module = "fduthesis"
checkengines = {"xetex", "luatex"}
checkopts = "-interaction=batchmode"
sourcefiles = {"source/*.dtx"}
installfiles = {"*.cls", "*.sty", "*.def"}
-- typesetdeps = {"source/latexmkrc."}
typesetexe = "xelatex"
typesetfiles = {"fduthesis.dtx"}
unpackfiles = {"fduthesis.dtx"}
unpackexe = "xetex"
-- excludefiles = {"*/breqn -abbr-test.pdf",
-- "*/eqbreaks.pdf"}
-- unpackopts = "-interaction=batchmode"
-- cmdchkfiles = {"*.dtx"}
local insert = table.insert
local sort = table.sort
function modified_check(names)
local errorlevel = 0
if testfiledir ~= "" and direxists(testfiledir) then
if not options["rerun"] then
checkinit()
end
local hide = true
--[[
-- To suppress TeX output.
if names and next(names) then
hide = false
end
]]--
names = names or { }
-- No names passed: find all test files
if not next(names) then
local excludenames = { }
for _,glob in pairs(excludetests) do
for _,name in pairs(filelist(testfiledir, glob .. lvtext)) do
excludenames[jobname(name)] = true
end
for _,name in pairs(filelist(unpackdir, glob .. lvtext)) do
excludenames[jobname(name)] = true
end
for _,name in pairs(filelist(testfiledir, glob .. pvtext)) do
excludenames[jobname(name)] = true
end
end
local function addname(name)
if not excludenames[jobname(name)] then
insert(names,jobname(name))
end
end
for _,glob in pairs(includetests) do
for _,name in pairs(filelist(testfiledir, glob .. lvtext)) do
addname(name)
end
for _,name in pairs(filelist(testfiledir, glob .. pvtext)) do
addname(name)
end
for _,name in pairs(filelist(unpackdir, glob .. lvtext)) do
if fileexists(testfiledir .. "/" .. name) then
print("Duplicate test file: " .. i)
return 1
end
addname(name)
end
end
sort(names)
-- Deal limiting range of names
if options["first"] then
local allnames = names
local active = false
local firstname = options["first"]
names = { }
for _,name in ipairs(allnames) do
if name == firstname then
active = true
end
if active then
insert(names,name)
end
end
end
if options["last"] then
local allnames = names
local lastname = options["last"]
names = { }
for _,name in ipairs(allnames) do
insert(names,name)
if name == lastname then
break
end
end
end
end
-- https://stackoverflow.com/a/32167188
local function shuffle(tbl)
local len, random = #tbl, rnd
for i = len, 2, -1 do
local j = random(1, i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
return tbl
end
if options["shuffle"] then
names = shuffle(names)
end
-- Actually run the tests
print("Running checks on")
local i = 0
for _,name in ipairs(names) do
i = i + 1
print(" " .. name .. " (" .. i.. "/" .. #names ..")")
local errlevel = runcheck(name, hide)
-- Return value must be 1 not errlevel
if errlevel ~= 0 then
if options["halt-on-error"] then
return 1
else
errorlevel = 1
-- visually show that something has failed
print(" --> failed\n")
end
end
end
if errorlevel ~= 0 then
checkdiff()
else
print("\n All checks passed\n")
end
end
return errorlevel
end
function main(target, names)
target_list["check"]["func"] = modified_check
stdmain(target, names)
end
kpse.set_program_name("kpsewhich")
dofile(kpse.lookup("l3build.lua"))