summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3build
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-10-14 22:32:58 +0000
committerKarl Berry <karl@freefriends.org>2015-10-14 22:32:58 +0000
commit0346eca0b9378bffafb6b32579dd4542b71b57f5 (patch)
treef9a5b79922bd74de6945c98e47f9b1d3009da982 /Master/texmf-dist/tex/latex/l3build
parent6028cf981b015fefcf1205f6cba193542627ddbf (diff)
l3 (14oct15)
git-svn-id: svn://tug.org/texlive/trunk@38642 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3build')
-rw-r--r--Master/texmf-dist/tex/latex/l3build/l3build.lua166
1 files changed, 156 insertions, 10 deletions
diff --git a/Master/texmf-dist/tex/latex/l3build/l3build.lua b/Master/texmf-dist/tex/latex/l3build/l3build.lua
index d1abc997109..7238c9a2167 100644
--- a/Master/texmf-dist/tex/latex/l3build/l3build.lua
+++ b/Master/texmf-dist/tex/latex/l3build/l3build.lua
@@ -98,6 +98,7 @@ typesetfiles = typesetfiles or {"*.dtx"}
typesetsuppfiles = typesetsuppfiles 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 { }
@@ -151,8 +152,10 @@ checkruns = checkruns or 1
packtdszip = packtdszip or false -- Not actually needed but clearer
scriptname = scriptname or "build.lua" -- Script used in each directory
typesetcmds = typesetcmds or ""
+versionform = versionform or ""
-- Extensions for various file types: used to abstract out stuff a bit
+bakext = bakext or ".bak"
logext = logext or ".log"
lveext = lveext or ".lve"
lvtext = lvtext or ".lvt"
@@ -167,25 +170,31 @@ function argparse()
local files = { }
local long_options =
{
- engine = "engine",
- ["halt-on-error"] = "halt" ,
- ["halt-on-failure"] = "halt" ,
- help = "help" ,
- quiet = "quiet"
+ date = "date" ,
+ engine = "engine" ,
+ ["halt-on-error"] = "halt" ,
+ ["halt-on-failure"] = "halt" ,
+ help = "help" ,
+ quiet = "quiet" ,
+ version = "version"
}
local short_options =
{
- e = "engine",
- h = "help" ,
- H = "halt" ,
- q = "quiet"
+ d = "date" ,
+ e = "engine" ,
+ h = "help" ,
+ H = "halt" ,
+ q = "quiet" ,
+ v = "version"
}
local option_args =
{
+ date = true ,
engine = true ,
halt = false,
help = false,
- quiet = false
+ quiet = false,
+ version = true
}
-- arg[1] is a special case: must be a command or "-h"/"--help"
-- Deal with this by assuming help and storing only apparently-valid
@@ -290,10 +299,12 @@ end
userargs = argparse()
+optdate = userargs["date"]
optengines = userargs["engine"]
opthalt = userargs["halt"]
opthelp = userargs["help"]
optquiet = userargs["quiet"]
+optversion = userargs["version"]
-- Convert a file glob into a pattern for use by e.g. string.gub
-- Based on https://github.com/davidm/lua-glob-pattern
@@ -575,15 +586,25 @@ function allmodules(target)
.. "\" for module "
.. i
)
+ local date = ""
+ if optdate then
+ date = " --date=" .. optdate[1]
+ end
local engines = ""
if optengines then
engines = " --engine=" .. table.concat(optengines, ",")
end
+ local version = ""
+ if optversion then
+ version = " --version=" .. optversion[1]
+ end
local errorlevel = run(
i,
"texlua " .. scriptname .. " " .. target
.. (opthalt and " -H" or "")
+ .. date
.. engines
+ .. version
)
if errorlevel ~= 0 then
return errorlevel
@@ -1307,10 +1328,13 @@ help = help or function()
if module ~= "" and testfiledir ~= "" then
print(" save Saves test validation log")
end
+ print(" setversion Update version information in sources")
print("")
print("Valid options are:")
+ print(" --date|-d Sets the date to insert into sources")
print(" --engine|-e Sets the engine to use for running test")
print(" --halt-on-error|-H Stops running tests after the first failure")
+ print(" --version|-v Sets the version to insert into sources")
print("")
end
@@ -1643,6 +1667,120 @@ function save(names)
end
end
+-- Provide some standard search-and-replace functions
+if versionform ~= "" and not setversion_update_line then
+ if versionform == "ProvidesPackage" then
+ function setversion_update_line(line, date, version)
+ local i
+ -- No real regex so do it one type at a time
+ for _,i in pairs({"Class", "File", "Package"}) do
+ if string.match(
+ line,
+ "^\\Provides" .. i .. "{[a-zA-Z0-9%-]+}%[[^%]]*%]$"
+ ) then
+ line = string.gsub(line, "%[%d%d%d%d/%d%d/%d%d", "["
+ .. string.gsub(date, "%-", "/"))
+ line = string.gsub(
+ line, "(%[%d%d%d%d/%d%d/%d%d) [^ ]*", "%1 " .. version
+ )
+ break
+ end
+ end
+ return line
+ end
+ elseif versionform == "ProvidesExplPackage" then
+ function setversion_update_line(line, date, version)
+ local i
+ -- No real regex so do it one type at a time
+ for _,i in pairs({"Class", "File", "Package"}) do
+ if string.match(
+ line,
+ "^\\ProvidesExpl" .. i .. " *{[a-zA-Z0-9%-]+}"
+ ) then
+ line = string.gsub(
+ line,
+ "{%d%d%d%d/%d%d/%d%d}( *){[^}]*}",
+ "{" .. string.gsub(date, "%-", "/") .. "}%1{" .. version .. "}"
+ )
+ break
+ end
+ end
+ return line
+ end
+ elseif versionform == "filename" then
+ function setversion_update_line(line, date, version)
+ if string.match(line, "^\\def\\filedate{%d%d%d%d/%d%d/%d%d}$") then
+ line = "\\def\\filedate{" .. string.gsub(date, "%-", "/") .. "}"
+ end
+ if string.match(line, "^\\def\\fileversion{[^}]+}$") then
+ line = "\\def\\fileversion{" .. version .. "}"
+ end
+ return line
+ end
+ elseif versionform == "ExplFileName" then
+ function setversion_update_line(line, date, version)
+ if string.match(line, "^\\def\\ExplFileDate{%d%d%d%d/%d%d/%d%d}$") then
+ line = "\\def\\ExplFileDate{" .. string.gsub(date, "%-", "/") .. "}"
+ end
+ if string.match(line, "^\\def\\ExplFileVersion{[^}]+}$") then
+ line = "\\def\\ExplFileVersion{" .. version .. "}"
+ end
+ return line
+ end
+ end
+end
+
+-- Used to actually carry out search-and-replace
+setversion_update_line = setversion_update_line or function(line, date, version)
+ return line
+end
+
+function setversion()
+ local function rewrite(file, date, version)
+ local changed = false
+ local lines = ""
+ for line in io.lines(file) do
+ local newline = setversion_update_line(line, date, version)
+ if newline ~= line then
+ line = newline
+ changed = true
+ end
+ lines = lines .. line .. os_newline
+ end
+ if changed then
+ -- Avoid adding/removing end-of-file newline
+ local f = io.open(file, "rb")
+ local content = f:read("*all")
+ io.close(f)
+ if not string.match(content, os_newline .. "$") then
+ string.gsub(lines, os_newline .. "$", "")
+ end
+ -- Write the new file
+ ren(".", file, file .. bakext)
+ local f = io.open(file, "w")
+ io.output(f)
+ io.write(lines)
+ io.close(f)
+ rm(".", file .. bakext)
+ end
+ end
+ local date = os.date("%Y-%m-%d")
+ if optdate then
+ date = optdate[1] or date
+ end
+ local version = -1
+ if optversion then
+ version = optversion[1] or version
+ end
+ local i, j
+ for _,i in pairs(versionfiles) do
+ for _,j in pairs(filelist(".", i)) do
+ rewrite(j, date, version)
+ end
+ end
+ return 0
+end
+
-- Unpack the package files using an 'isolated' system: this requires
-- a copy of the 'basic' DocStrip program, which is used then removed
function unpack()
@@ -1748,6 +1886,12 @@ function stdmain(target, files)
errorlevel = ctan()
elseif target == "install" then
errorlevel = allmodules("install")
+ elseif target == "setversion" then
+ errorlevel = allmodules("setversion")
+ -- Deal with any files in the bundle dir itself
+ if errorlevel == 0 then
+ errorlevel = setversion()
+ end
elseif target == "unpack" then
errorlevel = allmodules("bundleunpack")
elseif target == "version" then
@@ -1781,6 +1925,8 @@ function stdmain(target, files)
else
help()
end
+ elseif target == "setversion" then
+ errorlevel = setversion()
elseif target == "unpack" then
errorlevel = unpack()
elseif target == "version" then