aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-02-19 11:55:39 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-02-19 16:35:00 -0300
commitc13ff298bdd424d7b7401fce4f0379cda0348af8 (patch)
tree9cc8551a3c23ae09020bb135c202aa34029d150d
parent50ebdd5d17c8390d30132c165d2e0a614dc0ecae (diff)
downloadluarocks-c13ff298bdd424d7b7401fce4f0379cda0348af8.tar.gz
luarocks-c13ff298bdd424d7b7401fce4f0379cda0348af8.tar.bz2
luarocks-c13ff298bdd424d7b7401fce4f0379cda0348af8.zip
fix(build): don't look for Lua headers when installing pure-Lua rocks
This only applies to 'builtin' as we can't know about other modes, but this should be good enough. Fixes #1275.
-rw-r--r--spec/build_spec.lua117
-rw-r--r--spec/deps_spec.lua143
-rw-r--r--src/luarocks/build.lua34
-rw-r--r--src/luarocks/build/builtin.lua52
-rw-r--r--src/luarocks/cmd.lua2
-rw-r--r--src/luarocks/deps.lua54
6 files changed, 228 insertions, 174 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index 653f2160..3b33a1aa 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -598,123 +598,6 @@ describe("LuaRocks build #unit", function()
598 end, finally) 598 end, finally)
599 end) 599 end)
600 600
601 describe("builtin.autodetect_external_dependencies", function()
602 it("returns false if the given build table has no external dependencies", function()
603 local build_table = {
604 type = "builtin"
605 }
606
607 assert.falsy(build_builtin.autodetect_external_dependencies(build_table))
608 end)
609
610 it("returns a table of the external dependencies found in the given build table", function()
611 local build_table = {
612 type = "builtin",
613 modules = {
614 module1 = {
615 libraries = { "foo1", "foo2" },
616 },
617 module2 = {
618 libraries = "foo3"
619 },
620 }
621 }
622
623 local extdeps = build_builtin.autodetect_external_dependencies(build_table)
624 assert.same(extdeps["FOO1"], { library = "foo1" })
625 assert.same(extdeps["FOO2"], { library = "foo2" })
626 assert.same(extdeps["FOO3"], { library = "foo3" })
627 end)
628
629 it("adds proper include and library dirs to the given build table", function()
630 local build_table
631
632 build_table = {
633 type = "builtin",
634 modules = {
635 module1 = {
636 libraries = "foo"
637 }
638 }
639 }
640 build_builtin.autodetect_external_dependencies(build_table)
641 assert.same(build_table, {
642 type = "builtin",
643 modules = {
644 module1 = {
645 libraries = "foo",
646 incdirs = { "$(FOO_INCDIR)" },
647 libdirs = { "$(FOO_LIBDIR)" }
648 }
649 }
650 })
651
652 build_table = {
653 type = "builtin",
654 modules = {
655 module1 = {
656 libraries = "foo",
657 incdirs = { "INCDIRS" }
658 }
659 }
660 }
661 build_builtin.autodetect_external_dependencies(build_table)
662 assert.same(build_table, {
663 type = "builtin",
664 modules = {
665 module1 = {
666 libraries = "foo",
667 incdirs = { "INCDIRS" },
668 libdirs = { "$(FOO_LIBDIR)" }
669 }
670 }
671 })
672
673 build_table = {
674 type = "builtin",
675 modules = {
676 module1 = {
677 libraries = "foo",
678 libdirs = { "LIBDIRS" }
679 }
680 }
681 }
682 build_builtin.autodetect_external_dependencies(build_table)
683 assert.same(build_table, {
684 type = "builtin",
685 modules = {
686 module1 = {
687 libraries = "foo",
688 incdirs = { "$(FOO_INCDIR)" },
689 libdirs = { "LIBDIRS" }
690 }
691 }
692 })
693
694 build_table = {
695 type = "builtin",
696 modules = {
697 module1 = {
698 libraries = "foo",
699 incdirs = { "INCDIRS" },
700 libdirs = { "LIBDIRS" }
701 }
702 }
703 }
704 build_builtin.autodetect_external_dependencies(build_table)
705 assert.same(build_table, {
706 type = "builtin",
707 modules = {
708 module1 = {
709 libraries = "foo",
710 incdirs = { "INCDIRS" },
711 libdirs = { "LIBDIRS" }
712 }
713 }
714 })
715 end)
716 end)
717
718 describe("builtin.autodetect_modules", function() 601 describe("builtin.autodetect_modules", function()
719 local tmpdir 602 local tmpdir
720 local olddir 603 local olddir
diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua
index b0064298..32f68f51 100644
--- a/spec/deps_spec.lua
+++ b/spec/deps_spec.lua
@@ -116,3 +116,146 @@ describe("LuaRocks deps-mode #integration", function()
116 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) 116 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec"))
117 end) 117 end)
118end) 118end)
119
120test_env.unload_luarocks()
121test_env.setup_specs()
122local cfg = require("luarocks.core.cfg")
123local deps = require("luarocks.deps")
124local fs = require("luarocks.fs")
125
126describe("LuaRocks deps #unit", function()
127 local runner
128
129 lazy_setup(function()
130 runner = require("luacov.runner")
131 runner.init(testing_paths.testrun_dir .. "/luacov.config")
132 runner.tick = true
133 cfg.init()
134 fs.init()
135 deps.check_lua_incdir(cfg.variables)
136 deps.check_lua_libdir(cfg.variables)
137 end)
138
139 lazy_teardown(function()
140 runner.shutdown()
141 end)
142
143 describe("deps", function()
144 describe("deps.autodetect_external_dependencies", function()
145 it("returns false if the given build table has no external dependencies", function()
146 local build_table = {
147 type = "builtin"
148 }
149
150 assert.falsy(deps.autodetect_external_dependencies(build_table))
151 end)
152
153 it("returns a table of the external dependencies found in the given build table", function()
154 local build_table = {
155 type = "builtin",
156 modules = {
157 module1 = {
158 libraries = { "foo1", "foo2" },
159 },
160 module2 = {
161 libraries = "foo3"
162 },
163 }
164 }
165
166 local extdeps = deps.autodetect_external_dependencies(build_table)
167 assert.same(extdeps["FOO1"], { library = "foo1" })
168 assert.same(extdeps["FOO2"], { library = "foo2" })
169 assert.same(extdeps["FOO3"], { library = "foo3" })
170 end)
171
172 it("adds proper include and library dirs to the given build table", function()
173 local build_table
174
175 build_table = {
176 type = "builtin",
177 modules = {
178 module1 = {
179 libraries = "foo"
180 }
181 }
182 }
183 deps.autodetect_external_dependencies(build_table)
184 assert.same(build_table, {
185 type = "builtin",
186 modules = {
187 module1 = {
188 libraries = "foo",
189 incdirs = { "$(FOO_INCDIR)" },
190 libdirs = { "$(FOO_LIBDIR)" }
191 }
192 }
193 })
194
195 build_table = {
196 type = "builtin",
197 modules = {
198 module1 = {
199 libraries = "foo",
200 incdirs = { "INCDIRS" }
201 }
202 }
203 }
204 deps.autodetect_external_dependencies(build_table)
205 assert.same(build_table, {
206 type = "builtin",
207 modules = {
208 module1 = {
209 libraries = "foo",
210 incdirs = { "INCDIRS" },
211 libdirs = { "$(FOO_LIBDIR)" }
212 }
213 }
214 })
215
216 build_table = {
217 type = "builtin",
218 modules = {
219 module1 = {
220 libraries = "foo",
221 libdirs = { "LIBDIRS" }
222 }
223 }
224 }
225 deps.autodetect_external_dependencies(build_table)
226 assert.same(build_table, {
227 type = "builtin",
228 modules = {
229 module1 = {
230 libraries = "foo",
231 incdirs = { "$(FOO_INCDIR)" },
232 libdirs = { "LIBDIRS" }
233 }
234 }
235 })
236
237 build_table = {
238 type = "builtin",
239 modules = {
240 module1 = {
241 libraries = "foo",
242 incdirs = { "INCDIRS" },
243 libdirs = { "LIBDIRS" }
244 }
245 }
246 }
247 deps.autodetect_external_dependencies(build_table)
248 assert.same(build_table, {
249 type = "builtin",
250 modules = {
251 module1 = {
252 libraries = "foo",
253 incdirs = { "INCDIRS" },
254 libdirs = { "LIBDIRS" }
255 }
256 }
257 })
258 end)
259 end)
260 end)
261end)
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 471de427..55242e60 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -111,18 +111,6 @@ local function process_dependencies(rockspec, opts)
111 end 111 end
112 end 112 end
113 113
114 local ok, err, errcode = deps.check_lua_incdir(rockspec.variables)
115 if not ok then
116 return nil, err, errcode
117 end
118
119 if cfg.link_lua_explicitly then
120 local ok, err, errcode = deps.check_lua_libdir(rockspec.variables)
121 if not ok then
122 return nil, err, errcode
123 end
124 end
125
126 if opts.deps_mode == "none" then 114 if opts.deps_mode == "none" then
127 return true 115 return true
128 end 116 end
@@ -165,11 +153,8 @@ local function process_dependencies(rockspec, opts)
165 end 153 end
166 end 154 end
167 end 155 end
168 ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode, opts.verify) 156
169 if err then 157 return deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode, opts.verify)
170 return nil, err, errcode
171 end
172 return true
173end 158end
174 159
175local function fetch_and_change_to_source_dir(rockspec, opts) 160local function fetch_and_change_to_source_dir(rockspec, opts)
@@ -241,6 +226,21 @@ local function run_build_driver(rockspec, no_install)
241 if not pok or type(driver) ~= "table" then 226 if not pok or type(driver) ~= "table" then
242 return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver 227 return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver
243 end 228 end
229
230 if not driver.skip_lua_inc_lib_check then
231 local ok, err, errcode = deps.check_lua_incdir(rockspec.variables)
232 if not ok then
233 return nil, err, errcode
234 end
235
236 if cfg.link_lua_explicitly then
237 local ok, err, errcode = deps.check_lua_libdir(rockspec.variables)
238 if not ok then
239 return nil, err, errcode
240 end
241 end
242 end
243
244 local ok, err = driver.run(rockspec, no_install) 244 local ok, err = driver.run(rockspec, no_install)
245 if not ok then 245 if not ok then
246 return nil, "Build error: " .. err 246 return nil, "Build error: " .. err
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index 70210bab..c55b61a0 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -2,6 +2,11 @@
2--- A builtin build system: back-end to provide a portable way of building C-based Lua modules. 2--- A builtin build system: back-end to provide a portable way of building C-based Lua modules.
3local builtin = {} 3local builtin = {}
4 4
5-- This build driver checks LUA_INCDIR and LUA_LIBDIR on demand,
6-- so that pure-Lua rocks don't need to have development headers
7-- installed.
8builtin.skip_lua_inc_lib_check = true
9
5local unpack = unpack or table.unpack 10local unpack = unpack or table.unpack
6 11
7local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
@@ -9,38 +14,7 @@ local path = require("luarocks.path")
9local util = require("luarocks.util") 14local util = require("luarocks.util")
10local cfg = require("luarocks.core.cfg") 15local cfg = require("luarocks.core.cfg")
11local dir = require("luarocks.dir") 16local dir = require("luarocks.dir")
12 17local deps = require("luarocks.deps")
13function builtin.autodetect_external_dependencies(build)
14 if not build or not build.modules then
15 return nil
16 end
17 local extdeps = {}
18 local any = false
19 for _, data in pairs(build.modules) do
20 if type(data) == "table" and data.libraries then
21 local libraries = data.libraries
22 if type(libraries) == "string" then
23 libraries = { libraries }
24 end
25 local incdirs = {}
26 local libdirs = {}
27 for _, lib in ipairs(libraries) do
28 local upper = lib:upper():gsub("%+", "P"):gsub("[^%w]", "_")
29 any = true
30 extdeps[upper] = { library = lib }
31 table.insert(incdirs, "$(" .. upper .. "_INCDIR)")
32 table.insert(libdirs, "$(" .. upper .. "_LIBDIR)")
33 end
34 if not data.incdirs then
35 data.incdirs = incdirs
36 end
37 if not data.libdirs then
38 data.libdirs = libdirs
39 end
40 end
41 end
42 return any and extdeps or nil
43end
44 18
45local function autoextract_libs(external_dependencies, variables) 19local function autoextract_libs(external_dependencies, variables)
46 if not external_dependencies then 20 if not external_dependencies then
@@ -323,10 +297,16 @@ function builtin.run(rockspec, no_install)
323 end 297 end
324 if type(info) == "table" then 298 if type(info) == "table" then
325 if not checked_lua_h then 299 if not checked_lua_h then
326 local lua_incdir, lua_h = variables.LUA_INCDIR, "lua.h" 300 local ok, err, errcode = deps.check_lua_incdir(rockspec.variables)
327 if not fs.exists(dir.path(lua_incdir, lua_h)) then 301 if not ok then
328 return nil, "Lua header file "..lua_h.." not found (looked in "..lua_incdir.."). \n" .. 302 return nil, err, errcode
329 "You need to install the Lua development package for your system." 303 end
304
305 if cfg.link_lua_explicitly then
306 local ok, err, errcode = deps.check_lua_libdir(rockspec.variables)
307 if not ok then
308 return nil, err, errcode
309 end
330 end 310 end
331 checked_lua_h = true 311 checked_lua_h = true
332 end 312 end
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index 3cbe3852..3067f4ce 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -561,7 +561,7 @@ function cmd.run_command(description, commands, external_namespace, ...)
561 util.warning("command module " .. module .. " does not implement command(), skipping") 561 util.warning("command module " .. module .. " does not implement command(), skipping")
562 end 562 end
563 else 563 else
564 util.warning("failed to load command module " .. module) 564 util.warning("failed to load command module " .. module .. ": " .. mod)
565 end 565 end
566 end 566 end
567 567
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."