[latex3-commits] [git/LaTeX3-latex3-l3build] master: Name consistency, code comments and loop counter removed (b0dae84)
LAURENS Jérôme
jerome.laurens at u-bourgogne.fr
Tue Feb 23 22:26:52 CET 2021
Repository : https://github.com/latex3/l3build
On branch : master
Link : https://github.com/latex3/l3build/commit/b0dae84252fd382df7e82f4d8ecf2312d5b3e594
>---------------------------------------------------------------
commit b0dae84252fd382df7e82f4d8ecf2312d5b3e594
Author: LAURENS Jérôme <jerome.laurens at u-bourgogne.fr>
Date: Tue Feb 23 22:26:52 2021 +0100
Name consistency, code comments and loop counter removed
Adopted suggestions: `str_format`, `engine_info`, `result`, `create_file_list`.
More explicit var names (with explanations)
ternary operator more explicit
Redundant loop counter in check.lua
`pattern` name dropped because of lua patterns.
Commented out code removed
>---------------------------------------------------------------
b0dae84252fd382df7e82f4d8ecf2312d5b3e594
l3build-check.lua | 28 +++++++++++-----------
l3build-file-functions.lua | 58 ++++++++++++++++++++++++++--------------------
l3build-install.lua | 14 +++++------
l3build-upload.lua | 8 -------
4 files changed, 53 insertions(+), 55 deletions(-)
diff --git a/l3build-check.lua b/l3build-check.lua
index 2c9ce22..a307241 100644
--- a/l3build-check.lua
+++ b/l3build-check.lua
@@ -34,7 +34,7 @@ local luatex_version = status.luatex_version
local len = string.len
local char = string.char
-local frmt = string.format
+local str_format = string.format
local gmatch = string.gmatch
local gsub = string.gsub
local match = string.match
@@ -269,7 +269,7 @@ local function normalize_log(content,engine,errlevels)
-- tidy up to match pdfTeX if an ASCII engine is in use
if next(asciiengines) then
for i = 128, 255 do
- line = gsub(line, utf8_char(i), "^^" .. frmt("%02x", i))
+ line = gsub(line, utf8_char(i), "^^" .. str_format("%02x", i))
end
end
return line, lastline
@@ -345,7 +345,7 @@ local function normalize_lua_log(content,luatex)
l,
m .. " (%-?)%d+%.%d+",
m .. " %1"
- .. frmt(
+ .. str_format(
"%.3f",
match(line, m .. " %-?(%d+%.%d+)") or 0
)
@@ -714,13 +714,13 @@ function runtest(name, engine, hide, ext, test_type, breakout)
local binary = engine
local format = gsub(engine,"tex$",checkformat)
-- Special binary/format combos
- if specialformats[checkformat] and next(specialformats[checkformat]) then
- local t = specialformats[checkformat]
- local t_ngn = t[engine]
- if t_ngn then
- binary = t_ngn.binary or binary
- format = t_ngn.format or format
- checkopts = t_ngn.options or checkopts
+ local special_check = specialformats[checkformat]
+ if special_check and next(special_check) then
+ local engine_info = special_check[engine]
+ if engine_info then
+ binary = engine_info.binary or binary
+ format = engine_info.format or format
+ checkopts = engine_info.options or checkopts
end
end
-- Finalise format string
@@ -933,10 +933,8 @@ function check(names)
end
-- Actually run the tests
print("Running checks on")
- local i = 0
- for _,name in ipairs(names) do
- i = i + 1
- print(" " .. name .. " (" .. i.. "/" .. #names ..")")
+ for i, name in ipairs(names) do
+ print(" " .. name .. " (" .. i .. "/" .. #names ..")")
local errlevel = runcheck(name, hide)
-- Return value must be 1 not errlevel
if errlevel ~= 0 then
@@ -1015,7 +1013,7 @@ function save(names)
return 1
end
for _,engine in pairs(engines) do
- local testengine = ((engine == stdengine and "") or ("." .. engine))
+ local testengine = engine == stdengine and "" or ("." .. engine)
local out_file = name .. testengine .. test_type.reference
local gen_file = name .. "." .. engine .. test_type.generated
print("Creating and copying " .. out_file)
diff --git a/l3build-file-functions.lua b/l3build-file-functions.lua
index 2dfaa79..48c2745 100644
--- a/l3build-file-functions.lua
+++ b/l3build-file-functions.lua
@@ -214,12 +214,14 @@ end
-- Copy files 'quietly'
function cp(glob, source, dest)
local errorlevel
- for p_rel,p_cwd in pairs(tree(source, glob)) do
+ for p_src, p_cwd in pairs(tree(source, glob)) do
+ -- p_src is a path relative to `source` whereas
+ -- p_cwd is the counterpart relative to the current working directory
if os_type == "windows" then
if attributes(p_cwd)["mode"] == "directory" then
errorlevel = execute(
'xcopy /y /e /i "' .. unix_to_win(p_cwd) .. '" "'
- .. unix_to_win(dest .. '/' .. p_rel) .. '" > nul'
+ .. unix_to_win(dest .. '/' .. p_src) .. '" > nul'
)
else
errorlevel = execute(
@@ -287,53 +289,59 @@ function filelist(path, glob)
end
-- Does what filelist does, but can also glob subdirectories. In the returned
--- table, the keys are paths relative to the given starting path, the values
+-- table, the keys are paths relative to the given source path, the values
-- are their counterparts relative to the current working directory.
-function tree(path, glob)
+function tree(src_path, glob)
local function cropdots(path)
return gsub(gsub(path, "^%./", ""), "/%./", "/")
end
+ src_path = cropdots(src_path)
+ glob = cropdots(glob)
local function always_true()
return true
end
local function is_dir(file)
return attributes(file)["mode"] == "directory"
end
- local dirs = {["."] = cropdots(path)}
- for pattern, criterion in gmatch(cropdots(glob), "([^/]+)(/?)") do
- criterion = criterion == "/" and is_dir or always_true
- local function fill(path_a, dir, table)
- for _, file in ipairs(filelist(dir, pattern)) do
- local fullpath = path_a .. "/" .. file
+ local result = {["."] = src_path}
+ for glob_part, sep in gmatch(glob, "([^/]+)(/?)/*") do
+ local accept = sep == "/" and is_dir or always_true
+ ---Feeds the given table according to `glob_part`
+ --- at param p_src string path relative to `src_path`
+ --- at param p_cwd string path counterpart relative to the current working directory
+ --- at param table table
+ local function fill(p_src, p_cwd, table)
+ for _, file in ipairs(filelist(p_cwd, glob_part)) do
+ p_src = p_src .. "/" .. file
if file ~= "." and file ~= ".." and
- fullpath ~= builddir
+ p_src ~= builddir -- TODO: ensure that `builddir` is properly formatted
then
- local fulldir = dir .. "/" .. file
- if criterion(fulldir) then
- table[fullpath] = fulldir
+ p_cwd = p_cwd .. "/" .. file
+ if accept(p_cwd) then
+ table[p_src] = p_cwd
end
end
end
end
- local newdirs = {}
- if pattern == "**" then
+ local new_result = {}
+ if glob_part == "**" then
while true do
- local path_a, dir = next(dirs)
- if not path_a then
+ local p_src, p_cwd = next(result)
+ if not p_src then
break
end
- dirs[path_a] = nil
- newdirs[path_a] = dir
- fill(path_a, dir, dirs)
+ result[p_src] = nil
+ new_result[p_src] = p_cwd
+ fill(p_src, p_cwd, result)
end
else
- for path, dir in pairs(dirs) do
- fill(path, dir, newdirs)
+ for p_scr, p_cwd in pairs(result) do
+ fill(p_scr, p_cwd, new_result)
end
end
- dirs = newdirs
+ result = new_result
end
- return dirs
+ return result
end
function remove_duplicates(a)
diff --git a/l3build-install.lua b/l3build-install.lua
index 06dfeb3..f3cd95a 100644
--- a/l3build-install.lua
+++ b/l3build-install.lua
@@ -187,7 +187,7 @@ function install_files(target,full,dry_run)
if errorlevel ~= 0 then return errorlevel end
-- Creates a 'controlled' list of files
- local function create_list(dir,include,exclude)
+ local function create_file_list(dir,include,exclude)
dir = dir or currentdir
include = include or { }
exclude = exclude or { }
@@ -199,18 +199,18 @@ function install_files(target,full,dry_run)
end
end
end
- local ans = { }
+ local result = { }
for _,glob in pairs(include) do
for file,_ in pairs(tree(dir,glob)) do
if not excludelist[file] then
- insert(ans, file)
+ insert(result, file)
end
end
end
- return ans
+ return result
end
- local installlist = create_list(unpackdir,installfiles,{scriptfiles})
+ local installlist = create_file_list(unpackdir,installfiles,{scriptfiles})
if full then
errorlevel = doc()
@@ -229,8 +229,8 @@ function install_files(target,full,dry_run)
end
-- Set up lists: global as they are also needed to do CTAN releases
- typesetlist = create_list(docfiledir,typesetfiles,{sourcefiles})
- sourcelist = create_list(sourcefiledir,sourcefiles,
+ typesetlist = create_file_list(docfiledir,typesetfiles,{sourcefiles})
+ sourcelist = create_file_list(sourcefiledir,sourcefiles,
{bstfiles,installfiles,makeindexfiles,scriptfiles})
if dry_run then
diff --git a/l3build-upload.lua b/l3build-upload.lua
index a4dcf10..629d2ee 100644
--- a/l3build-upload.lua
+++ b/l3build-upload.lua
@@ -254,14 +254,6 @@ function construct_ctan_post(uploadfile,debug)
ctan_field("uploader", uploadconfig.uploader, 255, "Name of uploader", true, false )
ctan_field("version", uploadconfig.version, 32, "Package version", true, false )
- --[=[ `qq` is unused because line 258 is commented
- -- finish constructing the curl command:
- local qq = '"'
- if os_type == "windows" then
- qq = '\"'
- end
- --]=]
--- commandline ctan_post = ctan_post .. ' --form ' .. qq .. 'file=@' .. tostring(uploadfile) .. ';filename=' .. tostring(uploadfile) .. qq
ctan_post = ctan_post .. '\nform="file=@' .. tostring(uploadfile) . ';filename=' .. tostring(uploadfile) .. '"'
return ctan_post
More information about the latex3-commits
mailing list.