diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3build/l3build-file-functions.lua')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3build/l3build-file-functions.lua | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/Master/texmf-dist/tex/latex/l3build/l3build-file-functions.lua b/Master/texmf-dist/tex/latex/l3build/l3build-file-functions.lua index 71311bf51c1..a8c24356353 100644 --- a/Master/texmf-dist/tex/latex/l3build/l3build-file-functions.lua +++ b/Master/texmf-dist/tex/latex/l3build/l3build-file-functions.lua @@ -22,17 +22,31 @@ for those people who are interested. --]] +local pairs = pairs +local print = print + +local open = io.open + +local attributes = lfs.attributes +local currentdir = lfs.currentdir +local chdir = lfs.chdir +local lfs_dir = lfs.dir local execute = os.execute local getenv = os.getenv +local remove = os.remove local os_time = os.time local os_type = os.type +local luatex_revision = status.luatex_revision +local luatex_version = status.luatex_version + local match = string.match local sub = string.sub +local gmatch = string.gmatch local gsub = string.gsub - +local insert = table.insert -- Convert a file glob into a pattern for use by e.g. string.gub -- Based on https://github.com/davidm/lua-glob-pattern @@ -132,9 +146,9 @@ if os_type == "windows" then os_diffexe = getenv("diffexe") or "fc /n" os_grepexe = "findstr /r" os_newline = "\n" - if tonumber(status.luatex_version) < 100 or - (tonumber(status.luatex_version) == 100 - and tonumber(status.luatex_revision) < 4) then + if tonumber(luatex_version) < 100 or + (tonumber(luatex_version) == 100 + and tonumber(luatex_revision) < 4) then os_newline = "\r\n" end os_null = "nul" @@ -143,12 +157,24 @@ if os_type == "windows" then os_yes = "for /l %I in (1,1,200) do @echo y" end +-- Deal with the fact that Windows and Unix use different path separators +local function unix_to_win(path) + return gsub(path, "/", "\\") +end + +function normalize_path(path) + if os_type == "windows" then + return unix_to_win(path) + end + return path +end + -- 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) + local oldpwd = currentdir() + chdir(path) + local result = currentdir() + chdir(oldpwd) return gsub(result, "\\", "/") end @@ -167,7 +193,7 @@ function cp(glob, source, dest) for i,_ in pairs(tree(source, glob)) do local source = source .. "/" .. i if os_type == "windows" then - if lfs.attributes(source)["mode"] == "directory" then + if attributes(source)["mode"] == "directory" then errorlevel = execute( 'xcopy /y /e /i "' .. unix_to_win(source) .. '" "' .. unix_to_win(dest .. '/' .. i) .. '" > nul' @@ -204,7 +230,7 @@ function direxists(dir) end function fileexists(file) - local f = io.open(file, "r") + local f = open(file, "r") if f ~= nil then f:close() return true @@ -222,14 +248,14 @@ function filelist(path, glob) pattern = glob_to_pattern(glob) end if direxists(path) then - for entry in lfs.dir(path) do + for entry in lfs_dir(path) do if pattern then if match(entry, pattern) then - table.insert(files, entry) + insert(files, entry) end else if entry ~= "." and entry ~= ".." then - table.insert(files, entry) + insert(files, entry) end end end @@ -248,10 +274,10 @@ function tree(path, glob) return true end local function is_dir(file) - return lfs.attributes(file)["mode"] == "directory" + return attributes(file)["mode"] == "directory" end local dirs = {["."] = cropdots(path)} - for pattern, criterion in string.gmatch(cropdots(glob), "([^/]+)(/?)") do + for pattern, criterion in gmatch(cropdots(glob), "([^/]+)(/?)") do local criterion = criterion == "/" and is_dir or always_true function fill(path, dir, table) for _, file in ipairs(filelist(dir, pattern)) do @@ -341,7 +367,7 @@ end -- Remove file function rmfile(source, file) - os.remove(source .. "/" .. file) + remove(source .. "/" .. file) -- os.remove doesn't give a sensible errorlevel return 0 end @@ -362,16 +388,6 @@ function run(dir, cmd) return execute("cd " .. dir .. os_concat .. cmd) end --- Deal with the fact that Windows and Unix use different path separators -function unix_to_win(path) - if os_type == "windows" then - return gsub(path, "/", "\\") - else - return path - end -end - - -- Split a path into file and directory component function splitpath(file) local path, name = match(file, "^(.*)/([^/]*)$") |