[latex3-commits] [git/LaTeX3-latex3-l3build] master: Set up tagging (fixes #40) (5b772fb)

Joseph Wright joseph.wright at morningstar2.co.uk
Tue Mar 6 16:32:02 CET 2018


Repository : https://github.com/latex3/l3build
On branch  : master
Link       : https://github.com/latex3/l3build/commit/5b772fba618fb9c2c9a5f88b73d1ff1b824ed6ea

>---------------------------------------------------------------

commit 5b772fba618fb9c2c9a5f88b73d1ff1b824ed6ea
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Mar 6 14:47:11 2018 +0000

    Set up tagging (fixes #40)
    
    This removes "setversion" and related variables.
    
    Notice that --version is removed but needs to be
    'reworked' to give the desired behaviour.


>---------------------------------------------------------------

5b772fba618fb9c2c9a5f88b73d1ff1b824ed6ea
 build.lua              |   19 ++++++-
 l3build-arguments.lua  |    8 +--
 l3build-help.lua       |    2 +-
 l3build-setversion.lua |  140 ------------------------------------------------
 l3build-stdmain.lua    |   26 ++++++---
 l3build-tagging.lua    |   80 +++++++++++++++++++++++++++
 l3build-variables.lua  |    2 +-
 l3build.dtx            |   99 ++++++++++++++--------------------
 l3build.lua            |    2 +-
 9 files changed, 162 insertions(+), 216 deletions(-)

diff --git a/build.lua b/build.lua
index 66434d6..3eefac7 100644
--- a/build.lua
+++ b/build.lua
@@ -16,9 +16,26 @@ packtdszip   = true
 sourcefiles  = {"*.dtx", "l3build*.lua", "*.ins"}
 typesetcmds  = "\\AtBeginDocument{\\DisableImplementation}"
 unpackdeps   = { }
-versionfiles = {"*.dtx", "*.md", "*.lua"}
+tagfiles     = {"*.dtx", "*.md", "*.lua"}
 
 -- Detail how to set the version automatically
+function update_tag(file,content,tagname,tagdate)
+  if string.match(file, "%.dtx$") then
+    return string.gsub(content,
+      "\n%% \\date{Released %d%d%d%d/%d%d/%d%d}\n",
+      "\n%% \\date{Released " .. tagname .. "}\n")
+  elseif string.match(file, "%.md$") then
+    return string.gsub(content,
+      "\nRelease %d%d%d%d/%d%d/%d%d\n",
+      "\nRelease " .. tagname .. "\n")
+  elseif string.match(file, "%.lua$") then
+    return string.gsub(content,
+      '\nrelease_date = "%d%d%d%d/%d%d/%d%d"\n',
+      '\nrelease_date = "' .. tagname .. '"\n')
+  end
+  return contents
+end
+
 function setversion_update_line(line, date, version)
   local date = string.gsub(date, "%-", "/")
   -- .dtx file
diff --git a/l3build-arguments.lua b/l3build-arguments.lua
index b367039..40c92d5 100644
--- a/l3build-arguments.lua
+++ b/l3build-arguments.lua
@@ -116,13 +116,7 @@ option_list =
       {
         desc = "Location of user texmf tree",
         type = "string"
-      },
-    version =
-      {
-        desc  = "Sets the version to insert into sources",
-        short = "v",
-        type  = "string"
-      },
+      }
   }
 
 -- This is done as a function (rather than do ... end) as it allows early
diff --git a/l3build-help.lua b/l3build-help.lua
index 7226cfa..770022f 100644
--- a/l3build-help.lua
+++ b/l3build-help.lua
@@ -46,7 +46,7 @@ function help()
   if module ~= "" and testfiledir ~= "" then
     print("   save       Saves test validation log")
   end
-  print("   setversion Update version information in sources")
+  print("   tag        Update release tags in files")
   print("   uninstall  Uninstalls files from the local texmf tree")
   print("   unpack     Unpacks the source files into the build tree")
   print("")
