[latex3-commits] [git/LaTeX3-latex3-l3build] master: Add new --full option (fixes #69) (ad28396)

Joseph Wright joseph.wright at morningstar2.co.uk
Sat Aug 4 15:19:33 CEST 2018


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

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

commit ad2839647838961b389f349f2380dc8cb7b76e06
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sat Aug 4 13:47:46 2018 +0100

    Add new --full option (fixes #69)


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

ad2839647838961b389f349f2380dc8cb7b76e06
 CHANGELOG.md          |    3 ++
 l3build-arguments.lua |    5 ++
 l3build-install.lua   |  139 ++++++++++++++++++++++++++++++++++++++++---------
 l3build.dtx           |   14 +++++
 4 files changed, 136 insertions(+), 25 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f70d15..74544ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Added
+- `--full` option
+
 ### Changed
 - Run PDF-based tests for all engines
 - Tweaks to PDF-based normalisation: new `.tpf` files will be required
diff --git a/l3build-arguments.lua b/l3build-arguments.lua
index 4416ab6..e693ab9 100644
--- a/l3build-arguments.lua
+++ b/l3build-arguments.lua
@@ -79,6 +79,11 @@ option_list =
         short = "f",
         type  = "boolean"
       },
+    full =
+      {
+        desc = "Install all files",
+        type = "boolean"
+      },
     ["halt-on-error"] =
       {
         desc  = "Stops running tests after the first failure",
diff --git a/l3build-install.lua b/l3build-install.lua
index b1dbadd..2c42744 100644
--- a/l3build-install.lua
+++ b/l3build-install.lua
@@ -28,6 +28,7 @@ local print = print
 local set_program = kpse.set_program_name
 local var_value   = kpse.var_value
 
+local gsub  = string.gsub
 local match = string.match
 
 local insert = table.insert
@@ -90,40 +91,128 @@ function uninstall()
          + errorlevel
 end
 
-function install()
-  local function install_files(files,target)
-    if not next(files) then
-      return 0
+function install_files(target,full,dry_run)
+  local function install_files(source,dir,files,subdir,tool)
+    subdir = subdir or moduledir
+    -- For material associated with secondary tools (BibTeX, MakeIndex)
+    -- the structure needed is slightly different from those items going
+    -- into the tex/doc/source trees
+    if tool and module == "base" then
+      subdir = nil
     end
-    local installdir = gethome() .. target
-    if options["dry-run"] then
-      print("\n" .. "Installation root: " .. installdir
-        .. "\n" .. "Installation files:"
-      )
-      for _,filetype in pairs(files) do
-        for _,file in pairs(filelist(unpackdir,filetype)) do
-          print("- " .. file)
+    dir = dir .. (subdir and "/" or "") .. subdir
+    local filenames = { }
+    for _,glob_table in pairs(files) do
+      for _,glob in pairs(glob_table) do
+        for file,_ in pairs(tree(source,glob)) do
+          insert(filenames,file)
         end
       end
-      return 0
-    else
-      errorlevel = cleandir(installdir)
-      if errorlevel ~= 0 then
-        return errorlevel
+    end
+    local errorlevel = 0
+    -- The target is only created if there are actual files to install
+    if next(filenames) then
+      local installdir = target .. "/" .. dir
+      if dry_run then
+        print("\n" .. "For installation in " .. installdir .. ":")
+      else
+        errorlevel = cleandir(installdir)
+        if errorlevel ~= 0 then return errorlevel end
       end
-      for _,filetype in pairs(files) do
-        errorlevel = cp(filetype, unpackdir, installdir)
-        if errorlevel ~= 0 then
-          return errorlevel
+      for _,file in ipairs(filenames) do
+        if dry_run then
+          print("- " .. select(2,splitpath(file)))
+        else
+          errorlevel = cp(file,source,installdir)
+          if errorlevel ~= 0 then return errorlevel end
         end
       end
     end
     return 0
   end
   local errorlevel = unpack()
-  if errorlevel ~= 0 then
-    return errorlevel
+  if errorlevel ~= 0 then return errorlevel end
+  errorlevel = install_files(unpackdir,"tex",{installfiles})
+    + install_files(unpackdir,"bibtex/bst",{bstfiles},module,true)
+    + install_files(unpackdir,"makeindex",{makeindexfiles},module,true)
+    + install_files(unpackdir,"scripts",{scriptfiles},module)
+  if errorlevel ~= 0 then return errorlevel end
+  if full then
+    errorlevel = doc()
+    if errorlevel ~= 0 then return errorlevel end
+
+    -- Creates a 'controlled' list of files
+    local function excludelist(dir,include,exclude)
+      include = include or { }
+      exclude = exclude or { }
+      dir = dir or currentdir
+      local includelist = { }
+      local excludelist = { }
+      for _,glob_table in pairs(exclude) do
+        for _,glob in pairs(glob_table) do
+          for file,_ in pairs(tree(dir,glob)) do
+            excludelist[file] = true
+          end
+        end
+      end
+      for _,glob in pairs(include) do
+        for file,_ in pairs(tree(dir,glob)) do
+          if not excludelist[file] then
+            insert(includelist, file)
+          end
+        end
+      end
+      return includelist
+    end
+
+    -- For the purposes here, any typesetting demo files need to be
+    -- part of the main typesetting list
+    local typesetfiles = typesetfiles
+    for _,glob in pairs(typesetdemofiles) do
+      insert(typesetfiles,glob)
+    end
+
+    -- Find PDF files
+    pdffiles = { }
+    for _,glob in pairs(typesetfiles) do
+      insert(pdffiles,(gsub(glob,"%.%w+$",".pdf")))
+    end
+
+    -- Set up lists: global as they are also needed to do CTAN releases
+    typesetlist = excludelist(docfiledir,typesetfiles,{sourcefiles})
+    sourcelist = excludelist(sourcefiledir,sourcefiles,
+      {bstfiles,installfiles,makeindexfiles,scriptfiles})
+    
+    errorlevel = install_files(sourcefiledir,"source",{sourcelist})
+      + install_files(docfiledir,"doc",
+          {bibfiles,demofiles,docfiles,pdffiles,textfiles,typesetlist})
+    if errorlevel ~= 0 then return errorlevel end
+
+    -- Any script man files need special handling
+    local manfiles = { }
+    for _,glob in pairs(scriptmanfiles) do
+      for file,_ in pairs(tree(docfiledir,glob)) do
+        if dry_run then
+          insert(manfiles,"man" .. match(file,".$") .. "/" ..
+            select(2,splitpath(file)))
+        else
+          -- Man files should have a single-digit extension: the type
+          local installdir = target .. "/doc/man/man"  .. match(file,".$")
+          errorlevel = errorlevel + mkdir(installdir)
+          errorlevel = errorlevel + cp(file,docfiledir,installdir)
+        end
+      end
+    end
+    if next(manfiles) then
+      print("\n" .. "For installation in " .. target .. "/doc/man:")
+      for _,v in ipairs(manfiles) do
+        print("- " .. v)
+      end
+    end
   end
-  return   install_files(installfiles, "/tex/" .. moduledir)
-         + install_files(scriptfiles, "/scripts/" .. module)
+  return errorlevel
+end
+
+function install()
+  return install_files(gethome(),options["full"],options["dry-run"])
 end
diff --git a/l3build.dtx b/l3build.dtx
index a87dd20..257f6af 100644
--- a/l3build.dtx
+++ b/l3build.dtx
@@ -329,6 +329,8 @@
 % \item |--force| (|-f|) Force checks to run even if sanity
 %   checks fail, \emph{e.g.}~when |--engine| is not given in
 %   \luavar{checkengines}
+% \item |--full| Instructs the \texttt{install} target to include the 
+%   \texttt{doc} and \texttt{source} trees
 % \item |--halt-on-error| (|-H|) Specifies that checks
 %   should stop as soon as possible, rather than running all requested
 %   tests; the difference file is printed in the terminal directly in the case of failure
@@ -1259,6 +1261,7 @@
 %       \var{epoch}         & String  \\
 %       \var{first}         & Boolean \\
 %       \var{force}         & Boolean \\
+%       \var{full}          & Boolean \\
 %       \var{halt-on-error} & Boolean \\
 %       \var{help}          & Boolean \\
 %       \var{names}         & Table   \\
@@ -1457,6 +1460,17 @@
 %   |target| in this table is ignored.
 % \end{function}
 %
+% \begin{function}{install_files()}
+%   \begin{syntax}
+%     |install_files(|\meta{target},\meta{full},\meta{dry-run}|)|
+%   \end{syntax}
+%   Installs the files from the module into the TDS root \meta{target}.
+%   If \meta{full} is \texttt{true}, all files are copied: if it is
+%   \texttt{false}, the \texttt{doc} and \texttt{source} trees are skipped.
+%   If \meta{dry-run} is \texttt{true}, no files are copied, but instead the
+%   files which would be copied are reported.
+% \end{function}
+%
 % \subsection{Customising the target list}
 %
 % The targets known to \pkg{l3build} are stored in the global table





More information about the latex3-commits mailing list