diff options
| author | Renato Maia <maia.renato@gmail.com> | 2025-04-27 17:03:33 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2025-05-19 11:30:51 -0300 |
| commit | 3b7bf479568790a8b04772a36c1b3e712fed4579 (patch) | |
| tree | 01b97d4dacb07ee45082b23bb9c664013f41655e | |
| parent | 4d7b546602b906f924ac91a01276cd3b2569ca9f (diff) | |
| download | luarocks-3b7bf479568790a8b04772a36c1b3e712fed4579.tar.gz luarocks-3b7bf479568790a8b04772a36c1b3e712fed4579.tar.bz2 luarocks-3b7bf479568790a8b04772a36c1b3e712fed4579.zip | |
feat: add build vars. for rockspecs with the dir. of its deps.
Rockspecs can access the directory of its dependencies using variables
in the format 'foo_ROCKDIR' where 'foo' is the name of a dependency.
This is used to be able to access files of the rock like 'conf', 'docs'
and more.
| -rw-r--r-- | docs/creating_a_rock.md | 8 | ||||
| -rw-r--r-- | spec/build_spec.lua | 49 | ||||
| -rw-r--r-- | src/luarocks/deps.lua | 9 | ||||
| -rw-r--r-- | src/luarocks/deps.tl | 9 |
4 files changed, 69 insertions, 6 deletions
diff --git a/docs/creating_a_rock.md b/docs/creating_a_rock.md index 1d42b07f..a5441ea4 100644 --- a/docs/creating_a_rock.md +++ b/docs/creating_a_rock.md | |||
| @@ -148,6 +148,14 @@ and `5.3`, but not yet-to-be-released `5.4`. There are a few other operators | |||
| 148 | for specifying version constraints, see | 148 | for specifying version constraints, see |
| 149 | [Rockspec format](rockspec_format.md#dependency-information). | 149 | [Rockspec format](rockspec_format.md#dependency-information). |
| 150 | 150 | ||
| 151 | Rockspecs from [`rockspec_format = "3.1"`](rockspec_format.md#package-metadata)), | ||
| 152 | have access to special variables with the path of the installed rocks of its | ||
| 153 | dependencies. See the [section below](#including-documentation-and-other-files) | ||
| 154 | for information on how rocks can include files in their installation. Each | ||
| 155 | variable is the name of the dependency followed by the suffix `_ROCKDIR`. For | ||
| 156 | the example above, variable `LUAKNIFE_ROCKDIR` will be provided with the path of | ||
| 157 | the installed rock. | ||
| 158 | |||
| 151 | #### C modules linking to external libraries | 159 | #### C modules linking to external libraries |
| 152 | 160 | ||
| 153 | *If your code does not use third-party libraries, you may skip this subsection.* | 161 | *If your code does not use third-party libraries, you may skip this subsection.* |
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index ad6f4d42..2e139a41 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
| @@ -417,6 +417,55 @@ describe("LuaRocks build #integration", function() | |||
| 417 | assert.is.truthy(run.luarocks("show uses_luaversion_variable")) | 417 | assert.is.truthy(run.luarocks("show uses_luaversion_variable")) |
| 418 | end, finally) | 418 | end, finally) |
| 419 | end) | 419 | end) |
| 420 | |||
| 421 | |||
| 422 | it("dependency directory is not provided for old format", function() | ||
| 423 | test_env.run_in_tmp(function(tmpdir) | ||
| 424 | local rocks_tree = run.luarocks("config variables.ROCKS_TREE") | ||
| 425 | local rocks_path = table.concat({rocks_tree, "a_rock", "1.0-1"}, package.config:sub(1, 1)) | ||
| 426 | write_file("verify_argument.lua", string.format("assert(arg[1] == %q)", rocks_path)) | ||
| 427 | write_file("uses_rockdir_variable-3.1-11.rockspec", [[ | ||
| 428 | package = "uses_rockdir_variable" | ||
| 429 | version = "3.1-11" | ||
| 430 | source = { | ||
| 431 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/verify_argument.lua" | ||
| 432 | } | ||
| 433 | dependencies = { | ||
| 434 | "a_rock 1.0" | ||
| 435 | } | ||
| 436 | build = { | ||
| 437 | type = "command", | ||
| 438 | build_command = "$(LUA) verify_argument.lua $(A_ROCK_ROCKDIR)", | ||
| 439 | } | ||
| 440 | ]]) | ||
| 441 | assert.is_false(run.luarocks_bool("build uses_rockdir_variable-3.1-11.rockspec")) | ||
| 442 | end, finally) | ||
| 443 | end) | ||
| 444 | |||
| 445 | it("dependency directory is provided as variable", function() | ||
| 446 | test_env.run_in_tmp(function(tmpdir) | ||
| 447 | local rocks_tree = run.luarocks("config variables.ROCKS_TREE") | ||
| 448 | local rocks_path = table.concat({rocks_tree, "a_rock", "1.0-1"}, package.config:sub(1, 1)) | ||
| 449 | write_file("verify_argument.lua", string.format("assert(arg[1] == %q)", rocks_path)) | ||
| 450 | write_file("uses_rockdir_variable-3.1-11.rockspec", [[ | ||
| 451 | rockspec_format = "3.1" | ||
| 452 | package = "uses_rockdir_variable" | ||
| 453 | version = "3.1-11" | ||
| 454 | source = { | ||
| 455 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/verify_argument.lua" | ||
| 456 | } | ||
| 457 | dependencies = { | ||
| 458 | "a_rock 1.0" | ||
| 459 | } | ||
| 460 | build = { | ||
| 461 | type = "command", | ||
| 462 | build_command = "$(LUA) verify_argument.lua $(A_ROCK_ROCKDIR)", | ||
| 463 | } | ||
| 464 | ]]) | ||
| 465 | assert.is_truthy(run.luarocks_bool("build uses_rockdir_variable-3.1-11.rockspec")) | ||
| 466 | assert.is.truthy(run.luarocks("show uses_rockdir_variable")) | ||
| 467 | end, finally) | ||
| 468 | end) | ||
| 420 | end) | 469 | end) |
| 421 | 470 | ||
| 422 | describe("#mock external dependencies", function() | 471 | describe("#mock external dependencies", function() |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 19cf6936..5802601e 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
| @@ -329,9 +329,12 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock | |||
| 329 | util.printout(("%s %s depends on %s (%s)"):format( | 329 | util.printout(("%s %s depends on %s (%s)"):format( |
| 330 | name, version, tostring(depq), (rock_status(depq, get_versions)))) | 330 | name, version, tostring(depq), (rock_status(depq, get_versions)))) |
| 331 | 331 | ||
| 332 | local okfulfill, found_or_err, _ = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey) | 332 | local okfulfill, version_or_err, tree = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey) |
| 333 | if okfulfill then | 333 | if okfulfill then |
| 334 | deplocks.add(depskey, depq.name, found_or_err) | 334 | deplocks.add(depskey, depq.name, version_or_err) |
| 335 | if tree and rockspec:format_is_at_least("3.1") then | ||
| 336 | rockspec.variables[depq.name:upper() .. "_ROCKDIR"] = path.install_dir(depq.name, version_or_err, tree) | ||
| 337 | end | ||
| 335 | else | 338 | else |
| 336 | if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then | 339 | if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then |
| 337 | util.printerr("This version of " .. name .. " is designed for use with") | 340 | util.printerr("This version of " .. name .. " is designed for use with") |
| @@ -341,7 +344,7 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock | |||
| 341 | util.printerr("or look for a suitable version of " .. name .. " with") | 344 | util.printerr("or look for a suitable version of " .. name .. " with") |
| 342 | util.printerr(" luarocks search " .. name) | 345 | util.printerr(" luarocks search " .. name) |
| 343 | end | 346 | end |
| 344 | return nil, found_or_err | 347 | return nil, version_or_err |
| 345 | end | 348 | end |
| 346 | end | 349 | end |
| 347 | 350 | ||
diff --git a/src/luarocks/deps.tl b/src/luarocks/deps.tl index f6a6642f..d127288e 100644 --- a/src/luarocks/deps.tl +++ b/src/luarocks/deps.tl | |||
| @@ -329,9 +329,12 @@ function deps.fulfill_dependencies(rockspec: Rockspec, depskey: DepsKey, deps_mo | |||
| 329 | util.printout(("%s %s depends on %s (%s)"):format( | 329 | util.printout(("%s %s depends on %s (%s)"):format( |
| 330 | name, version, tostring(depq), (rock_status(depq, get_versions)))) | 330 | name, version, tostring(depq), (rock_status(depq, get_versions)))) |
| 331 | 331 | ||
| 332 | local okfulfill, found_or_err, _ = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey) | 332 | local okfulfill, version_or_err, tree = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey) |
| 333 | if okfulfill then | 333 | if okfulfill then |
| 334 | deplocks.add(depskey, depq.name, found_or_err) | 334 | deplocks.add(depskey, depq.name, version_or_err) |
| 335 | if tree and rockspec:format_is_at_least("3.1") then | ||
| 336 | rockspec.variables[depq.name:upper() .. "_ROCKDIR"] = path.install_dir(depq.name, version_or_err, tree) | ||
| 337 | end | ||
| 335 | else | 338 | else |
| 336 | if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then | 339 | if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then |
| 337 | util.printerr("This version of "..name.." is designed for use with") | 340 | util.printerr("This version of "..name.." is designed for use with") |
| @@ -341,7 +344,7 @@ function deps.fulfill_dependencies(rockspec: Rockspec, depskey: DepsKey, deps_mo | |||
| 341 | util.printerr("or look for a suitable version of "..name.." with") | 344 | util.printerr("or look for a suitable version of "..name.." with") |
| 342 | util.printerr(" luarocks search "..name) | 345 | util.printerr(" luarocks search "..name) |
| 343 | end | 346 | end |
| 344 | return nil, found_or_err | 347 | return nil, version_or_err |
| 345 | end | 348 | end |
| 346 | end | 349 | end |
| 347 | 350 | ||
