From c52a5c57ccffa5a0929593cd94fa5f87e795efd7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 17 Apr 2020 19:49:17 -0300 Subject: Check version of lua.h to ensure it matches --- src/luarocks/cmd/config.lua | 4 ++-- src/luarocks/deps.lua | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index 5e92634a..2573876d 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -240,8 +240,8 @@ end --- Driver function for "config" command. -- @return boolean: True if succeeded, nil on errors. function config_cmd.command(args) - deps.check_lua_incdir(cfg.variables) - deps.check_lua_libdir(cfg.variables) + deps.check_lua_incdir(cfg.variables, args.lua_version or cfg.lua_version) + deps.check_lua_libdir(cfg.variables, args.lua_version or cfg.lua_version) -- deprecated flags if args.lua_incdir then diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index d935a5c8..e1ecacee 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -649,13 +649,20 @@ function deps.scan_deps(results, manifest, name, version, deps_mode) end end -local function lua_h_exists(d) +local function lua_h_exists(d, luaver) + local n = tonumber(luaver) + local major = math.floor(n) + local minor = (n - major) * 10 + local luanum = math.floor(major * 100 + minor) + local lua_h = dir.path(d, "lua.h") local fd = io.open(lua_h) if fd then - -- TODO check that LUA_VERSION_MAJOR and LUA_VERSION_MINOR match luaver + local data = fd:read("*a") fd:close() - return d + if data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then + return d + end end end @@ -672,7 +679,7 @@ local function find_lua_incdir(prefix, luaver, luajitver) luajitver and prefix .. "/include/luajit-" .. luajitver:match("^(%d+%.%d+)"), } for _, d in ipairs(incdirs) do - if lua_h_exists(d) then + if lua_h_exists(d, luaver) then return d end end @@ -685,7 +692,7 @@ function deps.check_lua_incdir(vars) local ljv = util.get_luajit_version() if vars.LUA_INCDIR then - return lua_h_exists(vars.LUA_INCDIR) + return lua_h_exists(vars.LUA_INCDIR, cfg.lua_version) end if vars.LUA_DIR then @@ -713,7 +720,9 @@ function deps.check_lua_libdir(vars) table.insert(libnames, 1, "luajit-" .. cfg.lua_version) end local cache = {} + local save_LUA_INCDIR = vars.LUA_INCDIR local ok = check_external_dependency("LUA", { library = libnames }, vars, "build", cache) + vars.LUA_INCDIR = save_LUA_INCDIR if ok then vars.LUALIB = vars.LUA_LIBDIR_FILE return true -- cgit v1.2.3-55-g6feb