diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-11 18:11:20 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-14 14:06:51 -0300 |
commit | c9185f42835c52956b4cb906d765d5b4e6bb3539 (patch) | |
tree | 61f8825bc68b38a8fd953737f18aab6bafd1ba45 | |
parent | c905deaa146dcd285b5b6a0edf0d569c52ea1e5a (diff) | |
download | luarocks-c9185f42835c52956b4cb906d765d5b4e6bb3539.tar.gz luarocks-c9185f42835c52956b4cb906d765d5b4e6bb3539.tar.bz2 luarocks-c9185f42835c52956b4cb906d765d5b4e6bb3539.zip |
builtin: if "libraries" is used but "external_dependencies" is not given, autogenerate it
The approach is slightly ugly since it adds builtin-specific
knowledge to `luarocks.deps`, but I don't think any other
build backends will support this behavior any time soon.
-rw-r--r-- | spec/build_spec.lua | 27 | ||||
-rw-r--r-- | src/luarocks/build/builtin.lua | 32 | ||||
-rw-r--r-- | src/luarocks/deps.lua | 4 |
3 files changed, 63 insertions, 0 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index af2dfe38..ae559654 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
@@ -311,6 +311,33 @@ describe("LuaRocks build tests #integration", function() | |||
311 | assert.truthy(run.luarocks_bool("build " .. rockspec)) | 311 | assert.truthy(run.luarocks_bool("build " .. rockspec)) |
312 | assert.match("bla.lua", run.luarocks("show autodetect")) | 312 | assert.match("bla.lua", run.luarocks("show autodetect")) |
313 | end) | 313 | end) |
314 | |||
315 | it("'builtin' synthesizes external_dependencies if not given but a library is given in build", function() | ||
316 | local rockspec = "autodetect-1.0-1.rockspec" | ||
317 | test_env.write_file(rockspec, [[ | ||
318 | rockspec_format = "3.0" | ||
319 | package = "autodetect" | ||
320 | version = "1.0-1" | ||
321 | source = { | ||
322 | url = "file://]] .. testing_paths.fixtures_dir .. [[/c_module.c" | ||
323 | } | ||
324 | description = { | ||
325 | summary = "An example rockspec", | ||
326 | } | ||
327 | dependencies = { | ||
328 | "lua >= 5.1" | ||
329 | } | ||
330 | build = { | ||
331 | modules = { | ||
332 | c_module = { | ||
333 | sources = "c_module.c", | ||
334 | libraries = "inexistent_library", | ||
335 | } | ||
336 | } | ||
337 | } | ||
338 | ]], finally) | ||
339 | assert.match("INEXISTENT_LIBRARY_DIR", run.luarocks("build " .. rockspec)) | ||
340 | end) | ||
314 | end) | 341 | end) |
315 | 342 | ||
316 | describe("#mock external dependencies", function() | 343 | describe("#mock external dependencies", function() |
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 4ff59f8b..f414c166 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
@@ -10,6 +10,38 @@ local util = require("luarocks.util") | |||
10 | local cfg = require("luarocks.core.cfg") | 10 | local cfg = require("luarocks.core.cfg") |
11 | local dir = require("luarocks.dir") | 11 | local dir = require("luarocks.dir") |
12 | 12 | ||
13 | function 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() | ||
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 | ||
43 | end | ||
44 | |||
13 | local function autoextract_libs(external_dependencies, variables) | 45 | local function autoextract_libs(external_dependencies, variables) |
14 | if not external_dependencies then | 46 | if not external_dependencies then |
15 | return nil, nil, nil | 47 | return nil, nil, nil |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 3ec1aa93..bcd6ccf5 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -9,6 +9,7 @@ local dir = require("luarocks.dir") | |||
9 | local util = require("luarocks.util") | 9 | local util = require("luarocks.util") |
10 | local vers = require("luarocks.core.vers") | 10 | local vers = require("luarocks.core.vers") |
11 | local queries = require("luarocks.queries") | 11 | local queries = require("luarocks.queries") |
12 | local builtin = require("luarocks.build.builtin") | ||
12 | 13 | ||
13 | --- Attempt to match a dependency to an installed rock. | 14 | --- Attempt to match a dependency to an installed rock. |
14 | -- @param dep table: A dependency parsed in table format. | 15 | -- @param dep table: A dependency parsed in table format. |
@@ -277,6 +278,9 @@ function deps.check_external_deps(rockspec, mode) | |||
277 | patterns = cfg.runtime_external_deps_patterns | 278 | patterns = cfg.runtime_external_deps_patterns |
278 | subdirs = cfg.runtime_external_deps_subdirs | 279 | subdirs = cfg.runtime_external_deps_subdirs |
279 | end | 280 | end |
281 | if not rockspec.external_dependencies then | ||
282 | rockspec.external_dependencies = builtin.autodetect_external_dependencies(rockspec.build) | ||
283 | end | ||
280 | if rockspec.external_dependencies then | 284 | if rockspec.external_dependencies then |
281 | for name, ext_files in util.sortedpairs(rockspec.external_dependencies) do | 285 | for name, ext_files in util.sortedpairs(rockspec.external_dependencies) do |
282 | local ok = true | 286 | local ok = true |