[latex3-commits] [l3svn] 01/04: l3build: replace relative with absolute paths

noreply at latex-project.org noreply at latex-project.org
Sat May 13 10:25:06 CEST 2017


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

joseph pushed a commit to branch master
in repository l3svn.

commit 27f77d4ec58801ea2ac3453403d5591e8fc5d40f
Author: XZS <d.f.fischer at web.de>
Date:   Fri Apr 14 12:16:25 2017 +0200

    l3build: replace relative with absolute paths
    
    The relpath function is broken in multiple places. A comment directs it
    to look from the source, followed directly by a line looking from the
    target. In the component comparison routine, a "target" also takes the
    place of a "source".  These bugs never surfaced because the paths fed to
    the functions always were of equal length.
    
    However, fixing them just reveals the deeper flaws of the algorithm. It
    cannot deal with the current directory (".") correctly, which is fed to
    it in many places.
    
    Due to the nature of Lua, a sane, portable implementation is quite
    complex. Instead, ripping it out and relying solemnly on absolute paths
    in its place proves to be more easy and robust. Inspiration for this
    change came from Waf [1], a general-purpose build system, which also
    largely refrains from explicit relative paths altogether.
    
    Note that absolute paths are required by tools such as MakeIndex when
    allowing typesetting in complex set ups (for example when not
    everything is in the working directory).
    
    [1]: https://waf.io/
---
 l3build/l3build.dtx |   16 ++++++++--------
 l3build/l3build.lua |   38 ++++++++++++--------------------------
 2 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/l3build/l3build.dtx b/l3build/l3build.dtx
index 2d9da6d..0cd73c5 100644
--- a/l3build/l3build.dtx
+++ b/l3build/l3build.dtx
@@ -1145,6 +1145,14 @@
 % modelled on Unix command line commands but reflect the need to work on
 % Windows in a flexible way.
 %
+% \begin{function}{abspath()}
+%   \begin{syntax}
+%     |abspath(|\meta{target}|)|
+%   \end{syntax}
+%   Returns a string which gives the absolute location of the
+%   \meta{target} directory.
+% \end{function}
+%
 % \begin{function}{cleandir()}
 %   \begin{syntax}
 %     |cleandir(|\meta{dir}|)|
@@ -1190,14 +1198,6 @@
 %   Creates the \meta{dir}; returns an error level.
 % \end{function}
 %
-% \begin{function}{relpath()}
-%   \begin{syntax}
-%     |relpath(|\meta{target}, \meta{source}|)|
-%   \end{syntax}
-%   Returns a string which gives the location of the \meta{target} directory
-%   relative to the \meta{source}.
-% \end{function}
-%
 % \begin{function}{ren()}
 %   \begin{syntax}
 %     |ren(|\meta{dir}, \meta{source}, \meta{destination}|)|
diff --git a/l3build/l3build.lua b/l3build/l3build.lua
index bb16891..ac281fe 100644
--- a/l3build/l3build.lua
+++ b/l3build/l3build.lua
@@ -565,27 +565,13 @@ function mkdir(dir)
   end
 end
 
--- Find the relationship between two directories
-function relpath(target, source)
-  -- A shortcut for the case where the two are the same
-  if target == source then
-    return ""
-  end
-  local resultdir = ""
-  local trimpattern = "^[^/]*/"
-  -- Trim off identical leading directories
-  while
-    (match(target, trimpattern) or "X") ==
-    (match(target, trimpattern) or "Y") do
-    target = gsub(target, trimpattern, "")
-    source = gsub(source, trimpattern, "")
-  end
-  -- Go up from the source
-  for i = 0, select(2, gsub(target, "/", "")) do
-    resultdir = resultdir .. "../"
-  end
-  -- Return the relative part plus the unique part of the target
-  return resultdir .. target
+-- Return an absolute path from a relative one
+function abspath(path)
+  local oldpwd = lfs.currentdir()
+  lfs.chdir(path)
+  local result = lfs.currentdir()
+  lfs.chdir(oldpwd)
+  return result
 end
 
 -- Rename
@@ -1442,7 +1428,7 @@ function runtool(envvar, command)
     run(
       typesetdir,
       os_setenv .. " " .. envvar .. "=." .. os_pathsep
-        .. relpath(localdir, typesetdir)
+        .. abspath(localdir)
         .. (typesetsearch and os_pathsep or "") ..
       os_concat ..
       command
@@ -1483,7 +1469,7 @@ function bibtex(name)
         runtool(
           "BIBINPUTS",
           os_setenv .. " BSTINPUTS=." .. os_pathsep
-            .. relpath(localdir, typesetdir)
+            .. abspath(localdir)
             .. (typesetsearch and os_pathsep or "") ..
           os_concat ..
           bibtexexe .. " " .. bibtexopts .. " " .. name
@@ -1710,7 +1696,7 @@ function cmdcheck()
     cp(i, supportdir, testdir)
   end
   local engine = gsub(stdengine, "tex$", "latex")
-  local localdir = relpath(localdir, testdir)
+  local localdir = abspath(localdir)
   print("Checking source files")
   for _,i in ipairs(cmdchkfiles) do
     for _,j in ipairs(filelist(".", i)) do
@@ -1879,7 +1865,7 @@ function doc(files)
           end
         end
         if typeset then
-          local errorlevel = typesetpdf(relpath(dir, ".") .. "/" .. j)
+          local errorlevel = typesetpdf(abspath(dir) .. "/" .. j)
           if errorlevel ~= 0 then
             return errorlevel
           end
@@ -2120,7 +2106,7 @@ bundleunpack = bundleunpack or function(sourcedir)
       -- on Unix the "yes" command can't be used inside execute (it never
       -- stops, which confuses Lua)
       execute(os_yes .. ">>" .. localdir .. "/yes")
-      local localdir = relpath(localdir, unpackdir)
+      local localdir = abspath(localdir)
       errorlevel = run(
         unpackdir,
         os_setenv .. " TEXINPUTS=." .. os_pathsep

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


More information about the latex3-commits mailing list