[latex3-commits] [l3svn] 01/02: l3build: Pre-define some common version string forms

noreply at latex-project.org noreply at latex-project.org
Thu Oct 8 10:25:30 CEST 2015


This is an automated email from the git hooks/post-receive script.

joseph pushed a commit to branch master
in repository l3svn.

commit fb6dfff385f1cebb30ce9ace57107b9d7c2cd7da
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Thu Oct 8 09:21:21 2015 +0100

    l3build: Pre-define some common version string forms
---
 l3build/l3build.dtx |   65 +++++++++++++++++++++++++++++++++++++--------------
 l3build/l3build.lua |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 17 deletions(-)

diff --git a/l3build/l3build.dtx b/l3build/l3build.dtx
index 1069c9b..3624110 100644
--- a/l3build/l3build.dtx
+++ b/l3build/l3build.dtx
@@ -156,6 +156,7 @@
 \luavarset{packtdszip}  {false}       {Build a TDS-style zip file for CTAN?}
 \luavarset{scriptname}  {"build.lua"} {Name of script used in dependencies.}
 \luavarset{typesetcmds} {""}          {Instructions to be passed to \TeX{} when doing typesetting.}
+\luavarset{versionform} {""}          {Nature of version strings for auto-replacement.}
 }
 \allluavars
 \newcommand\luavartypeset{%
@@ -459,13 +460,14 @@
 % \end{buildcmd}
 %
 % \begin{buildcmd}{setversion}
-% Modifies the content of files specified byy |versionfiles| to allow
+% Modifies the content of files specified by |versionfiles| to allow
 % automatic updating of the file date and version. The latter are
 % specified using the |-d| and |-v| command line options and if not
 % given will default to the current date in ISO format (YYYY-MM-DD) and |-1|,
 % respectively. As detailed below, the standard set up has no search pattern
 % defined for this target and so no action will be taken \emph{unless}
-% the programmer has set up the appropriate function in the |build.lua| file.
+% a version type for substitution is set up (using \var{versionform} or
+% by defining a custom function).
 % \end{buildcmd}
 %
 % \begin{buildcmd}{unpack}
@@ -931,30 +933,59 @@
 %   \label{fig:expect-ins}
 % \end{figure}
 %
+% \ection{Release-focussed features}
+%
 % \subsection{Automatic version modification}
 %
-% As detailed above, the |sertversion| target will automatically edit
-% source files to modify date and version. This behaviour is governed by the
+% As detailed above, the |setversion| target will automatically edit
+% source files to modify date and version. This behaviour is governed by
+% variable \luavar{versionform}. As standard, no automatic replacement
+% takes place, but setting \luavar{versionform} will allow this to happen,
+% with options
+% \begin{itemize}
+%   \item |ProvidesPackage| Searches for lines using the \LaTeXe{}
+%     \cs{ProvidesPackage}, \cs{ProvidesClass} and \cs{ProvidesFile}
+%     identifiers (as a whole line).
+%   \item |ProvidesExplPackage| Searches for lines using the \pkg{expl3}
+%     \cs{ProvidesExplPackage}, \cs{ProvidesExplClass} and
+%     \cs{ProvidesExplFile} identifiers (at the start of a line).
+%   \item |filename| Searches for lines using |\def\filename|,
+%     |\def\filedate|, \dots, formulation.
+%   \item |ExplFileName| Searches for lines using |\def\ExplFileName|,
+%     |\def\ExplFileDate|, \dots, formulation.
+% \end{itemize}
+% 
+% For more complex cases, the programmer may directly define the
 % Lua function |update.line()|, which takes as arguments the line of the
 % source, the supplied date and the supplied version. It should return a
 % (possibly unmodified) line and may use one, both or neither of the
 % date and version to update the line. Typically, |update_line| should
 % match to the exact pattern used by the programmer in the source files.
 % For example, for code using macros for the date and version
-% a suitable function might read
-% \begin{verbatim}
-%   function update_line(line, date, version)
-%     local date = string.gsub(date, "%-", "/")
-%     -- Replace the identifiers
-%     if string.match(line, "^\\def\\filedate{%d%d%d%d/%d%d/%d%d}$") then
-%       line = "\\def\\filedate{" .. date .. "}"
-%     end
-%     if string.match(line, "^\\def\\fileversion{%d+}$") then
-%       line = "\\def\\fileversion{" .. version .. "}"
+% a suitable function might read as shown in Figure~\ref{fig:update-line}.
+% \begin{figure}
+%   \begin{lstlisting}[frame=single,language={[5.2]Lua},gobble = 6]
+%     function 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", "[" .. date)
+%           line = string.gsub(
+%             line, "(%[%d%d%d%d/%d%d/%d%d) [^ ]*", "%1 " .. version
+%           )
+%           break
+%         end
+%       end
+%       return line
 %     end
-%     return line
-%  end
-% \end{verbatim}
+%   \end{lstlisting}
+%   \caption{Example \texttt{update_line} function.}
+%   \label{fig:update-line}
+% \end{figure}
 %
 % \subsection{Typesetting documentation}
 %
diff --git a/l3build/l3build.lua b/l3build/l3build.lua
index 36c1c56..d301e56 100644
--- a/l3build/l3build.lua
+++ b/l3build/l3build.lua
@@ -152,6 +152,7 @@ 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  = ""
 
 -- Extensions for various file types: used to abstract out stuff a bit
 logext = logext or ".log"
@@ -1665,6 +1666,67 @@ function save(names)
   end
 end
 
+-- Provide some standard search-and-replace functions
+if versionform ~= "" and not updateline then
+  if versionform == "ProvidesPackage" then
+    function 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", "[" .. 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 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}", "{" .. date .. "}")
+          line = string.gsub(
+            line, "({%d%d%d%d/%d%d/%d%d} *){[^}]*}", "%1{" .. version .. "}"
+          )
+          break
+        end
+      end
+      return line
+    end
+  elseif versionform == "filename" then
+    function update_line(line, date, version)
+      if string.match(line, "^\\def\\filedate{%d%d%d%d/%d%d/%d%d}$") then
+        line = "\\def\\filedate{" .. date .. "}"
+      end
+      if string.match(line, "^\\def\\fileversion{[^}]+}$") then
+        line = "\\def\\fileversion{" .. version .. "}"
+      end
+      return line
+    end
+  elseif versionform == "ExplFileName" then
+    function update_line(line, date, version)
+      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{[^}]+}$") then
+        line = "\\def\\ExplFileVersion{" .. version .. "}"
+      end
+      return line
+    end
+  end
+end
+
 -- Used to actually carry out search-and-replace
 update_line = update_line or function(line, date, version)
   return line

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the latex3-commits mailing list