aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-06-27 10:55:16 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 21:32:39 -0300
commit9404d59d48a511983ed30a6d0f605041a74ff332 (patch)
tree920340b4b019a2dff9c7eeaeab01314af386b547
parentb7680a66385dde34c8e8dbdeafc22156425cb38c (diff)
downloadluarocks-9404d59d48a511983ed30a6d0f605041a74ff332.tar.gz
luarocks-9404d59d48a511983ed30a6d0f605041a74ff332.tar.bz2
luarocks-9404d59d48a511983ed30a6d0f605041a74ff332.zip
Let LuaRocks find LUA_LIBDIR and LUA_INCDIR by itself
-rw-r--r--spec/config_spec.lua8
-rw-r--r--spec/util/test_env.lua10
-rw-r--r--src/luarocks/build.lua10
-rw-r--r--src/luarocks/cmd.lua24
-rw-r--r--src/luarocks/cmd/config.lua2
-rw-r--r--src/luarocks/core/cfg.lua10
-rw-r--r--src/luarocks/deps.lua43
7 files changed, 48 insertions, 59 deletions
diff --git a/spec/config_spec.lua b/spec/config_spec.lua
index 825245b7..f415909d 100644
--- a/spec/config_spec.lua
+++ b/spec/config_spec.lua
@@ -20,14 +20,14 @@ describe("LuaRocks config tests #integration", function()
20 assert.match("rocks_servers", run.luarocks("config")) 20 assert.match("rocks_servers", run.luarocks("config"))
21 end) 21 end)
22 22
23 it("LuaRocks config include dir", function() 23 it("LuaRocks config include dir returns a subdir of LUA_DIR", function()
24 local output = run.luarocks("config --lua-incdir") 24 local output = run.luarocks("config --lua-incdir")
25 assert.are.same(hardcoded.LUA_INCDIR, output) 25 assert.match(hardcoded.LUA_DIR, output, 1, true)
26 end) 26 end)
27 27
28 it("LuaRocks config library dir", function() 28 it("LuaRocks config library dir returns a subdir of LUA_DIR", function()
29 local output = run.luarocks("config --lua-libdir") 29 local output = run.luarocks("config --lua-libdir")
30 assert.are.same(hardcoded.LUA_LIBDIR, output) 30 assert.match(hardcoded.LUA_DIR, output, 1, true)
31 end) 31 end)
32 32
33 it("LuaRocks config lua version", function() 33 it("LuaRocks config lua version", function()
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
index fc292607..60162ee3 100644
--- a/spec/util/test_env.lua
+++ b/spec/util/test_env.lua
@@ -547,14 +547,6 @@ local function create_paths(luaversion_full)
547 end 547 end
548 assert(testing_paths.lua, "Lua interpreter not found! Run `busted -Xhelper help` for options") 548 assert(testing_paths.lua, "Lua interpreter not found! Run `busted -Xhelper help` for options")
549 549
550 local incfile = test_env.file_if_exists(testing_paths.luadir .. "/include/lua/" .. test_env.lua_version .. "/lua.h")
551 or test_env.file_if_exists(testing_paths.luadir .. "/include/lua" .. test_env.lua_version .. "/lua.h")
552 or test_env.file_if_exists(testing_paths.luadir .. "/include/lua.h")
553 testing_paths.lua_incdir = assert(incfile, "Lua header lua.h not found!"):gsub("/lua.h$", "")
554
555 testing_paths.lua_libdir = test_env.file_if_exists(testing_paths.luadir .. "/lib")
556 or test_env.file_if_exists(testing_paths.luadir)
557
558 local base_dir = lfs.currentdir() 550 local base_dir = lfs.currentdir()
559 551
560 if test_env.TEST_TARGET_OS == "windows" then 552 if test_env.TEST_TARGET_OS == "windows" then
@@ -770,8 +762,6 @@ local function setup_luarocks()
770 "return {", 762 "return {",
771 ("SYSCONFDIR = %q,"):format(testing_paths.testing_lrprefix .. "/etc/luarocks"), 763 ("SYSCONFDIR = %q,"):format(testing_paths.testing_lrprefix .. "/etc/luarocks"),
772 ("LUA_DIR = %q,"):format(testing_paths.luadir), 764 ("LUA_DIR = %q,"):format(testing_paths.luadir),
773 ("LUA_INCDIR = %q,"):format(testing_paths.lua_incdir),
774 ("LUA_LIBDIR = %q,"):format(testing_paths.lua_libdir),
775 ("LUA_BINDIR = %q,"):format(testing_paths.lua_bindir), 765 ("LUA_BINDIR = %q,"):format(testing_paths.lua_bindir),
776 ("LUA_INTERPRETER = %q,"):format(testing_paths.lua_interpreter), 766 ("LUA_INTERPRETER = %q,"):format(testing_paths.lua_interpreter),
777 } 767 }
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)
119 end 119 end
120 end 120 end
121 121
122 if cfg.link_lua_explicitly then 122 local ok, err, errcode = deps.check_lua(rockspec.variables)
123 local ok, err, errcode = deps.check_lua_library(rockspec) 123 if not ok then
124 if not ok then 124 return nil, err, errcode
125 return nil, err, errcode
126 end
127 end 125 end
128 126
129 if opts.deps_mode == "none" then 127 if opts.deps_mode == "none" then
@@ -138,7 +136,7 @@ local function process_dependencies(rockspec, opts)
138 end 136 end
139 end 137 end
140 end 138 end
141 ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode) 139 local ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode)
142 if err then 140 if err then
143 return nil, err, errcode 141 return nil, err, errcode
144 end 142 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
108 end 108 end
109 end 109 end
110 110
111 local function find_lua_incdir(prefix, luaver, luajitver)
112 luajitver = luajitver and luajitver:gsub("%-.*", "")
113 local incdirs = {
114 prefix .. "/include/lua/" .. luaver,
115 prefix .. "/include/lua" .. luaver,
116 prefix .. "/include",
117 prefix,
118 luajitver and prefix .. "/include/luajit-" .. luajitver,
119 }
120
121 for _, d in ipairs(incdirs) do
122 local lua_h = dir.path(d, "lua.h")
123 -- TODO check that LUA_VERSION_MAJOR and LUA_VERSION_MINOR match luaver
124 if exists(lua_h) then
125 return d
126 end
127 end
128
129 -- fallback to a default, as it is not necessarily needed.
130 return incdirs[1]
131 end
132
133 function cmd.find_lua(prefix, luaver) 111 function cmd.find_lua(prefix, luaver)
134 local lua_interpreter, bindir, luajitver 112 local lua_interpreter, bindir, luajitver
135 lua_interpreter, bindir, luaver, luajitver = find_lua_bindir(prefix, luaver) 113 lua_interpreter, bindir, luaver, luajitver = find_lua_bindir(prefix, luaver)
@@ -143,8 +121,6 @@ do
143 lua_interpreter = lua_interpreter, 121 lua_interpreter = lua_interpreter,
144 lua_dir = prefix, 122 lua_dir = prefix,
145 lua_bindir = bindir, 123 lua_bindir = bindir,
146 lua_incdir = find_lua_incdir(prefix, luaver, luajitver),
147 lua_libdir = prefix .. "/lib",
148 } 124 }
149 end 125 end
150end 126end
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 = {}
4 4
5local cfg = require("luarocks.core.cfg") 5local cfg = require("luarocks.core.cfg")
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local deps = require("luarocks.deps")
7local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
8local fun = require("luarocks.fun") 9local fun = require("luarocks.fun")
9 10
@@ -119,6 +120,7 @@ end
119--- Driver function for "config" command. 120--- Driver function for "config" command.
120-- @return boolean: True if succeeded, nil on errors. 121-- @return boolean: True if succeeded, nil on errors.
121function config_cmd.command(flags) 122function config_cmd.command(flags)
123 deps.check_lua(cfg.variables)
122 if flags["lua-incdir"] then 124 if flags["lua-incdir"] then
123 print(cfg.variables.LUA_INCDIR) 125 print(cfg.variables.LUA_INCDIR)
124 return true 126 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)
260 defaults.variables.CFLAGS = "/nologo /MD /O2" 260 defaults.variables.CFLAGS = "/nologo /MD /O2"
261 defaults.variables.LIBFLAG = "/nologo /dll" 261 defaults.variables.LIBFLAG = "/nologo /dll"
262 262
263 defaults.variables.LUA_DIR = "c:/lua"
264 defaults.variables.LUA_BINDIR = "c:/lua/bin"
265 defaults.variables.LUA_LIBDIR = "c:/lua/lib"
266 defaults.variables.LUA_INCDIR = "c:/lua/include"
267
268 defaults.external_deps_patterns = { 263 defaults.external_deps_patterns = {
269 bin = { "?.exe", "?.bat" }, 264 bin = { "?.exe", "?.bat" },
270 lib = { "?.lib", "?.dll", "lib?.dll" }, 265 lib = { "?.lib", "?.dll", "lib?.dll" },
@@ -333,11 +328,6 @@ local function make_defaults(lua_version, target_cpu, platforms, home)
333 defaults.gcc_rpath = true 328 defaults.gcc_rpath = true
334 defaults.variables.LIBFLAG = "-shared" 329 defaults.variables.LIBFLAG = "-shared"
335 330
336 defaults.variables.LUA_DIR = "/usr/local"
337 defaults.variables.LUA_BINDIR = "/usr/local/bin"
338 defaults.variables.LUA_LIBDIR = "/usr/local/lib"
339 defaults.variables.LUA_INCDIR = "/usr/local/include"
340
341 defaults.external_deps_patterns = { 331 defaults.external_deps_patterns = {
342 bin = { "?" }, 332 bin = { "?" },
343 lib = { "lib?.a", "lib?.so", "lib?.so.*" }, 333 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,
303 local file = ext_files[dirdata.testfile] 303 local file = ext_files[dirdata.testfile]
304 if file then 304 if file then
305 local files = {} 305 local files = {}
306 if not file:match("%.") then 306 -- If it doesn't look like it contains a filename extension
307 if not (file:match("%.[a-z]+$") or file:match("%.[a-z]+%.")) then
307 add_all_patterns(file, dirdata.pattern, files) 308 add_all_patterns(file, dirdata.pattern, files)
308 else 309 else
309 for _, pattern in ipairs(dirdata.pattern) do 310 for _, pattern in ipairs(dirdata.pattern) do
@@ -474,16 +475,48 @@ function deps.scan_deps(results, manifest, name, version, deps_mode)
474 end 475 end
475end 476end
476 477
477function deps.check_lua_library(rockspec) 478local function find_lua_incdir(prefix, luaver, luajitver)
479 luajitver = luajitver and luajitver:gsub("%-.*", "")
480 local incdirs = {
481 prefix .. "/include/lua/" .. luaver,
482 prefix .. "/include/lua" .. luaver,
483 prefix .. "/include",
484 prefix,
485 luajitver and prefix .. "/include/luajit-" .. luajitver:match("^(%d+%.%d+)"),
486 }
487 for _, d in ipairs(incdirs) do
488 local lua_h = dir.path(d, "lua.h")
489 local fd = io.open(lua_h)
490 if fd then
491 -- TODO check that LUA_VERSION_MAJOR and LUA_VERSION_MINOR match luaver
492 fd:close()
493 return d
494 end
495 end
496
497 -- not found, will fallback to a default
498 return nil
499end
500
501function deps.check_lua(vars)
502 if (not vars.LUA_INCDIR) and vars.LUA_DIR then
503 vars.LUA_INCDIR = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, cfg.luajit_version)
504 end
505 local shortv = cfg.lua_version:gsub("%.", "")
478 local libnames = { 506 local libnames = {
479 "lua" .. cfg.lua_version, 507 "lua" .. cfg.lua_version,
480 "lua" .. cfg.lua_version:gsub("%.", ""), 508 "lua" .. shortv,
509 "lua-" .. cfg.lua_version,
510 "lua-" .. shortv,
481 "lua", 511 "lua",
482 } 512 }
513 if cfg.luajit_version then
514 table.insert(libnames, 1, "luajit-" .. cfg.lua_version)
515 end
483 for _, libname in ipairs(libnames) do 516 for _, libname in ipairs(libnames) do
484 local ok = check_external_dependency("LUA", { library = libname }, rockspec.variables, "build") 517 local ok = check_external_dependency("LUA", { library = libname }, vars, "build")
485 if ok then 518 if ok then
486 rockspec.variables.LUALIB = rockspec.variables.LUA_LIBDIR_FILE 519 vars.LUALIB = vars.LUA_LIBDIR_FILE
487 return true 520 return true
488 end 521 end
489 end 522 end