From d4e82aae9f411d5d2cac10f7e043a0c3c6180eb1 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Wed, 9 Jun 2021 22:00:15 +0200 Subject: allow to work without debug library --- src/luarocks/argparse.lua | 3 +++ src/luarocks/cmd.lua | 3 +++ src/luarocks/core/cfg.lua | 3 +++ src/luarocks/core/util.lua | 5 ++++- src/luarocks/loader.lua | 4 ++-- src/luarocks/util.lua | 3 +-- 6 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/luarocks/argparse.lua b/src/luarocks/argparse.lua index f440308d..2c2585dd 100644 --- a/src/luarocks/argparse.lua +++ b/src/luarocks/argparse.lua @@ -2067,6 +2067,9 @@ function Parser:parse(args) end local function xpcall_error_handler(err) + if not debug then + return tostring(err) + end return tostring(err) .. "\noriginal " .. debug.traceback("", 2):sub(2) end diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 72edc66d..233bb1bd 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -146,6 +146,9 @@ local function process_server_args(args) end local function error_handler(err) + if not debug then + return err + end local mode = "Arch.: " .. (cfg and cfg.arch or "unknown") if package.config:sub(1, 1) == "\\" then if cfg and cfg.fs_use_modules then diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index e24fa4f6..42f10991 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -50,6 +50,9 @@ local platform_order = { } local function detect_sysconfdir() + if not debug then + return + end local src = debug.getinfo(1, "S").source:gsub("\\", "/"):gsub("/+", "/") if src:sub(1, 1) == "@" then src = src:sub(2) diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 384a6eba..67a10b42 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua @@ -67,7 +67,10 @@ function util.show_table(t, tname, top_indent) local function basic_serialize(o) local so = tostring(o) if type(o) == "function" then - local info = debug.getinfo(o, "S") + local info = debug and debug.getinfo(o, "S") + if not info then + return ("%q"):format(so) + end -- info.name is nil because o is not a calling level if info.what == "C" then return ("%q"):format(so .. ", C function") diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index a3bd8f1b..825e4ce7 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -43,8 +43,8 @@ else -- a global. -- Detect when being called via -lluarocks.loader; this is -- most likely a wrapper. - local info = debug.getinfo(2, "nS") - if info.what == "C" and not info.name then + local info = debug and debug.getinfo(2, "nS") + if info and info.what == "C" and not info.name then luarocks = { loader = loader } temporary_global = true -- For the other half of this hack, diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index ae96eb6a..bb474ff0 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -23,7 +23,6 @@ local unpack = unpack or table.unpack local pack = table.pack or function(...) return { n = select("#", ...), ... } end local scheduled_functions = {} -local debug = require("debug") --- Schedule a function to be executed upon program termination. -- This is useful for actions such as deleting temporary directories @@ -198,7 +197,7 @@ function util.this_program(default) local i = 1 local last, cur = default, default while i do - local dbg = debug.getinfo(i,"S") + local dbg = debug and debug.getinfo(i,"S") if not dbg then break end last = cur cur = dbg.source -- cgit v1.2.3-55-g6feb