From 4d7b546602b906f924ac91a01276cd3b2569ca9f Mon Sep 17 00:00:00 2001 From: Renato Maia Date: Mon, 21 Apr 2025 11:16:38 -0300 Subject: feat: add LUA_VERSION build variable for rockspecs --- ...ing_a_makefile_that_plays_nice_with_luarocks.md | 1 + spec/build_spec.lua | 46 ++++++++++++++++++++++ src/luarocks/rockspecs.lua | 3 ++ src/luarocks/rockspecs.tl | 3 ++ src/luarocks/type/rockspec.lua | 5 ++- src/luarocks/type/rockspec.tl | 7 +++- 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/docs/creating_a_makefile_that_plays_nice_with_luarocks.md b/docs/creating_a_makefile_that_plays_nice_with_luarocks.md index 6d9ff2af..a6187659 100644 --- a/docs/creating_a_makefile_that_plays_nice_with_luarocks.md +++ b/docs/creating_a_makefile_that_plays_nice_with_luarocks.md @@ -21,6 +21,7 @@ For building: * `LUA_INCDIR` - where to find the Lua headers * `LUALIB` - the name of the Lua library. This is not available nor needed on all platforms. * `LUA` - the name of the Lua interpreter +* `LUA_VERSION` - the version of Lua For installing: diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 034c70d7..ad6f4d42 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -373,6 +373,52 @@ describe("LuaRocks build #integration", function() end) end) + describe("rockspec format 3.1", function() + it("version of Lua is not provided for old format", function() + test_env.run_in_tmp(function(tmpdir) + write_file("verify_argument.lua", string.format("assert(arg[1] == %q)", test_env.lua_version)) + write_file("uses_luaversion_variable-3.1-11.rockspec", [[ + package = "uses_luaversion_variable" + version = "3.1-11" + source = { + url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/verify_argument.lua" + } + dependencies = { + "lua >= 5.1" + } + build = { + type = "command", + build_command = "$(LUA) verify_argument.lua $(LUA_VERSION)", + } + ]]) + assert.is_false(run.luarocks_bool("build uses_luaversion_variable-3.1-11.rockspec")) + end, finally) + end) + + it("version of Lua is provided as variable", function() + test_env.run_in_tmp(function(tmpdir) + write_file("verify_argument.lua", string.format("assert(arg[1] == %q)", test_env.lua_version)) + write_file("uses_luaversion_variable-3.1-11.rockspec", [[ + rockspec_format = "3.1" + package = "uses_luaversion_variable" + version = "3.1-11" + source = { + url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/verify_argument.lua" + } + dependencies = { + "lua >= 5.1" + } + build = { + type = "command", + build_command = "$(LUA) verify_argument.lua $(LUA_VERSION)", + } + ]]) + assert.is_truthy(run.luarocks_bool("build uses_luaversion_variable-3.1-11.rockspec")) + assert.is.truthy(run.luarocks("show uses_luaversion_variable")) + end, finally) + end) + end) + describe("#mock external dependencies", function() lazy_setup(function() test_env.setup_specs(nil, "mock") diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.lua index 6a9a376c..8a1a528e 100644 --- a/src/luarocks/rockspecs.lua +++ b/src/luarocks/rockspecs.lua @@ -83,6 +83,9 @@ local function configure_paths(rockspec) vars.CONFDIR = path.conf_dir(name, version) vars.BINDIR = path.bin_dir(name, version) vars.DOCDIR = path.doc_dir(name, version) + if rockspec:format_is_at_least("3.1") then + vars.LUA_VERSION = cfg.lua_version + end rockspec.variables = vars end diff --git a/src/luarocks/rockspecs.tl b/src/luarocks/rockspecs.tl index a34c0dbf..9f12649c 100644 --- a/src/luarocks/rockspecs.tl +++ b/src/luarocks/rockspecs.tl @@ -83,6 +83,9 @@ local function configure_paths(rockspec: Rockspec) vars.CONFDIR = path.conf_dir(name, version) vars.BINDIR = path.bin_dir(name, version) vars.DOCDIR = path.doc_dir(name, version) + if rockspec:format_is_at_least("3.1") then + vars.LUA_VERSION = cfg.lua_version + end rockspec.variables = vars end diff --git a/src/luarocks/type/rockspec.lua b/src/luarocks/type/rockspec.lua index cd4044f6..10b06690 100644 --- a/src/luarocks/type/rockspec.lua +++ b/src/luarocks/type/rockspec.lua @@ -11,7 +11,7 @@ local type_check = require("luarocks.type_check") -type_rockspec.rockspec_format = "3.0" +type_rockspec.rockspec_format = "3.1" @@ -174,6 +174,9 @@ local rockspec_formats, versions = type_check.declare_schemas({ }, }, }, + + ["3.1"] = {}, + }) diff --git a/src/luarocks/type/rockspec.tl b/src/luarocks/type/rockspec.tl index 599c13ce..52ad7909 100644 --- a/src/luarocks/type/rockspec.tl +++ b/src/luarocks/type/rockspec.tl @@ -11,7 +11,7 @@ local type_check = require("luarocks.type_check") -- local type TableSchema = type_check.TableSchema -type_rockspec.rockspec_format = "3.0" +type_rockspec.rockspec_format = "3.1" -- Syntax for type-checking tables: -- @@ -173,7 +173,10 @@ local rockspec_formats, versions = type_check.declare_schemas({ _more = true, }, } - } + }, + + ["3.1"] = {}, + }) -- type_rockspec.order = {"rockspec_format", "package", "version", -- cgit v1.2.3-55-g6feb