Skip to content

Commit

Permalink
deps: better error message when lua.h version mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Apr 16, 2022
1 parent ab5b138 commit 1411cd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions binary/all_in_one
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ local function generate(main_program, dir, skip)
fd:write(reindent_c(table.concat(out, "\n")))
fd:close()

deps.check_lua_incdir(cfg.variables)
deps.check_lua_libdir(cfg.variables)
assert(deps.check_lua_incdir(cfg.variables))
assert(deps.check_lua_libdir(cfg.variables))

cmd = table.concat(filter_in(nonnull, {
CC, "-o", TARGET_DIR .. "/" .. program_name .. ".exe",
Expand Down
22 changes: 15 additions & 7 deletions src/luarocks/deps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,10 @@ local function lua_h_exists(d, luaver)
if data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then
return d
end

return nil, "Lua header mismatches configured version. You may need to install them or configure LUA_INCDIR.", "dependency"
return nil, "Lua header found at " .. d .. " does not match Lua version " .. luaver .. ". You may want to override this by configuring LUA_INCDIR.", "dependency", 2
end

return nil, "Failed finding Lua header files. You may need to install them or configure LUA_INCDIR.", "dependency"
return nil, "Failed finding Lua header files. You may need to install them or configure LUA_INCDIR.", "dependency", 1
end

local function find_lua_incdir(prefix, luaver, luajitver)
Expand All @@ -684,14 +683,21 @@ local function find_lua_incdir(prefix, luaver, luajitver)
prefix,
luajitver and prefix .. "/include/luajit-" .. luajitver:match("^(%d+%.%d+)"),
}
local errprio = 0
local mainerr
for _, d in ipairs(incdirs) do
if lua_h_exists(d, luaver) then
local ok, err, _, prio = lua_h_exists(d, luaver)
if ok then
return d
end
if prio > errprio then
mainerr = err
errprio = prio
end
end

-- not found, will fallback to a default
return nil
return nil, mainerr
end

function deps.check_lua_incdir(vars)
Expand All @@ -702,10 +708,12 @@ function deps.check_lua_incdir(vars)
end

if vars.LUA_DIR then
vars.LUA_INCDIR = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv)
if vars.LUA_INCDIR then
local d, err = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv)
if d then
vars.LUA_INCDIR = d
return true
end
return nil, err
end

return nil, "Failed finding Lua header files. You may need to install them or configure LUA_INCDIR.", "dependency"
Expand Down

0 comments on commit 1411cd7

Please sign in to comment.