diff --git a/l3build-setversion.lua b/l3build-setversion.lua
deleted file mode 100644
index 178bb29..0000000
--- a/l3build-setversion.lua
+++ /dev/null
@@ -1,140 +0,0 @@
---[[
-
-File l3build-setversion.lua Copyright (C) 2018 The LaTeX3 Project
-
-It may be distributed and/or modified under the conditions of the
-LaTeX Project Public License (LPPL), either version 1.3c of this
-license or (at your option) any later version.  The latest version
-of this license is in the file
-
-   http://www.latex-project.org/lppl.txt
-
-This file is part of the "l3build bundle" (The Work in LPPL)
-and all files in that bundle must be distributed together.
-
------------------------------------------------------------------------
-
-The development version of the bundle can be found at
-
-   https://github.com/latex3/l3build
-
-for those people who are interested.
-
---]]
-
-
---[[
-      L3BUILD SETVERSION
-      ==================
---]]
-
-local gsub             = string.gsub
-local match            = string.match
-
--- 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)
-      -- No real regex so do it one type at a time
-      for _,i in pairs({"Class", "File", "Package"}) do
-        if match(
-          line,
-          "^\\Provides" .. i .. "{[a-zA-Z0-9%-%.]+}%[[^%]]*%]$"
-        ) then
-          line = gsub(line, "%[%d%d%d%d/%d%d/%d%d", "["
-            .. gsub(date, "%-", "/"))
-          line = 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)
-      -- No real regex so do it one type at a time
-      for _,i in pairs({"Class", "File", "Package"}) do
-        if match(
-          line,
-          "^\\ProvidesExpl" .. i .. " *{[a-zA-Z0-9%-%.]+}"
-        ) then
-          line = gsub(
-            line,
-            "{%d%d%d%d/%d%d/%d%d}( *){[^}]*}",
-            "{" .. gsub(date, "%-", "/") .. "}%1{" .. version .. "}"
-          )
-          break
-        end
-      end
-      return line
-    end
-  elseif versionform == "filename" then
-    function setversion_update_line(line, date, version)
-      if match(line, "^\\def\\filedate{%d%d%d%d/%d%d/%d%d}$") then
-        line = "\\def\\filedate{" .. gsub(date, "%-", "/") .. "}"
-      end
-      if match(line, "^\\def\\fileversion{[^}]+}$") then
-        line = "\\def\\fileversion{" .. version .. "}"
-      end
-      return line
-    end
-  elseif versionform == "ExplFileDate" then
-    function setversion_update_line(line, date, version)
-      if match(line, "^\\def\\ExplFileDate{%d%d%d%d/%d%d/%d%d}$") then
-        line = "\\def\\ExplFileDate{" .. gsub(date, "%-", "/") .. "}"
-      end
-      if 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(dir, file, date, version)
-    local changed = false
-    local result = ""
-    for line in io.lines(dir .. "/" .. file) do
-      local newline = setversion_update_line(line, date, version)
-      if newline ~= line then
-        line = newline
-        changed = true
-      end
-      result = result .. line .. os_newline
-    end
-    if changed then
-      -- Avoid adding/removing end-of-file newline
-      local f = io.open(dir .. "/" .. file, "rb")
-      local content = f:read("*all")
-      f:close()
-      if not match(content, os_newline .. "$") then
-        gsub(result, os_newline .. "$", "")
-      end
-      -- Write the new file
-      ren(dir, file, file .. bakext)
-      local f = io.open(dir .. "/" .. file, "w")
-      io.output(f)
-      io.write(result)
-      f:close()
-      rmfile(dir, file .. bakext)
-    end
-  end
-  local date = options["date"] or os.date("%Y-%m-%d")
-  local version = options["version"] or -1
-  for _,dir in pairs(remove_duplicates({currentdir, sourcefiledir, docfiledir})) do
-    for _,i in pairs(versionfiles) do
-      for file,_ in pairs(tree(dir, i)) do
-        rewrite(dir, file, date, version)
-      end
-    end
-  end
-  return 0
-end
-
diff --git a/l3build-stdmain.lua b/l3build-stdmain.lua
index d6d59f1..dc30ecd 100644
--- a/l3build-stdmain.lua
+++ b/l3build-stdmain.lua
@@ -66,11 +66,17 @@ function stdmain(target, names)
       errorlevel = ctan()
     elseif target == "install" then
       errorlevel = call(modules, "install")
