-
Notifications
You must be signed in to change notification settings - Fork 14
/
l3build.lua
2505 lines (2390 loc) · 72.5 KB
/
l3build.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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
File l3build.lua Copyright (C) 2014-2017 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.
--]]
-- Version information
release_date = "2017/12/06"
-- "module" is a deprecated function in Lua 5.2: as we want the name
-- for other purposes, and it should eventually be 'free', simply
-- remove the built-in
if type(module) == "function" then
module = nil
end
-- Ensure the module and bundle exist
module = module or ""
bundle = bundle or ""
-- Sanity check
if module == "" and bundle == "" then
if string.match(arg[0], "l3build%.lua$") then
print(
"\n" ..
"l3build: A testing and building system for LaTeX\n\n" ..
"Release " .. release_date
)
if arg[1] and not string.match(arg[1], "version") then
print(
"\n"
.. "Error: Call l3build using a configuration file, not directly.\n"
)
end
else
print(
"\n"
.. "Error: Specify either bundle or module in configuration script.\n"
)
end
os.exit(1)
end
-- Directory structure for the build system
-- Use Unix-style path separators
maindir = maindir or "."
-- Substructure for file locations
docfiledir = docfiledir or maindir
supportdir = supportdir or maindir .. "/support"
testfiledir = testfiledir or "testfiles"
testsuppdir = testsuppdir or testfiledir .. "/support"
-- Structure within a development area
builddir = builddir or maindir .. "/build"
distribdir = distribdir or builddir .. "/distrib"
localdir = localdir or builddir .. "/local"
testdir = testdir or builddir .. "/test"
typesetdir = typesetdir or builddir .. "/doc"
unpackdir = unpackdir or builddir .. "/unpacked"
-- Substructure for CTAN release material
ctandir = ctandir or distribdir .. "/ctan"
tdsdir = tdsdir or distribdir .. "/tds"
tdsroot = tdsroot or "latex"
-- Location for installation on CTAN or in TEXMFHOME
if bundle == "" then
moduledir = tdsroot .. "/" .. module
ctanpkg = ctanpkg or module
else
moduledir = tdsroot .. "/" .. bundle .. "/" .. module
ctanpkg = ctanpkg or bundle
end
-- File types for various operations
-- Use Unix-style globs
-- All of these may be set earlier, so a initialised conditionally
bibfiles = bibfiles or {"*.bib"}
binaryfiles = binaryfiles or {"*.pdf", "*.zip"}
bstfiles = bstfiles or {"*.bst"}
checkfiles = checkfiles or { }
checksuppfiles = checksuppfiles or { }
cmdchkfiles = cmdchkfiles or { }
cleanfiles = cleanfiles or {"*.log", "*.pdf", "*.zip"}
demofiles = demofiles or { }
docfiles = docfiles or { }
excludefiles = excludefiles or {"*~"}
installfiles = installfiles or {"*.sty","*.cls"}
makeindexfiles = makeindexfiles or {"*.ist"}
sourcefiles = sourcefiles or {"*.dtx", "*.ins"}
textfiles = textfiles or {"*.md", "*.txt"}
typesetdemofiles = typesetdemofiles or { }
typesetfiles = typesetfiles or {"*.dtx"}
typesetsuppfiles = typesetsuppfiles or { }
typesetsourcefiles = typesetsourcefiles or { }
unpackfiles = unpackfiles or {"*.ins"}
unpacksuppfiles = unpacksuppfiles or { }
versionfiles = versionfiles or {"*.dtx"}
-- Roots which should be unpacked to support unpacking/testing/typesetting
checkdeps = checkdeps or { }
typesetdeps = typesetdeps or { }
unpackdeps = unpackdeps or { }
-- Executable names plus following options
typesetexe = typesetexe or "pdflatex"
unpackexe = unpackexe or "tex"
zipexe = zipexe or "zip"
checkopts = checkopts or "-interaction=nonstopmode"
cmdchkopts = cmdchkopts or "-interaction=batchmode"
typesetopts = typesetopts or "-interaction=nonstopmode"
unpackopts = unpackopts or ""
zipopts = zipopts or "-v -r -X"
-- Engines for testing
checkengines = checkengines or {"pdftex", "xetex", "luatex"}
checkformat = checkformat or "latex"
stdengine = stdengine or "pdftex"
-- Enable access to trees outside of the repo
-- As these may be set false, a more elaborate test than normal is needed
if checksearch == nil then
checksearch = true
end
if typesetsearch == nil then
typesetsearch = true
end
if unpacksearch == nil then
unpacksearch = true
end
-- Additional settings to fine-tune typesetting
glossarystyle = glossarystyle or "gglo.ist"
indexstyle = indexstyle or "gind.ist"
-- Supporting binaries and options
biberexe = biberexe or "biber"
biberopts = biberopts or ""
bibtexexe = bibtexexe or "bibtex8"
bibtexopts = bibtexopts or "-W"
makeindexexe = makeindexexe or "makeindex"
makeindexopts = makeindexopts or ""
-- Forcing epoch
if forcecheckepoch == nil then
forcecheckepoch = true
end
if forcedocepoch == nil then
forcedocepoch = true
end
-- Other required settings
asciiengines = asciiengines or {"pdftex"}
checkruns = checkruns or 1
epoch = epoch or 1463734800
maxprintline = maxprintline or 79
packtdszip = packtdszip or false
scriptname = scriptname or "build.lua"
typesetcmds = typesetcmds or ""
typesetruns = typesetruns or 2
versionform = versionform or ""
recordstatus = recordstatus or false
-- Extensions for various file types: used to abstract out stuff a bit
bakext = bakext or ".bak"
dviext = dviext or ".dvi"
logext = logext or ".log"
lveext = lveext or ".lve"
lvtext = lvtext or ".lvt"
pdfext = pdfext or ".pdf"
psext = psext or ".ps"
tlgext = tlgext or ".tlg"
-- File operations are aided by the LuaFileSystem module
local lfs = require("lfs")
-- Local access to functions
local assert = assert
local ipairs = ipairs
local next = next
local print = print
local select = select
local tonumber = tonumber
local close = io.close
local lines = io.lines
local open = io.open
local output = io.output
local stderr = io.stderr
local write = io.write
local set_program_name = kpse.set_program_name
local var_value = kpse.var_value
local lfs_attributes = lfs.attributes
local lfs_dir = lfs.dir
local os_date = os.date
local execute = os.execute
local exit = os.exit
local getenv = os.getenv
local os_remove = os.remove
local os_time = os.time
local os_type = os.type
local len = string.len
local luatex_revision = status.luatex_revision
local luatex_version = status.luatex_version
local char = string.char
local find = string.find
local format = string.format
local gmatch = string.gmatch
local gsub = string.gsub
local len = string.len
local match = string.match
local rep = string.rep
local sort = table.sort
local sub = string.sub
local concat = table.concat
local insert = table.insert
local utf8_char = unicode.utf8.char
-- Parse command line options
local option_list =
{
date =
{
desc = "Sets the date to insert into sources",
short = "d",
type = "string"
},
engine =
{
desc = "Sets the engine(s) to use for running test",
short = "e",
type = "table"
},
epoch =
{
desc = "Sets the epoch for tests and typesetting",
short = "E",
type = "string"
},
force =
{
desc = "Force tests to run if engine is not set up",
short = "f",
type = "boolean"
},
["halt-on-error"] =
{
desc = "Stops running tests after the first failure",
short = "H",
type = "boolean"
},
help =
{
short = "h",
type = "boolean"
},
pdf =
{
desc = "Check/save PDF files",
short = "p",
type = "boolean"
},
quiet =
{
desc = "Suppresses TeX output when unpacking",
short = "q",
type = "boolean"
},
rerun =
{
desc = "Skip setup: simply rerun tests",
short = "r",
type = "boolean"
},
testfiledir =
{
desc = "Selects the specified testfile location",
short = "t",
type = "table"
},
version =
{
desc = "Sets the version to insert into sources",
short = "v",
type = "string"
},
}
-- This is done as a function (rather than do ... end) as it allows early
-- termination (break)
local function argparse()
local result = { }
local files = { }
local long_options = { }
local short_options = { }
-- Turn long/short options into two lookup tables
for k,v in pairs(option_list) do
short_options[v["short"]] = k
long_options[k] = k
end
local args = args
-- arg[1] is a special case: must be a command or "-h"/"--help"
-- Deal with this by assuming help and storing only apparently-valid
-- input
local a = arg[1]
result["target"] = "help"
if a then
-- No options are allowed in position 1, so filter those out
if not match(a, "^%-") then
result["target"] = a
end
end
-- Stop here if help is required
if result["target"] == "help" then
return result
end
-- An auxiliary to grab all file names into a table
local function remainder(num)
local files = { }
for i = num, #arg do
insert(files, arg[i])
end
return files
end
-- Examine all other arguments
-- Use a while loop rather than for as this makes it easier
-- to grab arg for optionals where appropriate
local i = 2
while i <= #arg do
local a = arg[i]
-- Terminate search for options
if a == "--" then
files = remainder(i + 1)
break
end
-- Look for optionals
local opt
local optarg
local opts
-- Look for and option and get it into a variable
if match(a, "^%-") then
if match(a, "^%-%-") then
opts = long_options
local pos = find(a, "=", 1, true)
if pos then
opt = sub(a, 3, pos - 1)
optarg = sub(a, pos + 1)
else
opt = sub(a, 3)
end
else
opts = short_options
opt = sub(a, 2, 2)
-- Only set optarg if it is there
if #a > 2 then
optarg = sub(a, 3)
end
end
-- Now check that the option is valid and sort out the argument
-- if required
local optname = opts[opt]
if optname then
-- Tidy up arguments
if option_list[optname]["type"] == "boolean" then
if optarg then
local opt = "-" .. (match(a, "^%-%-") and "-" or "") .. opt
stderr:write("Value not allowed for option " .. opt .."\n")
return {"help"}
end
else
if not optarg then
optarg = arg[i + 1]
if not optarg then
stderr:write("Missing value for option " .. a .."\n")
return {"help"}
end
i = i + 1
end
end
else
stderr:write("Unknown option " .. a .."\n")
return {"help"}
end
-- Store the result
if optarg then
if option_list[optname]["type"] == "string" then
result[optname] = optarg
else
local opts = result[optname] or { }
for hit in gmatch(optarg, "([^,%s]+)") do
insert(opts, hit)
end
result[optname] = opts
end
else
result[optname] = true
end
i = i + 1
end
if not opt then
files = remainder(i)
break
end
end
if next(files) then
result["files"] = files
end
return result
end
options = argparse()
-- Sanity check
if options["engine"] and not options["force"] then
-- Make a lookup table
local t = { }
for _, engine in pairs(checkengines) do
t[engine] = true
end
for _, engine in pairs(options["engine"]) do
if not t[engine] then
print("\n! Error: Engine \"" .. engine .. "\" not set up for testing!")
print("\n Valid values are:")
for _, engine in ipairs(checkengines) do
print(" - " .. engine)
end
print("")
exit(1)
end
end
end
-- Tidy up the epoch setting
-- Force an epoch if set at the command line
if options["epoch"] then
epoch = options["epoch"]
forcecheckepoch = true
forcedocepoch = true
end
-- If given as an ISO date, turn into an epoch number
do
local y, m, d = match(epoch, "^(%d%d%d%d)-(%d%d)-(%d%d)$")
if y then
epoch =
os_time({year = y, month = m, day = d, hour = 0, sec = 0, isdst = nil}) -
os_time({year = 1970, month = 1, day = 1, hour = 0, sec = 0, isdst = nil})
elseif match(epoch, "^%d+$") then
epoch = tonumber(epoch)
else
epoch = 0
end
end
-- Convert a file glob into a pattern for use by e.g. string.gub
-- Based on https://github.com/davidm/lua-glob-pattern
-- Simplified substantially: "[...]" syntax not supported as is not
-- required by the file patterns used by the team. Also note style
-- changes to match coding approach in rest of this file.
--
-- License for original globtopattern
--[[
(c) 2008-2011 David Manura. Licensed under the same terms as Lua (MIT).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
(end license)
--]]
local function glob_to_pattern(glob)
local pattern = "^" -- pattern being built
local i = 0 -- index in glob
local char -- char at index i in glob
-- escape pattern char
local function escape(char)
return match(char, "^%w$") and char or "%" .. char
end
-- Convert tokens.
while true do
i = i + 1
char = sub(glob, i, i)
if char == "" then
pattern = pattern .. "$"
break
elseif char == "?" then
pattern = pattern .. "."
elseif char == "*" then
pattern = pattern .. ".*"
elseif char == "[" then
-- Ignored
print("[...] syntax not supported in globs!")
elseif char == "\\" then
i = i + 1
char = sub(glob, i, i)
if char == "" then
pattern = pattern .. "\\$"
break
end
pattern = pattern .. escape(char)
else
pattern = pattern .. escape(char)
end
end
return pattern
end
-- Detect the operating system in use
-- Support items are defined here for cases where a single string can cover
-- both Windows and Unix cases: more complex situations are handled inside
-- the support functions
os_concat = ";"
os_null = "/dev/null"
os_pathsep = ":"
os_setenv = "export"
os_yes = "printf 'y\\n%.0s' {1..200}"
local os_ascii = "echo \"\""
local os_cmpexe = getenv("cmpexe") or "cmp"
local os_cmpext = getenv("cmpext") or ".cmp"
local os_diffext = getenv("diffext") or ".diff"
local os_diffexe = getenv("diffexe") or "diff -c --strip-trailing-cr"
local os_grepexe = "grep"
local os_newline = "\n"
if os_type == "windows" then
os_ascii = "@echo."
os_cmpexe = getenv("cmpexe") or "fc /b"
os_cmpext = getenv("cmpext") or ".cmp"
os_concat = "&"
os_diffext = getenv("diffext") or ".fc"
os_diffexe = getenv("diffexe") or "fc /n"
os_grepexe = "findstr /r"
os_newline = "\n"
if tonumber(luatex_version) < 100 or
(tonumber(luatex_version) == 100
and tonumber(luatex_revision) < 4) then
os_newline = "\r\n"
end
os_null = "nul"
os_pathsep = ";"
os_setenv = "set"
os_yes = "for /l %I in (1,1,200) do @echo y"
end
-- Return an absolute path from a relative one
function abspath(path)
local oldpwd = lfs.currentdir()
lfs.chdir(path)
local result = lfs.currentdir()
lfs.chdir(oldpwd)
return gsub(result, "\\", "/")
end
-- For cleaning out a directory, which also ensures that it exists
function cleandir(dir)
local errorlevel = mkdir(dir)
if errorlevel ~= 0 then
return errorlevel
end
return rm(dir, "*")
end
-- Copy files 'quietly'
function cp(glob, source, dest)
local errorlevel
for i,_ in pairs(tree(source, glob)) do
local source = source .. "/" .. i
if os_type == "windows" then
if lfs_attributes(source)["mode"] == "directory" then
errorlevel = execute(
'xcopy /y /e /i "' .. unix_to_win(source) .. '" "'
.. unix_to_win(dest .. '/' .. i) .. '" > nul'
)
else
errorlevel = execute(
'xcopy /y "' .. unix_to_win(source) .. '" "'
.. unix_to_win(dest) .. '" > nul'
)
end
else
errorlevel = execute("cp -RLf '" .. source .. "' '" .. dest .. "'")
end
if errorlevel ~=0 then
return errorlevel
end
end
return 0
end
-- OS-dependent test for a directory
function direxists(dir)
local errorlevel
if os_type == "windows" then
errorlevel =
execute("if not exist \"" .. unix_to_win(dir) .. "\" exit 1")
else
errorlevel = execute("[ -d " .. dir .. " ]")
end
if errorlevel ~= 0 then
return false
end
return true
end
function fileexists(file)
local f = open(file, "r")
if f ~= nil then
close(f)
return true
else
return false
end
end
-- Generate a table containing all file names of the given glob or all files
-- if absent
function filelist(path, glob)
local files = { }
local pattern
if glob then
pattern = glob_to_pattern(glob)
end
if direxists(path) then
for entry in lfs_dir(path) do
if pattern then
if match(entry, pattern) then
insert(files, entry)
end
else
if entry ~= "." and entry ~= ".." then
insert(files, entry)
end
end
end
end
return files
end
-- Does what filelist does, but can also glob subdirectories. In the returned
-- table, the keys are paths relative to the given starting path, the values
-- are their counterparts relative to the current working directory.
function tree(path, glob)
function cropdots(path)
return gsub(gsub(path, "^%./", ""), "/%./", "/")
end
function always_true()
return true
end
function is_dir(file)
return lfs_attributes(file)["mode"] == "directory"
end
local dirs = {["."] = cropdots(path)}
for pattern, critereon in gmatch(cropdots(glob), "([^/]+)(/?)") do
local critereon = critereon == "/" and is_dir or always_true
function fill(path, dir, table)
for _, file in ipairs(filelist(dir, pattern)) do
local fullpath = path .. "/" .. file
if file ~= "." and file ~= ".." and
fullpath ~= builddir and
(sub(pattern, 1, 1) == "."
or sub(file, 1, 1) ~= ".")
then
local fulldir = dir .. "/" .. file
if critereon(fulldir) then
table[fullpath] = fulldir
end
end
end
end
local newdirs = {}
if pattern == "**" then
while true do
path, dir = next(dirs)
if not path then
break
end
dirs[path] = nil
newdirs[path] = dir
fill(path, dir, dirs)
end
else
for path, dir in pairs(dirs) do
fill(path, dir, newdirs)
end
end
dirs = newdirs
end
return dirs
end
function mkdir(dir)
if os_type == "windows" then
-- Windows (with the extensions) will automatically make directory trees
-- but issues a warning if the dir already exists: avoid by including a test
local dir = unix_to_win(dir)
return execute(
"if not exist " .. dir .. "\\nul " .. "mkdir " .. dir
)
else
return execute("mkdir -p " .. dir)
end
end
-- Rename
function ren(dir, source, dest)
local dir = dir .. "/"
if os_type == "windows" then
return execute("ren " .. unix_to_win(dir) .. source .. " " .. dest)
else
return execute("mv " .. dir .. source .. " " .. dir .. dest)
end
end
-- Remove file(s) based on a glob
function rm(source, glob)
for _,i in ipairs(filelist(source, glob)) do
os_remove(source .. "/" .. i)
end
-- os_remove doesn't give a sensible errorlevel
return 0
end
-- Remove a directory tree
function rmdir(dir)
-- First, make sure it exists to avoid any errors
mkdir(dir)
if os_type == "windows" then
return execute("rmdir /s /q " .. unix_to_win(dir))
else
return execute("rm -r " .. dir)
end
end
-- Run a command in a given directory
function run(dir, cmd)
return execute("cd " .. dir .. os_concat .. cmd)
end
-- Deal with the fact that Windows and Unix use different path separators
function unix_to_win(path)
return gsub(path, "/", "\\")
end
--
-- Auxiliary functions which are used by more than one main function
--
-- Do some subtarget for all modules in a bundle
function call(dirs, target, opts)
-- Turn the option table into a string
local opts = opts or options
local s = ""
for k,v in pairs(opts) do
if k ~= "files" and k ~= "target" then -- Special cases
local t = option_list[k] or { }
local arg = ""
if t["type"] == "string" then
arg = arg .. "=" .. v
end
if t["type"] == "table" then
for _,a in pairs(v) do
if arg == "" then
arg = "=" .. a -- Add the initial "=" here
else
arg = arg .. "," .. a
end
end
end
s = s .. " --" .. k .. arg
end
end
if opts["files"] then
for _,v in pairs(opts["files"]) do
s = s .. " " .. v
end
end
for _,i in ipairs(dirs) do
print(
"Running script " .. scriptname .. " with target \"" .. target
.. "\" for module "
.. i
)
local errorlevel = run(
i,
"texlua " .. scriptname .. " " .. target .. s
)
if errorlevel ~= 0 then
return errorlevel
end
end
return 0
end
-- Set up the check system files: needed for checking one or more tests and
-- for saving the test files
function checkinit()
cleandir(testdir)
depinstall(checkdeps)
-- Copy dependencies to the test directory itself: this makes the paths
-- a lot easier to manage, and is important for dealing with the log and
-- with file input/output tests
for _,i in ipairs(filelist(localdir)) do
cp(i, localdir, testdir)
end
bundleunpack({".", testfiledir})
for _,i in ipairs(installfiles) do
cp(i, unpackdir, testdir)
end
for _,i in ipairs(checkfiles) do
cp(i, unpackdir, testdir)
end
if direxists(testsuppdir) then
for _,i in ipairs(filelist(testsuppdir)) do
cp(i, testsuppdir, testdir)
end
end
for _,i in ipairs(checksuppfiles) do
cp(i, supportdir, testdir)
end
execute(os_ascii .. ">" .. testdir .. "/ascii.tcx")
end
-- Copy files to the main CTAN release directory
function copyctan()
-- Do all of the copying in one go
for _,i in ipairs(
{
bibfiles,
demofiles,
docfiles,
pdffiles,
sourcefiles,
textfiles,
typesetlist
}
) do
for _,j in ipairs(i) do
cp(j, ".", ctandir .. "/" .. ctanpkg)
end
end
end
-- Copy files to the correct places in the TDS tree
function copytds()
local function install(source, dest, files, tool)
local moduledir = moduledir
-- For material associated with secondary tools (BibTeX, MakeIndex)
-- the structure needed is slightly different from those items going
-- into the tex/doc/source trees
if tool then
-- "base" is reserved for the tools themselves: make the assumption
-- in this case that the tdsroot name is the right place for stuff to
-- go (really just for the team)
if module == "base" then
moduledir = tdsroot
else
moduledir = module
end
end
-- Convert the file table(s) to a list of individual files
local filenames = { }
for _,i in ipairs(files) do
for _,j in ipairs(i) do
for _,k in ipairs(filelist(source, j)) do
insert(filenames, k)
end
end
end
-- The target is only created if there are actual files to install
if next(filenames) ~= nil then
local installdir = tdsdir .. "/" .. dest .. "/" .. moduledir
mkdir(installdir)
for _,i in ipairs(filenames) do
cp(i, source, installdir)
end
end
end
install(
".",
"doc",
{bibfiles, demofiles, docfiles, pdffiles, textfiles, typesetlist}
)
install(unpackdir, "makeindex", {makeindexfiles}, true)
install(unpackdir, "bibtex/bst", {bstfiles}, true)
install(".", "source", {sourcelist})
install(unpackdir, "tex", {installfiles})
end
-- Unpack files needed to support testing/typesetting/unpacking
function depinstall(deps)
local errorlevel
for _,i in ipairs(deps) do
print("Installing dependency: " .. i)
errorlevel = run(i, "texlua " .. scriptname .. " unpack -q")
if errorlevel ~= 0 then
return errorlevel
end
end
return 0
end
-- Convert the raw log file into one for comparison/storage: keeps only
-- the 'business' part from the tests and removes system-dependent stuff
local function formatlog(logfile, newfile, engine, errlevels)
local maxprintline = maxprintline
if engine == "luatex" or engine == "luajittex" then
maxprintline = maxprintline + 1 -- Deal with an out-by-one error
end
local function killcheck(line)
-- Skip lines containing file dates
if match(line, "[^<]%d%d%d%d/%d%d/%d%d") then
return true
elseif
-- Skip \openin/\openout lines in web2c 7.x
-- As Lua doesn't allow "(in|out)", a slightly complex approach:
-- do a substitution to check the line is exactly what is required!
match(
gsub(line, "^\\openin", "\\openout"), "^\\openout%d%d? = "
) then
return true
end
return false
end
-- Substitutions to remove some non-useful changes
local function normalize(line, lastline)
-- Zap line numbers from \show, \showbox, \box_show and the like:
-- do this before wrapping lines
line = gsub(line, "^l%.%d+ ", "l. ...")
-- Also from lua stack traces.
line = gsub(line, "lua:%d+: in function", "lua:...: in function")
-- Allow for wrapped lines: preserve the content and wrap
-- Skip lines that have an explicit marker for truncation
if len(line) == maxprintline and
not match(line, "%.%.%.$") then
return "", (lastline or "") .. line
end
local line = (lastline or "") .. line
lastline = ""
-- Zap ./ at begin of filename
line = gsub(line, "%(%.%/", "(")
-- Zap paths if places other than 'here' are accessible
if checksearch then
-- The pattern excludes < and > as the image part can have
-- several entries on one line
local pattern = "%w?:?/[^ %<%>]*/([^/%(%)]*%.%w*)"
-- Files loaded from TeX: all start ( -- )
line = gsub(line, "%(" .. pattern, "(../%1")
-- Images
line = gsub(line, "<" .. pattern .. ">", "<../%1>")
-- luaotfload files start with keywords
line = gsub(line, "from " .. pattern .. "%(", "from. ./%1(")
line = gsub(line, ": " .. pattern .. "%)", ": ../%1)")
-- Deal with XeTeX specials
if match(line, "^%.+\\XeTeX.?.?.?file") then
line = gsub(line, pattern, "../%1")
end
end
-- Deal with the fact that "(.aux)" may have still a leading space
line = gsub(line, "^ %(%.aux%)", "(.aux)")
-- Merge all of .fd data into one line so will be removed later
if match(line, "^ *%([%.%/%w]+%.fd[^%)]*$") then
lastline = (lastline or "") .. line
return "", (lastline or "") .. line
end