Debian Codegraph @

texk/texlive/linked_scripts/l3build/l3build.lua

raw symbols SCIP
1 #!/usr/bin/env texlua
2
3 --[[
4
5 File l3build.lua Copyright (C) 2014-2025 The LaTeX Project
6
7 It may be distributed and/or modified under the conditions of the
8 LaTeX Project Public License (LPPL), either version 1.3c of this
9 license or (at your option) any later version. The latest version
10 of this license is in the file
11
12 https://www.latex-project.org/lppl.txt
13
14 This file is part of the "l3build bundle" (The Work in LPPL)
15 and all files in that bundle must be distributed together.
16
17 -----------------------------------------------------------------------
18
19 The development version of the bundle can be found at
20
21 https://github.com/latex3/l3build
22
23 for those people who are interested.
24
25 --]]
26
27 -- Version information
28 release_date = "2025-12-24"
29
30 -- File operations are aided by the LuaFileSystem module
31 local lfs = require("lfs")
32
33 -- Local access to functions
34
35 local ipairs = ipairs
36 local insert = table.insert
37 local lookup = kpse.lookup
38 local match = string.match
39 local gsub = string.gsub
40 local next = next
41 local print = print
42 local exit = os.exit
43 local open = io.open
44
45 -- l3build setup and functions
46 kpse.set_program_name("kpsewhich")
47 build_kpse_path = match(lookup("l3build.lua"),"(.*[/])")
48 local function build_require(s)
49 require(lookup("l3build-"..s..".lua", { path = build_kpse_path } ) )
50 end
51
52 -- Minimal code to do basic checks
53 build_require("arguments")
54 build_require("help")
55
56 build_require("file-functions")
57 build_require("typesetting")
58 build_require("aux")
59 build_require("clean")
60 build_require("check")
61 build_require("ctan")
62 build_require("install")
63 build_require("unpack")
64 build_require("manifest")
65 build_require("manifest-setup")
66 build_require("tagging")
67 build_require("upload")
68 build_require("stdmain")
69
70 -- This has to come after stdmain(),
71 -- and that has to come after the functions are defined
72 if options["target"] == "help" then
73 help()
74 exit(0)
75 elseif options["target"] == "version" then
76 version()
77 exit(0)
78 end
79
80 -- Look for some configuration details
81 if fileexists("build.lua") then
82 dofile("build.lua")
83 else
84 print("Error: Cannot find configuration build.lua")
85 exit(1)
86 end
87
88 -- Load standard settings for variables:
89 -- comes after any user versions
90 build_require("variables")
91
92 -- Ensure that directories are 'space safe'
93 maindir = escapepath(maindir)
94 docfiledir = escapepath(docfiledir)
95 sourcefiledir = escapepath(sourcefiledir)
96 supportdir = escapepath(supportdir)
97 testfiledir = escapepath(testfiledir)
98 testsuppdir = escapepath(testsuppdir)
99 builddir = escapepath(builddir)
100 distribdir = escapepath(distribdir)
101 localdir = escapepath(localdir)
102 resultdir = escapepath(resultdir)
103 testdir = escapepath(testdir)
104 typesetdir = escapepath(typesetdir)
105 unpackdir = escapepath(unpackdir)
106
107 -- Tidy up the epoch setting
108 -- Force an epoch if set at the command line
109 -- Must be done after loading variables, etc.
110 if options["epoch"] then
111 epoch = options["epoch"]
112 forcecheckepoch = true
113 forcedocepoch = true
114 end
115 epoch = normalize_epoch(epoch)
116 -- LuaTeX needs the `-utc` option
117 if forcecheckepoch then
118 if next(specialformats) and next(specialformats.latex)
119 and next (specialformats.latex.luatex) then
120 local options = specialformats.latex.luatex.options
121 specialformats.latex.luatex.options = (options and (options .. " ") or "") .. "-utc"
122 end
123 if next(specialformats) and next(specialformats["latex-dev"])
124 and next (specialformats["latex-dev"].luatex) then
125 local options = specialformats["latex-dev"].luatex.options
126 specialformats["latex-dev"].luatex.options = (options and (options .. " ") or "") .. "-utc"
127 end
128 end
129 if forcedocepoch then
130 if match(typesetexe,"luatex") or match(typesetexe,"lualatex") then
131 typesetopts = typesetopts .. " -utc"
132 end
133 end
134 -- Allow for LaTeX "dev" release
135 if options["dev"] then
136 if checkformat == "latex" then
137 checkformat = "latex-dev"
138 elseif checkformat ~= "latex-dev" then
139 print("Ignoring --dev option with non-LaTeX format")
140 end
141 end
142
143 --
144 -- Deal with multiple configs for tests
145 --
146
147 -- When we have specific files to deal with, only use explicit configs
148 -- (or just the default one)
149 if options["names"] then
150 checkconfigs = options["config"] or {"build"}
151 else
152 checkconfigs = options["config"] or checkconfigs
153 end
154
155 if #checkconfigs > 1 then
156 if options["target"] == "check" or options["target"] == "bundlecheck" then
157 local errorlevel = 0
158 local failed = { }
159 for i = 1, #checkconfigs do
160 options["config"] = {checkconfigs[i]}
161 errorlevel = call({"."}, "check", options)
162 if errorlevel ~= 0 then
163 if options["halt-on-error"] then
164 exit(1)
165 else
166 insert(failed,checkconfigs[i])
167 end
168 end
169 end
170 if next(failed) then
171 for _,config in ipairs(failed) do
172 checkdiff(config)
173 end
174 if options["show-saves"] then
175 local savecmds, recheckcmds = "", ""
176 for _,config in ipairs(failed) do
177 local testdir = testdir
178 if config ~= "build" then
179 testdir = testdir .. "-" .. config
180 end
181 local f = open(testdir .. "/.savecommands")
182 if not f then
183 print("Error: Cannot find save commands for configuration \"" ..
184 config .. "\"")
185 exit(2)
186 end
187 for line in f:lines() do
188 if line == "" then break end
189 savecmds = savecmds .. " " .. line .. "\n"
190 end
191 for line in f:lines() do
192 recheckcmds = recheckcmds .. " " .. line .. "\n"
193 end
194 f:close()
195 end
196 print"To regenerate the test files, run\n"
197 print(savecmds)
198 if recheckcmds ~= "" and #checkengines ~= 1 then
199 print"To detect engine-specific differences, run after that\n"
200 print(recheckcmds)
201 end
202 end
203 exit(1)
204 else
205 -- Avoid running the 'main' set of tests twice
206 exit(0)
207 end
208 elseif options["target"] == "clean" then
209 local failure
210 for i = 1, #checkconfigs do
211 options["config"] = {checkconfigs[i]}
212 failure = 0 ~= call({"."}, "clean", options) or failure
213 end
214 exit(failure and 1 or 0)
215 end
216 end
217 if #checkconfigs == 1 and
218 (options["target"] == "check" or options["target"] == "save" or options["target"] == "clean") then
219 if checkconfigs[1] == "build" then
220 -- Sanity check for default config
221 check_engines("build.lua")
222 else
223 local configname = gsub(checkconfigs[1], "%.lua$", "")
224 local config = "./" .. configname .. ".lua"
225 if fileexists(config) then
226 local savedtestfiledir = testfiledir
227 dofile(config)
228 -- Sanity check for non-default config
229 check_engines(configname .. ".lua")
230 testdir = testdir .. "-" .. configname
231 -- Reset testsuppdir if required
232 if savedtestfiledir ~= testfiledir and
233 testsuppdir == savedtestfiledir .. "/support" then
234 testsuppdir = testfiledir .. "/support"
235 end
236 else
237 print("Error: Cannot find configuration \"" .. configname .. ".lua\"")
238 exit(1)
239 end
240 end
241 end
242
243 -- Call the main function
244 main(options["target"], options["names"])