-    elseif target == "setversion" then
-      errorlevel = call(modules, "setversion")
-      -- Deal with any files in the bundle dir itself
-      if errorlevel == 0 then
-        errorlevel = setversion()
+    elseif target == "tag" then
+      if options["names"] and #options["names"] == 1 then
+        errorlevel = call(modules,"tag")
+        -- Deal with any files in the bundle dir itself
+        if errorlevel == 0 then
+          errorlevel = tag(options["names"][1])
+        end
+      else
+        print("Tag name required")
+        help()
+        exit(1)
       end
     elseif target == "uninstall" then
       errorlevel = call(modules, "uninstall")
@@ -107,8 +113,14 @@ function stdmain(target, names)
       else
         help()
       end
-    elseif target == "setversion" then
-      errorlevel = setversion()
+    elseif target == "tag" then
+      if options["names"] and #options["names"] == 1 then
+        errorlevel = tag(options["names"][1])
+      else
+        print("Tag name required")
+        help()
+        exit(1)
+      end
     elseif target == "uninstall" then
       errorlevel = uninstall()
     elseif target == "unpack" then
diff --git a/l3build-tagging.lua b/l3build-tagging.lua
new file mode 100644
index 0000000..1e62499
--- /dev/null
+++ b/l3build-tagging.lua
@@ -0,0 +1,80 @@
+--[[
+
+File l3build-tagging.lua Copyright (C) 2018 The LaTeX3 Project
+
+It may be distributed and/or modified under the conditions of the
+LaTeX Project Public License (LPPL), either version 1.3c of this
+license or (at your option) any later version.  The latest version
+of this license is in the file
+
+   http://www.latex-project.org/lppl.txt
+
+This file is part of the "l3build bundle" (The Work in LPPL)
+and all files in that bundle must be distributed together.
+
+-----------------------------------------------------------------------
+
+The development version of the bundle can be found at
+
+   https://github.com/latex3/l3build
+
+for those people who are interested.
+
+--]]
+
+local pairs   = pairs
+local open    = io.open
+local os_date = os.date
+local match   = string.match
+local gsub    = string.gsub
+
+update_tag = update_tag or function(filename,content,tagname,tagdate)
+  return content
+end
+
+tag_hook = tag_hook or function(tagname)
+  return 0
+end
+
+local function update_file_tag(file,tagname,tagdate)
+  local filename = basename(file)
+  print("Tagging  ".. filename)
+  local f = assert(open(file,"rb"))
+  local content = f:read("*all")
+  f:close()
+  -- Deal with Unix/Windows line endings
+  content = gsub(content .. (match(content,"\n$") and "" or "\n"),
+    "\r\n", "\n")
+  local updated_content = update_tag(filename,content,tagname,tagdate)
+  if content == updated_content then
+    return 0
+  else
+    local path = dirname(file)
+    ren(path,filename,filename .. ".bak")
+    local f = assert(open(file,"w"))
+    -- Convert line ends back if required during write
+    -- Watch for the second return value!
+    f:write((gsub(updated_content,"\n",os_newline)))
+    f:close()
+    rm(path,filename .. ".bak")
+  end
+  return 0
+end
+
+function tag(tagname)
+  local tagdate = options["date"] or os_date("%Y-%m-%d")
+  local dirs = remove_duplicates({currentdir, sourcefiledir, docfiledir})
+  local errorlevel = 0
+  for _,dir in pairs(dirs) do
+    for _,filetype in pairs(tagfiles) do
+      for file,_ in pairs(tree(dir,filetype)) do
+        errorlevel = update_file_tag(dir .. "/" .. file,tagname,tagdate)
+        if errorlevel ~= 0 then
+          return errorlevel
+        end
+      end
+    end
+  end
+  return tag_hook(tagname)
+end
+
diff --git a/l3build-variables.lua b/l3build-variables.lua
index c7ecbb9..9bf5c3a 100644
--- a/l3build-variables.lua
+++ b/l3build-variables.lua
@@ -108,6 +108,7 @@ excludefiles       = excludefiles       or {"*~"}
 installfiles       = installfiles       or {"*.sty","*.cls"}
 makeindexfiles     = makeindexfiles     or {"*.ist"}
 sourcefiles        = sourcefiles        or {"*.dtx", "*.ins"}
