-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbuild.lua
149 lines (134 loc) · 4.87 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
-- Build script for LaTeX "l3build" files
-- Identify the bundle and module
module = "l3build"
bundle = ""
-- Non-standard settings
checkconfigs = {"build", "config-pdf", "config-plain","config-context"}
checkdeps = { }
checkengines = {"pdftex", "xetex", "luatex", "ptex", "uptex"}
cleanfiles = {"*.pdf", "*.tex", "*.zip"}
exefiles = {"l3build.lua"}
installfiles = {"regression-test.tex"}
packtdszip = true
scriptfiles = {"l3build*.lua"}
scriptmanfiles = {"l3build.1"}
sourcefiles = {"*.dtx", "l3build*.lua", "*.ins"}
typesetruns = 4
typesetcmds = "\\AtBeginDocument{\\DisableImplementation}"
unpackdeps = { }
tagfiles = {
"l3build.1",
"l3build.dtx",
"l3build.ins",
"**/*.md", -- to include README.md in ./examples
"l3build*.lua",
"**/regression-test.cfg"
}
uploadconfig = {
author = "The LaTeX Team",
license = "lppl1.3c",
summary = "A testing and building system for (La)TeX",
topic = {"macro-supp", "package-devel"},
ctanPath = "/macros/latex/contrib/l3build",
repository = "https://github.com/latex3/l3build/",
bugtracker = "https://github.com/latex3/l3build/issues",
update = true,
description = [[
The build system supports testing and building (La)TeX code, on
Linux, macOS, and Windows systems. The package offers:
* A unit testing system for (La)TeX code;
* A system for typesetting package documentation; and
* An automated process for creating CTAN releases.
]]
}
-- Detail how to set the version automatically
function update_tag(file,content,tagname,tagdate)
local iso = "%d%d%d%d%-%d%d%-%d%d"
local url = "https://github.com/latex3/l3build/compare/"
-- update copyright
local year = os.date("%Y")
local oldyear = math.tointeger(year - 1)
if string.match(content,"%(C%)%s*" .. oldyear .. " The LaTeX Project") then
content = string.gsub(content,
"%(C%)%s*" .. oldyear .. " The LaTeX Project",
"(C) " .. year .. " The LaTeX Project")
elseif string.match(content,"%(C%)%s*%d%d%d%d%-" .. oldyear .. " The LaTeX Project") then
content = string.gsub(content,
"%(C%)%s*(%d%d%d%d%-)" .. oldyear .. " The LaTeX Project",
"(C) %1" .. year .. " The LaTeX Project")
end
-- update release date
if string.match(file, "%.1$") then
return string.gsub(content,
'%.TH l3build 1 "' .. iso .. '"\n',
'.TH l3build 1 "' .. tagname .. '"\n')
elseif string.match(file, "%.dtx$") then
return string.gsub(content,
"\n%% \\date{Released " .. iso .. "}\n",
"\n%% \\date{Released " .. tagname .. "}\n")
elseif string.match(file, "%.md$") then
if string.match(file,"CHANGELOG.md") then
local previous = string.match(content,"compare/(" .. iso .. ")%.%.%.HEAD")
if tagname == previous then return content end
content = string.gsub(content,
"## %[Unreleased%]",
"## [Unreleased]\n\n## [" .. tagname .."]")
return string.gsub(content,
iso .. "%.%.%.HEAD",
tagname .. "...HEAD\n[" .. tagname .. "]: " .. url .. previous
.. "..." .. tagname)
end
return string.gsub(content,
"\nRelease " .. iso .. "\n",
"\nRelease " .. tagname .. "\n")
elseif string.match(file, "%.lua$") then
return string.gsub(content,
'\nrelease_date = "' .. iso .. '"\n',
'\nrelease_date = "' .. tagname .. '"\n')
end
return content
end
function tag_hook(tagname)
os.execute('git commit -a -m "Step release tag"')
end
-- Auto-generate a .1 file from the help
function docinit_hook()
local find = string.find
local insert = table.insert
local open = io.open
---@type file*?
local f = assert(open("README.md","rb"))
---@cast f file*
local readme = f:read("a")
f:close()
f = nil
local date_start,date_end = find(readme,"%d%d%d%d%p%d%d%p%d%d")
local man_t = {}
insert(man_t,'.TH ' .. string.upper(module) .. ' 1 "'
.. readme:sub(date_start,date_end) .. '" "LaTeX"\n')
insert(man_t,(".SH NAME\n" .. module .. "\n"))
insert(man_t,(".SH SYNOPSIS\n Usage " .. module .. " <target> [<options>] [<names>]\n"))
insert(man_t,".SH DESCRIPTION")
local _,desc_start = find(readme,"Overview\n--------")
local desc_end,_ = find(readme,"Issues")
local overview = readme:sub(desc_start + 8,desc_end - 2):gsub("[_]",""):gsub("`",'"'):gsub("[*] ","\n * ")
insert(man_t,overview)
local cmd = "texlua ./" .. module .. ".lua --help"
f = assert(io.popen(cmd,"r"))
local help_text = assert(f:read("a"))
f:close()
f = nil
insert(man_t,(help_text:gsub("\nUsage.*names>]\n\n","")
:gsub("Valid targets",".SH COMMANDS\nValid targets")
:gsub("Valid options",".SH OPTIONS\nValid options")
:gsub("Full manual",'.SH "SEE ALSO"\nFull manual')
:gsub("Bug tracker","\nBug tracker")
:gsub("Copyright",".SH AUTHORS\nCopyright")))
f = assert(open(module .. ".1","wb"))
f:write((table.concat(man_t,"\n"):gsub("\n$","")))
f:close()
return 0
end
if not release_date then
dofile("./l3build.lua")
end