Skip to content

Commit

Permalink
execute51
Browse files Browse the repository at this point in the history
l3build-setup.lua defines execute51 and a local require
  • Loading branch information
jlaurens committed Jun 20, 2024
1 parent c6f0168 commit 0cf5d90
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 45 deletions.
12 changes: 7 additions & 5 deletions l3build-check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ local sort = table.sort
local utf8_char = unicode.utf8.char

local exit = os.exit
local execute = os.execute
local remove = os.remove

local L3B = require("l3build")
local execute51 = L3B.execute51

-- randomise the random numbers
math.randomseed( os.time() )

Expand Down Expand Up @@ -87,7 +89,7 @@ function checkinit()
for _,i in ipairs(checksuppfiles) do
cp(i, supportdir, testdir)
end
execute(os_ascii .. ">" .. testdir .. "/ascii.tcx")
execute51(os_ascii .. ">" .. testdir .. "/ascii.tcx")
return checkinit_hook()
end

Expand Down Expand Up @@ -699,7 +701,7 @@ function base_compare(test_type,name,engine,cleanup)
if compare then
return compare(difffile, reffile, genfile, cleanup, name, engine)
end
local errorlevel = execute(os_diffexe .. " "
local errorlevel = execute51(os_diffexe .. " "
.. normalize_path(reffile .. " " .. genfile .. " > " .. difffile))
if errorlevel == 0 or cleanup then
remove(difffile)
Expand All @@ -726,14 +728,14 @@ function compare_tlg(difffile, tlgfile, logfile, cleanup, name, engine)
local luatlgfile = testdir .. "/" .. testname .. tlgext
rewrite(tlgfile,luatlgfile,normalize_lua_log)
rewrite(logfile,lualogfile,normalize_lua_log,true)
errorlevel = execute(os_diffexe .. " "
errorlevel = execute51(os_diffexe .. " "
.. normalize_path(luatlgfile .. " " .. lualogfile .. " > " .. difffile))
if cleanup then
remove(lualogfile)
remove(luatlgfile)
end
else
errorlevel = execute(os_diffexe .. " "
errorlevel = execute51(os_diffexe .. " "
.. normalize_path(tlgfile .. " " .. logfile .. " > " .. difffile))
end
if errorlevel == 0 or cleanup then
Expand Down
3 changes: 2 additions & 1 deletion l3build-ctan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ local attributes = lfs.attributes
local lower = string.lower
local match = string.match

local newzip = require"l3build-zip"
local L3B = require("l3build")
local newzip = L3B.require("zip")

-- Copy files to the main CTAN release directory
function copyctan()
Expand Down
29 changes: 16 additions & 13 deletions l3build-file-functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ local gsub = string.gsub

local insert = table.insert

local L3B = require("l3build")
local execute51 = L3B.execute51

-- Convert a file glob into a pattern for use by e.g. string.gub
-- Based on https://github.com/davidm/lua-glob-pattern
-- Simplified substantially: "[...]" syntax not supported as is not
Expand Down Expand Up @@ -233,25 +236,25 @@ function cp(glob, source, dest)
-- p_cwd is the counterpart relative to the current working directory
if os_type == "windows" then
if direxists(p.cwd) then
errorlevel = execute(
errorlevel = execute51(
'xcopy /y /e /i "' .. unix_to_win(p.cwd) .. '" '
.. unix_to_win(dest .. '/' .. escapepath(p.src)) .. ' > nul'
) and 0 or 1
)
else
errorlevel = execute(
errorlevel = execute51(
'xcopy /y "' .. unix_to_win(p.cwd) .. '" '
.. unix_to_win(dest .. '/') .. ' > nul'
) and 0 or 1
)
end
else
-- Ensure we get similar behavior on all platforms
if not direxists(dirname(dest)) then
errorlevel = mkdir(dirname(dest))
if errorlevel ~=0 then return errorlevel end
end
errorlevel = execute(
errorlevel = execute51(
"cp -RLf '" .. p.cwd .. "' " .. dest
) and 0 or 1
)
end
if errorlevel ~=0 then
return errorlevel
Expand Down Expand Up @@ -377,11 +380,11 @@ function mkdir(dir)
-- Windows (with the extensions) will automatically make directory trees
-- but issues a warning if the dir already exists: avoid by including a test
dir = unix_to_win(dir)
return execute(
return execute51(
"if not exist " .. dir .. "\\nul " .. "mkdir " .. dir
)
else
return execute("mkdir -p " .. dir)
return execute51("mkdir -p " .. dir)
end
end

Expand All @@ -391,9 +394,9 @@ function ren(dir, source, dest)
if os_type == "windows" then
source = gsub(source, "^%.+/", "")
dest = gsub(dest, "^%.+/", "")
return execute("ren " .. unix_to_win(dir) .. source .. " " .. dest)
return execute51("ren " .. unix_to_win(dir) .. source .. " " .. dest)
else
return execute("mv " .. dir .. source .. " " .. dir .. dest)
return execute51("mv " .. dir .. source .. " " .. dir .. dest)
end
end

Expand All @@ -418,15 +421,15 @@ function rmdir(dir)
-- First, make sure it exists to avoid any errors
mkdir(dir)
if os_type == "windows" then
return execute("rmdir /s /q " .. unix_to_win(dir))
return execute51("rmdir /s /q " .. unix_to_win(dir))
else
return execute("rm -r " .. dir)
return execute51("rm -r " .. dir)
end
end

-- Run a command in a given directory
function run(dir, cmd)
return execute("cd " .. dir .. os_concat .. cmd)
return execute51("cd " .. dir .. os_concat .. cmd)
end

-- Split a path into file and directory component
Expand Down
67 changes: 67 additions & 0 deletions l3build-setup.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--[[
File l3build-file-functions.lua Copyright (C) 2018-2024 The LaTeX Project
It may be distributed and/or modified under the conditions of the
LaTeX Project Public License (LPPL), either version 1.3c of this
license or (at your option) any later version. The latest version
of this license is in the file
https://www.latex-project.org/lppl.txt
This file is part of the "l3build bundle" (The Work in LPPL)
and all files in that bundle must be distributed together.
-----------------------------------------------------------------------
The development version of the bundle can be found at
https://github.com/latex3/l3build
for those people who are interested.
--]]

--[[
The very first call:
require("l3build-setup")
Then
local l3B = require("l3build")
After that, we have access to `L3B.execute51`, and `l3B.require`.
]]
-- reentrant management, in case of L3B.require("setup")
if package.loaded.l3build then
return package.loaded.l3build
end

local M = { -- the return table
_DESCRIPTION = "l3build main table"
}

package.loaded.l3build = M -- from now on `require("l3build")` returns M

local execute = os.execute -- version 5.1 see https://tug.org/pipermail/luatex/2015-November/005535.html

---Execute a command sticking version 5.1 output
---
---`texlua` 1.18 uses Lua 5.3 except for `os.execute` which is still 5.1.
---A wrapper will simplify migration to Lua 5.4, if ever.
---@param command string?
---@return integer
function M.execute51(command)
---@diagnostic disable-next-line: return-type-mismatch
return execute(command)
end

---Wrapper over `require`
---
---Returns only one value as of Lua 5.3. Ready for Lua 5.4.
---@param module string without the "l3build-" prefix
---@return unknown
---@usage Public
function M.require(module)
local ans = require("l3build-"..module)
return ans
end

return M
46 changes: 20 additions & 26 deletions l3build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,39 @@ for those people who are interested.
-- Version information
release_date = "2024-05-27"

-- File operations are aided by the LuaFileSystem module
local lfs = require("lfs")

-- Local access to functions

local ipairs = ipairs
local insert = table.insert
local lookup = kpse.lookup
local match = string.match
local gsub = string.gsub
local next = next
local print = print
local exit = os.exit
local open = io.open

-- l3build setup and functions
-- Activate kpse in 'require':
kpse.set_program_name("kpsewhich")
build_kpse_path = match(lookup("l3build.lua"),"(.*[/])")
local function build_require(s)
require(lookup("l3build-"..s..".lua", { path = build_kpse_path } ) )
end

local L3B = require("l3build-setup")

-- Minimal code to do basic checks
build_require("arguments")
build_require("help")

build_require("file-functions")
build_require("typesetting")
build_require("aux")
build_require("clean")
build_require("check")
build_require("ctan")
build_require("install")
build_require("unpack")
build_require("manifest")
build_require("manifest-setup")
build_require("tagging")
build_require("upload")
build_require("stdmain")
L3B.require("arguments")
L3B.require("help")

L3B.require("file-functions")
L3B.require("typesetting")
L3B.require("aux")
L3B.require("clean")
L3B.require("check")
L3B.require("ctan")
L3B.require("install")
L3B.require("unpack")
L3B.require("manifest")
L3B.require("manifest-setup")
L3B.require("tagging")
L3B.require("upload")
L3B.require("stdmain")

-- This has to come after stdmain(),
-- and that has to come after the functions are defined
Expand All @@ -87,7 +81,7 @@ end

-- Load standard settings for variables:
-- comes after any user versions
build_require("variables")
L3B.require("variables")

-- Ensure that directories are 'space safe'
maindir = escapepath(maindir)
Expand Down

0 comments on commit 0cf5d90

Please sign in to comment.