From 9404d59d48a511983ed30a6d0f605041a74ff332 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 27 Jun 2018 10:55:16 -0300 Subject: Let LuaRocks find LUA_LIBDIR and LUA_INCDIR by itself --- src/luarocks/build.lua | 10 ++++------ src/luarocks/cmd.lua | 24 ------------------------ src/luarocks/cmd/config.lua | 2 ++ src/luarocks/core/cfg.lua | 10 ---------- src/luarocks/deps.lua | 43 ++++++++++++++++++++++++++++++++++++++----- 5 files changed, 44 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index a609615e..3c7ff84e 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -119,11 +119,9 @@ local function process_dependencies(rockspec, opts) end end - if cfg.link_lua_explicitly then - local ok, err, errcode = deps.check_lua_library(rockspec) - if not ok then - return nil, err, errcode - end + local ok, err, errcode = deps.check_lua(rockspec.variables) + if not ok then + return nil, err, errcode end if opts.deps_mode == "none" then @@ -138,7 +136,7 @@ local function process_dependencies(rockspec, opts) end end end - ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode) + local ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode) if err then return nil, err, errcode end diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index d4ee5bc0..9639fd7d 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -108,28 +108,6 @@ do end end - local function find_lua_incdir(prefix, luaver, luajitver) - luajitver = luajitver and luajitver:gsub("%-.*", "") - local incdirs = { - prefix .. "/include/lua/" .. luaver, - prefix .. "/include/lua" .. luaver, - prefix .. "/include", - prefix, - luajitver and prefix .. "/include/luajit-" .. luajitver, - } - - for _, d in ipairs(incdirs) do - local lua_h = dir.path(d, "lua.h") - -- TODO check that LUA_VERSION_MAJOR and LUA_VERSION_MINOR match luaver - if exists(lua_h) then - return d - end - end - - -- fallback to a default, as it is not necessarily needed. - return incdirs[1] - end - function cmd.find_lua(prefix, luaver) local lua_interpreter, bindir, luajitver lua_interpreter, bindir, luaver, luajitver = find_lua_bindir(prefix, luaver) @@ -143,8 +121,6 @@ do lua_interpreter = lua_interpreter, lua_dir = prefix, lua_bindir = bindir, - lua_incdir = find_lua_incdir(prefix, luaver, luajitver), - lua_libdir = prefix .. "/lib", } end end diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index cd446f44..794cc989 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -4,6 +4,7 @@ local config_cmd = {} local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") +local deps = require("luarocks.deps") local dir = require("luarocks.dir") local fun = require("luarocks.fun") @@ -119,6 +120,7 @@ end --- Driver function for "config" command. -- @return boolean: True if succeeded, nil on errors. function config_cmd.command(flags) + deps.check_lua(cfg.variables) if flags["lua-incdir"] then print(cfg.variables.LUA_INCDIR) return true diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index df10db2b..ee9af258 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -260,11 +260,6 @@ local function make_defaults(lua_version, target_cpu, platforms, home) defaults.variables.CFLAGS = "/nologo /MD /O2" defaults.variables.LIBFLAG = "/nologo /dll" - defaults.variables.LUA_DIR = "c:/lua" - defaults.variables.LUA_BINDIR = "c:/lua/bin" - defaults.variables.LUA_LIBDIR = "c:/lua/lib" - defaults.variables.LUA_INCDIR = "c:/lua/include" - defaults.external_deps_patterns = { bin = { "?.exe", "?.bat" }, lib = { "?.lib", "?.dll", "lib?.dll" }, @@ -333,11 +328,6 @@ local function make_defaults(lua_version, target_cpu, platforms, home) defaults.gcc_rpath = true defaults.variables.LIBFLAG = "-shared" - defaults.variables.LUA_DIR = "/usr/local" - defaults.variables.LUA_BINDIR = "/usr/local/bin" - defaults.variables.LUA_LIBDIR = "/usr/local/lib" - defaults.variables.LUA_INCDIR = "/usr/local/include" - defaults.external_deps_patterns = { bin = { "?" }, lib = { "lib?.a", "lib?.so", "lib?.so.*" }, diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 90c7b3d9..53798cd1 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -303,7 +303,8 @@ local function check_external_dependency_at(extdir, name, ext_files, vars, dirs, local file = ext_files[dirdata.testfile] if file then local files = {} - if not file:match("%.") then + -- If it doesn't look like it contains a filename extension + if not (file:match("%.[a-z]+$") or file:match("%.[a-z]+%.")) then add_all_patterns(file, dirdata.pattern, files) else for _, pattern in ipairs(dirdata.pattern) do @@ -474,16 +475,48 @@ function deps.scan_deps(results, manifest, name, version, deps_mode) end end -function deps.check_lua_library(rockspec) +local function find_lua_incdir(prefix, luaver, luajitver) + luajitver = luajitver and luajitver:gsub("%-.*", "") + local incdirs = { + prefix .. "/include/lua/" .. luaver, + prefix .. "/include/lua" .. luaver, + prefix .. "/include", + prefix, + luajitver and prefix .. "/include/luajit-" .. luajitver:match("^(%d+%.%d+)"), + } + for _, d in ipairs(incdirs) do + 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 + fd:close() + return d + end + end + + -- not found, will fallback to a default + return nil +end + +function deps.check_lua(vars) + if (not vars.LUA_INCDIR) and vars.LUA_DIR then + vars.LUA_INCDIR = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, cfg.luajit_version) + end + local shortv = cfg.lua_version:gsub("%.", "") local libnames = { "lua" .. cfg.lua_version, - "lua" .. cfg.lua_version:gsub("%.", ""), + "lua" .. shortv, + "lua-" .. cfg.lua_version, + "lua-" .. shortv, "lua", } + if cfg.luajit_version then + table.insert(libnames, 1, "luajit-" .. cfg.lua_version) + end for _, libname in ipairs(libnames) do - local ok = check_external_dependency("LUA", { library = libname }, rockspec.variables, "build") + local ok = check_external_dependency("LUA", { library = libname }, vars, "build") if ok then - rockspec.variables.LUALIB = rockspec.variables.LUA_LIBDIR_FILE + vars.LUALIB = vars.LUA_LIBDIR_FILE return true end end -- cgit v1.2.3-55-g6feb