aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/deps.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/deps.lua')
-rw-r--r--src/luarocks/deps.lua54
1 files changed, 51 insertions, 3 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 8af28327..2680b64b 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -10,7 +10,6 @@ local fun = require("luarocks.fun")
10local util = require("luarocks.util") 10local util = require("luarocks.util")
11local vers = require("luarocks.core.vers") 11local vers = require("luarocks.core.vers")
12local queries = require("luarocks.queries") 12local queries = require("luarocks.queries")
13local builtin = require("luarocks.build.builtin")
14local deplocks = require("luarocks.deplocks") 13local deplocks = require("luarocks.deplocks")
15 14
16--- Generate a function that matches dep queries against the manifest, 15--- Generate a function that matches dep queries against the manifest,
@@ -570,6 +569,40 @@ local function check_external_dependency(name, ext_files, vars, mode, cache)
570 return nil, err_dirname, err_testfile, err_files 569 return nil, err_dirname, err_testfile, err_files
571end 570end
572 571
572function deps.autodetect_external_dependencies(build)
573 -- only applies to the 'builtin' build type
574 if not build or not build.modules then
575 return nil
576 end
577
578 local extdeps = {}
579 local any = false
580 for _, data in pairs(build.modules) do
581 if type(data) == "table" and data.libraries then
582 local libraries = data.libraries
583 if type(libraries) == "string" then
584 libraries = { libraries }
585 end
586 local incdirs = {}
587 local libdirs = {}
588 for _, lib in ipairs(libraries) do
589 local upper = lib:upper():gsub("%+", "P"):gsub("[^%w]", "_")
590 any = true
591 extdeps[upper] = { library = lib }
592 table.insert(incdirs, "$(" .. upper .. "_INCDIR)")
593 table.insert(libdirs, "$(" .. upper .. "_LIBDIR)")
594 end
595 if not data.incdirs then
596 data.incdirs = incdirs
597 end
598 if not data.libdirs then
599 data.libdirs = libdirs
600 end
601 end
602 end
603 return any and extdeps or nil
604end
605
573--- Set up path-related variables for external dependencies. 606--- Set up path-related variables for external dependencies.
574-- For each key in the external_dependencies table in the 607-- For each key in the external_dependencies table in the
575-- rockspec file, four variables are created: <key>_DIR, <key>_BINDIR, 608-- rockspec file, four variables are created: <key>_DIR, <key>_BINDIR,
@@ -587,7 +620,7 @@ function deps.check_external_deps(rockspec, mode)
587 assert(rockspec:type() == "rockspec") 620 assert(rockspec:type() == "rockspec")
588 621
589 if not rockspec.external_dependencies then 622 if not rockspec.external_dependencies then
590 rockspec.external_dependencies = builtin.autodetect_external_dependencies(rockspec.build) 623 rockspec.external_dependencies = deps.autodetect_external_dependencies(rockspec.build)
591 end 624 end
592 if not rockspec.external_dependencies then 625 if not rockspec.external_dependencies then
593 return true 626 return true
@@ -706,16 +739,25 @@ local function find_lua_incdir(prefix, luaver, luajitver)
706end 739end
707 740
708function deps.check_lua_incdir(vars) 741function deps.check_lua_incdir(vars)
742 if vars.LUA_INCDIR_OK == true
743 then return true
744 end
745
709 local ljv = util.get_luajit_version() 746 local ljv = util.get_luajit_version()
710 747
711 if vars.LUA_INCDIR then 748 if vars.LUA_INCDIR then
712 return lua_h_exists(vars.LUA_INCDIR, cfg.lua_version) 749 local ok, err = lua_h_exists(vars.LUA_INCDIR, cfg.lua_version)
750 if ok then
751 vars.LUA_INCDIR_OK = true
752 end
753 return ok, err
713 end 754 end
714 755
715 if vars.LUA_DIR then 756 if vars.LUA_DIR then
716 local d, err = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv) 757 local d, err = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv)
717 if d then 758 if d then
718 vars.LUA_INCDIR = d 759 vars.LUA_INCDIR = d
760 vars.LUA_INCDIR_OK = true
719 return true 761 return true
720 end 762 end
721 return nil, err 763 return nil, err
@@ -725,10 +767,15 @@ function deps.check_lua_incdir(vars)
725end 767end
726 768
727function deps.check_lua_libdir(vars) 769function deps.check_lua_libdir(vars)
770 if vars.LUA_LIBDIR_OK == true
771 then return true
772 end
773
728 local fs = require("luarocks.fs") 774 local fs = require("luarocks.fs")
729 local ljv = util.get_luajit_version() 775 local ljv = util.get_luajit_version()
730 776
731 if vars.LUA_LIBDIR and vars.LUALIB and fs.exists(dir.path(vars.LUA_LIBDIR, vars.LUALIB)) then 777 if vars.LUA_LIBDIR and vars.LUALIB and fs.exists(dir.path(vars.LUA_LIBDIR, vars.LUALIB)) then
778 vars.LUA_LIBDIR_OK = true
732 return true 779 return true
733 end 780 end
734 781
@@ -768,6 +815,7 @@ function deps.check_lua_libdir(vars)
768 815
769 if ok then 816 if ok then
770 vars.LUALIB = vars.LUA_LIBDIR_FILE 817 vars.LUALIB = vars.LUA_LIBDIR_FILE
818 vars.LUA_LIBDIR_OK = true
771 return true 819 return true
772 else 820 else
773 err = err or "Failed finding Lua library. You may need to configure LUA_LIBDIR." 821 err = err or "Failed finding Lua library. You may need to configure LUA_LIBDIR."