Skip to content

Commit

Permalink
Remove local, add local
Browse files Browse the repository at this point in the history
Remove local redeclaration of a local variable
Rename locals that hide outer locals (appending '_a' for example).
Simplify the shuffle overhead
Remove unused variable
  • Loading branch information
jlaurens committed Feb 21, 2021
1 parent 942619c commit 0d86c7b
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 79 deletions.
41 changes: 18 additions & 23 deletions l3build-check.lua
Expand Up @@ -134,7 +134,7 @@ local function normalize_log(content,engine,errlevels)
not match(line, "%.%.%.$") then
return "", (lastline or "") .. line
end
local line = (lastline or "") .. line
line = (lastline or "") .. line
lastline = ""
-- Zap ./ at begin of filename
line = gsub(line, "%(%.%/", "(")
Expand Down Expand Up @@ -696,17 +696,17 @@ function runtest(name, engine, hide, ext, pdfmode, breakout)
cp(lvtfile, fileexists(testfiledir .. "/" .. lvtfile)
and testfiledir or unpackdir, testdir)
local checkopts = checkopts
local engine = engine or stdengine
engine = engine or stdengine
local binary = engine
local format = gsub(engine,"tex$",checkformat)
format = gsub(engine,"tex$",checkformat)
-- Special binary/format combos
if specialformats[checkformat] and next(specialformats[checkformat]) then
local t = specialformats[checkformat]
if t[engine] and next(t[engine]) then
local t = t[engine]
binary = t.binary or binary
checkopts = t.options or checkopts
format = t.format or format
local t_ngn = t[engine]
if t_ngn and next(t_ngn) then
binary = t_ngn.binary or binary
checkopts = t_ngn.options or checkopts
format = t_ngn.format or format
end
end
-- Finalise format string
Expand Down Expand Up @@ -807,11 +807,11 @@ function runtest(name, engine, hide, ext, pdfmode, breakout)
for _,filetype in pairs(auxfiles) do
for _,file in pairs(filelist(testdir, filetype)) do
if match(file,"^" .. name .. ".[^.]+$") then
local ext = match(file, "%.[^.]+$")
if ext ~= lvtext and
ext ~= tlgext and
ext ~= lveext and
ext ~= logext then
local e7n = match(file, "%.[^.]+$")
if e7n ~= lvtext and
e7n ~= tlgext and
e7n ~= lveext and
e7n ~= logext then
local newname = gsub(file,"(%.[^.]+)$","." .. engine .. "%1")
if fileexists(testdir,newname) then
rm(testdir,newname)
Expand Down Expand Up @@ -908,17 +908,12 @@ function check(names)
end
end
end
-- https://stackoverflow.com/a/32167188
local function shuffle(tbl)
local len, random = #tbl, rnd
for i = len, 2, -1 do
local j = random(1, i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
return tbl
end
if options["shuffle"] then
names = shuffle(names)
-- https://stackoverflow.com/a/32167188
for i = #names, 2, -1 do
local j = rnd(1, i)
names[i], names[j] = names[j], names[i]
end
end
-- Actually run the tests
print("Running checks on")
Expand Down
39 changes: 19 additions & 20 deletions l3build-file-functions.lua
Expand Up @@ -36,7 +36,6 @@ local execute = os.execute
local exit = os.exit
local getenv = os.getenv
local remove = os.remove
local os_time = os.time
local os_type = os.type
local luatex_revision = status.luatex_revision
Expand Down Expand Up @@ -183,6 +182,7 @@ function abspath(path)
error(msg)
end
-- TODO: Fix the cross platform problem
function escapepath(path)
if os_type == "windows" then
local path,count = gsub(path,'"','')
Expand Down Expand Up @@ -214,22 +214,21 @@ end
-- Copy files 'quietly'
function cp(glob, source, dest)
local errorlevel
for i,_ in pairs(tree(source, glob)) do
local source = source .. "/" .. i
for p_rel,p_cwd in pairs(tree(source, glob)) do
if os_type == "windows" then
if attributes(source)["mode"] == "directory" then
if attributes(p_cwd)["mode"] == "directory" then
errorlevel = execute(
'xcopy /y /e /i "' .. unix_to_win(source) .. '" "'
.. unix_to_win(dest .. '/' .. i) .. '" > nul'
'xcopy /y /e /i "' .. unix_to_win(p_cwd) .. '" "'
.. unix_to_win(dest .. '/' .. p_rel) .. '" > nul'
)
else
errorlevel = execute(
'xcopy /y "' .. unix_to_win(source) .. '" "'
'xcopy /y "' .. unix_to_win(p_cwd) .. '" "'
.. unix_to_win(dest .. '/') .. '" > nul'
)
end
else
errorlevel = execute("cp -RLf '" .. source .. "' '" .. dest .. "'")
errorlevel = execute("cp -RLf '" .. p_cwd .. "' '" .. dest .. "'")
end
if errorlevel ~=0 then
return errorlevel
Expand Down Expand Up @@ -302,10 +301,10 @@ function tree(path, glob)
end
local dirs = {["."] = cropdots(path)}
for pattern, criterion in gmatch(cropdots(glob), "([^/]+)(/?)") do
local criterion = criterion == "/" and is_dir or always_true
local function fill(path, dir, table)
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 .. "/" .. file
local fullpath = path_a .. "/" .. file
if file ~= "." and file ~= ".." and
fullpath ~= builddir
then
Expand All @@ -319,13 +318,13 @@ function tree(path, glob)
local newdirs = {}
if pattern == "**" then
while true do
local path, dir = next(dirs)
if not path then
local path_a, dir = next(dirs)
if not path_a then
break
end
dirs[path] = nil
newdirs[path] = dir
fill(path, dir, dirs)
dirs[path_a] = nil
newdirs[path_a] = dir
fill(path_a, dir, dirs)
end
else
for path, dir in pairs(dirs) do
Expand Down Expand Up @@ -357,7 +356,7 @@ function mkdir(dir)
if os_type == "windows" then
-- Windows (with the extensions) will automatically make directory trees
-- but issues a warning if the dir already exists: avoid by including a test
local dir = unix_to_win(dir)
dir = unix_to_win(dir)
return execute(
"if not exist " .. dir .. "\\nul " .. "mkdir " .. dir
)
Expand All @@ -368,10 +367,10 @@ end
-- Rename
function ren(dir, source, dest)
local dir = dir .. "/"
dir = dir .. "/"
if os_type == "windows" then
local source = gsub(source, "^%.+/", "")
local dest = gsub(dest, "^%.+/", "")
source = gsub(source, "^%.+/", "")
dest = gsub(dest, "^%.+/", "")
return execute("ren " .. unix_to_win(dir) .. source .. " " .. dest)
else
return execute("mv " .. dir .. source .. " " .. dir .. dest)
Expand Down
4 changes: 2 additions & 2 deletions l3build-help.lua
Expand Up @@ -39,7 +39,7 @@ end
function help()
local function setup_list(list)
local longest = 0
for k,v in pairs(list) do
for k,_ in pairs(list) do
if k:len() > longest then
longest = k:len()
end
Expand Down Expand Up @@ -70,7 +70,7 @@ function help()
end
print("")
print("Valid options are:")
local longest,t = setup_list(option_list)
longest,t = setup_list(option_list)
for _,k in ipairs(t) do
local opt = option_list[k]
local filler = rep(" ", longest - k:len() + 1)
Expand Down
24 changes: 12 additions & 12 deletions l3build-install.lua
Expand Up @@ -97,7 +97,7 @@ function uninstall()
if errorlevel ~= 0 then return errorlevel end
-- Finally, clean up special locations
for _,location in ipairs(tdslocations) do
local path,glob = splitpath(location)
local path = splitpath(location)
errorlevel = zapdir(path)
if errorlevel ~= 0 then return errorlevel end
end
Expand Down Expand Up @@ -140,11 +140,11 @@ function install_files(target,full,dry_run)
end
local matched = false
for _,location in ipairs(tdslocations) do
local path,glob = splitpath(location)
local pattern = glob_to_pattern(glob)
local l_dir,l_glob = splitpath(location)
local pattern = glob_to_pattern(l_glob)
if match(filename,pattern) then
insert(paths,path)
insert(filenames,path .. sourcepath .. filename)
insert(paths,l_dir)
insert(filenames,l_dir .. sourcepath .. filename)
matched = true
break
end
Expand All @@ -162,12 +162,12 @@ function install_files(target,full,dry_run)
if next(filenames) then
if not dry_run then
for _,path in pairs(paths) do
local dir = target .. "/" .. path
if not cleanpaths[dir] then
errorlevel = cleandir(dir)
local dir_a = target .. "/" .. path
if not cleanpaths[dir_a] then
errorlevel = cleandir(dir_a)
if errorlevel ~= 0 then return errorlevel end
end
cleanpaths[dir] = true
cleanpaths[dir_a] = true
end
end
for _,file in ipairs(filenames) do
Expand All @@ -192,17 +192,17 @@ function install_files(target,full,dry_run)
exclude = exclude or { }
dir = dir or currentdir
local includelist = { }
local excludelist = { }
local excludelist_a = { }
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
excludelist_a[file] = true
end
end
end
for _,glob in pairs(include) do
for file,_ in pairs(tree(dir,glob)) do
if not excludelist[file] then
if not excludelist_a[file] then
insert(includelist, file)
end
end
Expand Down
10 changes: 4 additions & 6 deletions l3build-manifest-setup.lua
Expand Up @@ -221,18 +221,16 @@ end
--]]
manifest_sort_within_match = manifest_sort_within_match or function(files)
local f = files
table.sort(f)
return f
table.sort(files)
return files
end
manifest_sort_within_group = manifest_sort_within_group or function(files)
local f = files
--[[
-- no-op by default; make your own definition to customise. E.g.:
table.sort(f)
table.sort(files)
--]]
return f
return files
end
--[[
Expand Down
2 changes: 2 additions & 0 deletions l3build-stdmain.lua
Expand Up @@ -22,6 +22,8 @@ for those people who are interested.
--]]
local lfs = require("lfs")
local exit = os.exit
local insert = table.insert
Expand Down
2 changes: 1 addition & 1 deletion l3build-tagging.lua
Expand Up @@ -51,7 +51,7 @@ local function update_file_tag(file,tagname,tagdate)
else
local path = dirname(file)
ren(path,filename,filename .. ".bak")
local f = assert(open(file,"w"))
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)))
Expand Down
20 changes: 10 additions & 10 deletions l3build-typesetting.lua
Expand Up @@ -49,9 +49,9 @@ end
-- An auxiliary used to set up the environmental variables
function runcmd(cmd,dir,vars)
local dir = dir or "."
local dir = abspath(dir)
local vars = vars or {}
dir = dir or "."
dir = abspath(dir)
vars = vars or {}
-- Allow for local texmf files
local env = os_setenv .. " TEXMFCNF=." .. os_pathsep
local localtexmf = ""
Expand Down Expand Up @@ -80,7 +80,7 @@ function biber(name,dir)
end
function bibtex(name,dir)
local dir = dir or "."
dir = dir or "."
if fileexists(dir .. "/" .. name .. ".aux") then
-- LaTeX always generates an .aux file, so there is a need to
-- look inside it for a \citation line
Expand All @@ -105,7 +105,7 @@ function bibtex(name,dir)
end
function makeindex(name,dir,inext,outext,logext,style)
local dir = dir or "."
dir = dir or "."
if fileexists(dir .. "/" .. name .. inext) then
if style == "" then style = nil end
return runcmd(makeindexexe .. " " .. makeindexopts
Expand All @@ -119,15 +119,15 @@ function makeindex(name,dir,inext,outext,logext,style)
end
function tex(file,dir,cmd)
local dir = dir or "."
local cmd = cmd or typesetexe .. typesetopts
dir = dir or "."
cmd = cmd or typesetexe .. typesetopts
return runcmd(cmd .. " \"" .. typesetcmds
.. "\\input " .. file .. "\"",
dir,{"TEXINPUTS","LUAINPUTS"})
end
local function typesetpdf(file,dir)
local dir = dir or "."
dir = dir or "."
local name = jobname(file)
print("Typesetting " .. name)
local fn = typeset
Expand All @@ -141,7 +141,7 @@ local function typesetpdf(file,dir)
print(" ! Compilation failed")
return errorlevel
end
pdfname = name .. pdfext
local pdfname = name .. pdfext
rm(docfiledir,pdfname)
return cp(pdfname,dir,docfiledir)
end
Expand Down Expand Up @@ -226,7 +226,7 @@ function doc(files)
end
-- Now know if we should typeset this source
if typeset then
local errorlevel = typesetpdf(srcname,path)
errorlevel = typesetpdf(srcname,path)
if errorlevel ~= 0 then
return errorlevel
else
Expand Down
2 changes: 0 additions & 2 deletions l3build-unpack.lua
Expand Up @@ -22,8 +22,6 @@ for those people who are interested.
--]]
local execute = os.execute
-- Unpack the package files using an 'isolated' system: this requires
-- a copy of the 'basic' DocStrip program, which is used then removed
function unpack(sources, sourcedirs)
Expand Down

0 comments on commit 0d86c7b

Please sign in to comment.