[latex3-commits] [l3svn] branch master updated: l3build: Add "setversion" target
noreply at latex-project.org
noreply at latex-project.org
Wed Oct 7 19:06:31 CEST 2015
This is an automated email from the git hooks/post-receive script.
joseph pushed a commit to branch master
in repository l3svn.
The following commit(s) were added to refs/heads/master by this push:
new 5668cc8 l3build: Add "setversion" target
5668cc8 is described below
commit 5668cc8ea78a0468c1c53deb335b31aeb1231086
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Wed Oct 7 12:43:17 2015 +0100
l3build: Add "setversion" target
This will allow auto-editing of files to step version:
needed by us but also useful to others. At present this is
not documented: to do.
Note that as standard there is no attempt to edit: the user has to
define the appropriate function to do the work. Also note that
the file is read one line at a time: this avoids the need to match
for os_newline as it allows normal Lua pattern use for start/end of
line.
---
build-config.lua | 25 +++++++++++++++
build.lua | 12 ++++++++
l3build/l3build.lua | 85 +++++++++++++++++++++++++++++++++++++++++++++------
l3kernel/build.lua | 5 ++-
4 files changed, 116 insertions(+), 11 deletions(-)
diff --git a/build-config.lua b/build-config.lua
index 04ebf7e..93e143d 100644
--- a/build-config.lua
+++ b/build-config.lua
@@ -19,3 +19,28 @@ end
if unpacksearch == nil then
unpacksearch = false
end
+
+-- Detail how to set the version automatically
+function setversion(line, date, version)
+ local changed = false
+ local date = string.gsub(date, "%-", "/")
+ -- Replace the identifiers
+ if string.match(line, "^\\def\\ExplFileDate{%d%d%d%d/%d%d/%d%d}$") then
+ line = "\\def\\ExplFileDate{" .. date .. "}"
+ end
+ if string.match(line, "^\\def\\ExplFileVersion{%d+}$") then
+ line = "\\def\\ExplFileVersion{" .. version .. "}"
+ end
+ -- Update the interlock
+ if string.match(
+ line, "^\\RequirePackage{expl3}%[%d%d%d%d/%d%d/%d%d%]$"
+ ) then
+ line = "\\RequirePackage{expl3}[" .. date .. "]"
+ end
+ if string.match(
+ line, "^%%<package>\\@ifpackagelater{expl3}{%d%d%d%d/%d%d/%d%d}$"
+ ) then
+ line = "%<package>\\@ifpackagelater{expl3}{" .. date .. "}"
+ end
+ return line
+end
diff --git a/build.lua b/build.lua
index 9e38719..04aad15 100644
--- a/build.lua
+++ b/build.lua
@@ -41,15 +41,25 @@ function main (target)
local function dobundles (bundles, target)
local errorlevel = 0
for _,i in ipairs (bundles) do
+ local date = ""
+ if optdate then
+ date = " --date=" .. optdate[1]
+ end
local engines = ""
if optengines then
engines = " --engine=" .. table.concat(optengines, ",")
end
+ version = ""
+ if optversion then
+ version = " --version=" .. optversion[1]
+ end
errorlevel = run(
i,
"texlua " .. scriptname .. " "
.. target .. (opthalt and " -H" or "")
+ .. date
.. engines
+ .. version
)
if errorlevel ~= 0 then
break
@@ -75,6 +85,8 @@ function main (target)
errorlevel = dobundles(bundles, "doc")
elseif target == "install" then
errorlevel = dobundles (bundles, "install")
+ elseif target == "setversion" then
+ errorlevel = dobundles(bundles, "setversion")
elseif target == "unpack" then
errorlevel = dobundles (bundles, "unpack")
elseif target == "version" then
diff --git a/l3build/l3build.lua b/l3build/l3build.lua
index d1abc99..c5874d4 100644
--- a/l3build/l3build.lua
+++ b/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 { }
@@ -167,25 +168,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 +297,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
@@ -1307,10 +1316,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 +1655,55 @@ function save(names)
end
end
+-- Used to actually carry out search-and-replace
+setversion_replace = setversion 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_replace(line, date, version)
+ if newline ~= line then
+ line = newline
+ changed = true
+ end
+ lines = lines .. line .. os_newline
+ end
+ if newlines ~= lines 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
+ local f = io.open(file, "w")
+ io.output(f)
+ io.write(lines)
+ io.close(f)
+ 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 +1809,8 @@ function stdmain(target, files)
errorlevel = ctan()
elseif target == "install" then
errorlevel = allmodules("install")
+ elseif target == "setversion" then
+ errorlevel = allmodules("setversion")
elseif target == "unpack" then
errorlevel = allmodules("bundleunpack")
elseif target == "version" then
@@ -1781,6 +1844,8 @@ function stdmain(target, files)
else
help()
end
+ elseif target == "setversion" then
+ errorlevel = setversion()
elseif target == "unpack" then
errorlevel = unpack()
elseif target == "version" then
diff --git a/l3kernel/build.lua b/l3kernel/build.lua
index 71bd5a3..5db4f91 100644
--- a/l3kernel/build.lua
+++ b/l3kernel/build.lua
@@ -35,7 +35,8 @@ typesetfiles =
"l3styleguide.tex", "source3.tex"
}
typesetskipfiles = {"source3-body.tex"}
-unpackfiles = {"l3.ins"}
+unpackfiles = {"l3.ins"}
+versionfiles = {"expl3.dtx"}
-- No deps other than the test system
checkdeps = {maindir .. "/l3build"}
@@ -110,6 +111,8 @@ function main(target, files)
else
help()
end
+ elseif target == "setversion" then
+ errorlevel = setversion()
elseif target == "unpack" then
errorlevel = unpack()
elseif target == "version" then
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the latex3-commits
mailing list