+tagfiles           = tagfiles           or {"*.dtx"}
 textfiles          = textfiles          or {"*.md", "*.txt"}
 typesetdemofiles   = typesetdemofiles   or { }
 typesetfiles       = typesetfiles       or {"*.dtx"}
@@ -115,7 +116,6 @@ typesetsuppfiles   = typesetsuppfiles   or { }
 typesetsourcefiles = typesetsourcefiles 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 { }
diff --git a/l3build.dtx b/l3build.dtx
index 71896a7..1d266f3 100644
--- a/l3build.dtx
+++ b/l3build.dtx
@@ -1,6 +1,6 @@
 % \iffalse
 %
-% File l3build.dtx (C) Copyright 2014-2017 The LaTeX3 Project
+% File l3build.dtx (C) Copyright 2014-2018 The LaTeX3 Project
 %
 % It may be distributed and/or modified under the conditions of the
 % LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -88,6 +88,7 @@
 \luavarset{installfiles}      {\{"*.sty","*.cls"\}}{Files to install to the \TeX{} tree and similar task}
 \luavarset{makeindexfiles}    {\{"*.ist"\}}{MakeIndex files to be included in a TDS-style zip}
 \luavarset{sourcefiles}       {\{"*.dtx", "*.ins"\}}{Files to copy for unpacking}
+\luavarset{tagfiles}          {\{"*.dtx"\}}{Files for automatic tagging}
 \luavarset{textfiles}         {\{"*.md", "*.txt"\}}{Plain text files to send to CTAN as-is}
 \luavarset{typesetdemofiles}  {\{\}}{Files to typeset before the documentation for inclusion in main documentation files}
 \luavarset{typesetfiles}      {\{"*.dtx"\}}{Files to typeset for documentation}
@@ -95,7 +96,6 @@
 \luavarset{typesetsourcefiles}{\{\}}{Files to copy to unpacking when typesetting.}
 \luavarset{unpackfiles}       {\{"*.ins"\}}{Files to run to perform unpacking.}
 \luavarset{unpacksuppfiles}   {\{\}}{Files needed to support unpacking when \enquote{sandboxed}}
-\luavarset{versionfiles}      {\{"*.dtx"\}}{Files for automatic version editing}
 \luavarseparator
 \luavarset{bakext}{".bak"}{Extension of backup files}
 \luavarset{dviext}{".dvi"}{Extension of DVI files}
@@ -153,7 +153,6 @@
 \luavarset{scriptname}  {"build.lua"} {Name of script used in dependencies}
 \luavarset{typesetcmds} {""}          {Instructions to be passed to \TeX{} when doing typesetting.}
 \luavarset{typsetcycles}{3}           {Number of cycles of typesetting to carry out.}
-\luavarset{versionform} {""}          {Nature of version strings for auto-replacement.}
 \luavarset{recordstatus}{false}       {Switch to include error level from test runs in \texttt{.tlg} files}
 \luavarset{manifestfile}        {"MANIFEST.md"} {Filename to use for the manifest file.}
 }
@@ -305,7 +304,7 @@
 % \item doc \meta{name(s)}
 % \item install
 % \item save \meta{name(s)}
-% \item setversion
+% \item tag
 % \item unpack
 % \end{itemize}
 % These commands are described below.
@@ -313,7 +312,7 @@
 % As well as these commands, the system recognises the options
 % \begin{itemize}
 %   \item |--config| (|-c|) Configuration(s) to use for testing
-% \item |--date| Date to use when setting version
+% \item |--date| Date to use when tagging
 %   data
 % \item |--dry-run| Runs the \texttt{install} target but does not copy
 %   any files: simply lists those that would be installed
@@ -334,8 +333,6 @@
 % \item |--rerun| Run tests without unpacking/set up
 % \item |--shuffle| Shuffle the order in whichs tests run
 % \item |--texmfhome| Sets the location of the user tree for installing
-% \item |--version| (|-v|) Version string to use when setting
-%   version data
 % \end{itemize}
 %
 % \begin{buildcmd}{check}
@@ -528,15 +525,14 @@
 % Improvements to this process are planned for the future.
 % \end{buildcmd}
 %
-% \begin{buildcmd}{setversion}
-% 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}
-% a version type for substitution is set up (using \var{versionform} or
-% by defining a custom function).
+% \begin{buildcmd}{tag}
+% Modifies the content of files specified by |tagfiles| to allow
+% automatic updating of the release tag and date. The tag is given as a
+% command line option, whilst the optional date should be passed using
+% |--date| (|-d|); if not given, the date will default to the current date in
+% ISO format (YYYY-MM-DD). As detailed below, the standard set up has no search
+% pattern defined for this target and so no action will be taken \emph{unless}
+% tag substitution is set up.
 % \end{buildcmd}
 %
 % \begin{buildcmd}{unpack}
@@ -1116,56 +1112,43 @@
 %
 % \section{Release-focussed features}
 %
-% \subsection{Automatic version modification}
+% \subsection{Automatic tagging}
 %
-% As detailed above, the |setversion| target will automatically edit
-% source files to modify date and version. This behaviour is governed by
-% variable \var{versionform}. As standard, no automatic replacement
-% takes place, but setting \var{versionform} will allow this to happen,
-% with options
+% As detailed above, the |tag| target will automatically edit
+% source files to modify date and release tag. As standard, no automatic
+% replacement takes place, but setting up a |updae_tag()| function
+% will allow this to happen. This takes four arguments:
 % \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 |ExplFileDate| --- Searches for lines using |\def\ExplFileDate|,
-%     \dots, formulation.
+%   \item The file name
+%   \item The full content of the file
+%   \item The tag name
+%   \item The tag date
 % \end{itemize}
-%
-% For more complex cases, the programmer may directly define the
-% Lua function |setversion_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, |setversion_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 as shown in Figure~\ref{fig:update-line}.
+% and should return the (modified) contents for writing to disk.
+% For example, the function used by |l3build| itself is
+% shown in Figure~\ref{fig:update-tag}.
 % \begin{figure}
 %   \begin{lstlisting}[frame=single,language={[5.2]Lua},gobble = 6]
-%     function setversion_update_line(line, date, version)
-%       -- 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
+%     -- Detail how to set the version automatically
+%     function update_tag(file,content,tagname,tagdate)
+%       if string.match(file, "%.dtx$") then
+%         return string.gsub(content,
+%           "\n%% \\date{Released %d%d%d%d/%d%d/%d%d}\n",
+%           "\n%% \\date{Released " .. tagname .. "}\n")
+%       elseif string.match(file, "%.md$") then
+%         return string.gsub(content,
+%           "\nRelease %d%d%d%d/%d%d/%d%d\n",
+%           "\nRelease " .. tagname .. "\n")
+%       elseif string.match(file, "%.lua$") then
+%         return string.gsub(content,
+%           '\nrelease_date = "%d%d%d%d/%d%d/%d%d"\n',
+%           '\nrelease_date = "' .. tagname .. '"\n')
 %       end
-%       return line
+%       return contents
 %     end
 %   \end{lstlisting}
-%   \caption{Example \texttt{setversion_update_line} function.}
-%   \label{fig:update-line}
+%   \caption{Example \texttt{update_tag} function.}
+%   \label{fig:update-tag}
 % \end{figure}
 %
 % \subsection{Typesetting documentation}
diff --git a/l3build.lua b/l3build.lua
index b81d405..db34db2 100644
--- a/l3build.lua
+++ b/l3build.lua
@@ -59,7 +59,7 @@ build_require("install")
 build_require("unpack")
 build_require("manifest")
 build_require("manifest-setup")
-build_require("setversion")
+build_require("tagging")
 build_require("help")
 build_require("stdmain")
 





More information about the latex3-commits mailing list