diff options
| author | Hugo Levy-Falk <hugo@klafyvel.me> | 2026-07-14 00:10:33 +0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2026-07-13 19:50:25 -0300 |
| commit | ddbf1ac2e38415a48c89f09238ad9b28d0c3fa68 (patch) | |
| tree | aeb7935abbb3ed8161d6128d127a50aec352bb69 | |
| parent | 3e48d87a0d0527b51eb9520662b5cc2e54d5b66f (diff) | |
| download | luarocks-ddbf1ac2e38415a48c89f09238ad9b28d0c3fa68.tar.gz luarocks-ddbf1ac2e38415a48c89f09238ad9b28d0c3fa68.tar.bz2 luarocks-ddbf1ac2e38415a48c89f09238ad9b28d0c3fa68.zip | |
fix: make write_rockspec command write valid rockspec given the rockspec_format argument.
| -rw-r--r-- | spec/init_spec.lua | 22 | ||||
| -rw-r--r-- | spec/write_rockspec_spec.lua | 22 | ||||
| -rw-r--r-- | src/luarocks/cmd/write_rockspec.lua | 18 | ||||
| -rw-r--r-- | src/luarocks/cmd/write_rockspec.tl | 18 |
4 files changed, 54 insertions, 26 deletions
diff --git a/spec/init_spec.lua b/spec/init_spec.lua index ae211706..c193c32d 100644 --- a/spec/init_spec.lua +++ b/spec/init_spec.lua | |||
| @@ -18,7 +18,7 @@ describe("luarocks #init #integration", function() | |||
| 18 | lfs.mkdir(myproject) | 18 | lfs.mkdir(myproject) |
| 19 | lfs.chdir(myproject) | 19 | lfs.chdir(myproject) |
| 20 | 20 | ||
| 21 | assert(run.luarocks("init")) | 21 | assert(run.luarocks_bool("init")) |
| 22 | if is_win then | 22 | if is_win then |
| 23 | assert.truthy(lfs.attributes(myproject .. "/lua.bat")) | 23 | assert.truthy(lfs.attributes(myproject .. "/lua.bat")) |
| 24 | assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) | 24 | assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) |
| @@ -41,7 +41,7 @@ describe("luarocks #init #integration", function() | |||
| 41 | lfs.mkdir(myproject) | 41 | lfs.mkdir(myproject) |
| 42 | lfs.chdir(myproject) | 42 | lfs.chdir(myproject) |
| 43 | 43 | ||
| 44 | assert(run.luarocks("init --no-gitignore")) | 44 | assert(run.luarocks_bool("init --no-gitignore")) |
| 45 | if is_win then | 45 | if is_win then |
| 46 | assert.truthy(lfs.attributes(myproject .. "/lua.bat")) | 46 | assert.truthy(lfs.attributes(myproject .. "/lua.bat")) |
| 47 | assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) | 47 | assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) |
| @@ -64,7 +64,7 @@ describe("luarocks #init #integration", function() | |||
| 64 | lfs.mkdir(myproject) | 64 | lfs.mkdir(myproject) |
| 65 | lfs.chdir(myproject) | 65 | lfs.chdir(myproject) |
| 66 | 66 | ||
| 67 | assert(run.luarocks("init --no-wrapper-scripts")) | 67 | assert(run.luarocks_bool("init --no-wrapper-scripts")) |
| 68 | assert.falsy(lfs.attributes(myproject .. "/lua.bat")) | 68 | assert.falsy(lfs.attributes(myproject .. "/lua.bat")) |
| 69 | assert.falsy(lfs.attributes(myproject .. "/luarocks.bat")) | 69 | assert.falsy(lfs.attributes(myproject .. "/luarocks.bat")) |
| 70 | assert.falsy(lfs.attributes(myproject .. "/lua")) | 70 | assert.falsy(lfs.attributes(myproject .. "/lua")) |
| @@ -84,7 +84,7 @@ describe("luarocks #init #integration", function() | |||
| 84 | lfs.mkdir(myproject) | 84 | lfs.mkdir(myproject) |
| 85 | lfs.chdir(myproject) | 85 | lfs.chdir(myproject) |
| 86 | 86 | ||
| 87 | assert(run.luarocks("init --wrapper-dir=./bin")) | 87 | assert(run.luarocks_bool("init --wrapper-dir=./bin")) |
| 88 | if is_win then | 88 | if is_win then |
| 89 | assert.truthy(lfs.attributes(myproject .. "/bin/lua.bat")) | 89 | assert.truthy(lfs.attributes(myproject .. "/bin/lua.bat")) |
| 90 | assert.truthy(lfs.attributes(myproject .. "/bin/luarocks.bat")) | 90 | assert.truthy(lfs.attributes(myproject .. "/bin/luarocks.bat")) |
| @@ -107,7 +107,7 @@ describe("luarocks #init #integration", function() | |||
| 107 | lfs.mkdir(myproject) | 107 | lfs.mkdir(myproject) |
| 108 | lfs.chdir(myproject) | 108 | lfs.chdir(myproject) |
| 109 | 109 | ||
| 110 | assert(run.luarocks("init")) | 110 | assert(run.luarocks_bool("init")) |
| 111 | if is_win then | 111 | if is_win then |
| 112 | assert.truthy(lfs.attributes(myproject .. "/lua.bat")) | 112 | assert.truthy(lfs.attributes(myproject .. "/lua.bat")) |
| 113 | assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) | 113 | assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) |
| @@ -146,7 +146,7 @@ describe("luarocks #init #integration", function() | |||
| 146 | lfs.mkdir(myproject) | 146 | lfs.mkdir(myproject) |
| 147 | lfs.chdir(myproject) | 147 | lfs.chdir(myproject) |
| 148 | 148 | ||
| 149 | assert(run.luarocks("init customname 1.0")) | 149 | assert(run.luarocks_bool("init customname 1.0")) |
| 150 | assert.truthy(lfs.attributes(myproject .. "/customname-1.0-1.rockspec")) | 150 | assert.truthy(lfs.attributes(myproject .. "/customname-1.0-1.rockspec")) |
| 151 | assert.truthy(run.luarocks_bool("lint " .. myproject .. "/customname-1.0-1.rockspec")) | 151 | assert.truthy(run.luarocks_bool("lint " .. myproject .. "/customname-1.0-1.rockspec")) |
| 152 | end, finally) | 152 | end, finally) |
| @@ -158,7 +158,7 @@ describe("luarocks #init #integration", function() | |||
| 158 | lfs.mkdir(myproject) | 158 | lfs.mkdir(myproject) |
| 159 | lfs.chdir(myproject) | 159 | lfs.chdir(myproject) |
| 160 | 160 | ||
| 161 | assert(run.luarocks("init --lua-versions=5.1,5.2,5.3,5.4,5.5")) | 161 | assert(run.luarocks_bool("init --lua-versions=5.1,5.2,5.3,5.4,5.5")) |
| 162 | local rockspec_name = myproject .. "/myproject-dev-1.rockspec" | 162 | local rockspec_name = myproject .. "/myproject-dev-1.rockspec" |
| 163 | assert.truthy(lfs.attributes(rockspec_name)) | 163 | assert.truthy(lfs.attributes(rockspec_name)) |
| 164 | local fd = assert(io.open(rockspec_name, "rb")) | 164 | local fd = assert(io.open(rockspec_name, "rb")) |
| @@ -175,7 +175,7 @@ describe("luarocks #init #integration", function() | |||
| 175 | copy_dir(testing_paths.fixtures_dir .. "/git_repo", myproject) | 175 | copy_dir(testing_paths.fixtures_dir .. "/git_repo", myproject) |
| 176 | lfs.chdir(myproject) | 176 | lfs.chdir(myproject) |
| 177 | 177 | ||
| 178 | assert(run.luarocks("init")) | 178 | assert(run.luarocks_bool("init")) |
| 179 | local fd = assert(io.open(myproject .. "/myproject-dev-1.rockspec", "r")) | 179 | local fd = assert(io.open(myproject .. "/myproject-dev-1.rockspec", "r")) |
| 180 | local content = assert(fd:read("*a")) | 180 | local content = assert(fd:read("*a")) |
| 181 | assert.truthy(content:find("summary = \"Test repo\"")) | 181 | assert.truthy(content:find("summary = \"Test repo\"")) |
| @@ -197,7 +197,7 @@ describe("luarocks #init #integration", function() | |||
| 197 | lfs.mkdir(myproject) | 197 | lfs.mkdir(myproject) |
| 198 | lfs.chdir(myproject) | 198 | lfs.chdir(myproject) |
| 199 | 199 | ||
| 200 | assert(run.luarocks("init")) | 200 | assert(run.luarocks_bool("init")) |
| 201 | assert.truthy(lfs.attributes(myproject .. "/.luarocks/config-" .. test_env.lua_version .. ".lua")) | 201 | assert.truthy(lfs.attributes(myproject .. "/.luarocks/config-" .. test_env.lua_version .. ".lua")) |
| 202 | local rockspec_filename = myproject .. "/myproject-dev-1.rockspec" | 202 | local rockspec_filename = myproject .. "/myproject-dev-1.rockspec" |
| 203 | assert.truthy(lfs.attributes(rockspec_filename)) | 203 | assert.truthy(lfs.attributes(rockspec_filename)) |
| @@ -218,14 +218,14 @@ describe("luarocks #init #integration", function() | |||
| 218 | ]], finally) | 218 | ]], finally) |
| 219 | write_file(tmpdir .. "/my_dependency.lua", "return {}", finally) | 219 | write_file(tmpdir .. "/my_dependency.lua", "return {}", finally) |
| 220 | 220 | ||
| 221 | assert.truthy(run.luarocks("build my_dependency-1.0-1.rockspec")) | 221 | assert.truthy(run.luarocks_bool("build my_dependency-1.0-1.rockspec")) |
| 222 | assert.truthy(lfs.attributes(myproject .. "/lua_modules/share/lua/" .. test_env.lua_version .."/my_dependency.lua")) | 222 | assert.truthy(lfs.attributes(myproject .. "/lua_modules/share/lua/" .. test_env.lua_version .."/my_dependency.lua")) |
| 223 | 223 | ||
| 224 | os.remove(rockspec_filename) | 224 | os.remove(rockspec_filename) |
| 225 | os.remove("my_dependency-1.0-1.rockspec") | 225 | os.remove("my_dependency-1.0-1.rockspec") |
| 226 | 226 | ||
| 227 | -- re-run init | 227 | -- re-run init |
| 228 | assert(run.luarocks("init")) | 228 | assert(run.luarocks_bool("init")) |
| 229 | 229 | ||
| 230 | -- file is recreated | 230 | -- file is recreated |
| 231 | assert.truthy(lfs.attributes(rockspec_filename)) | 231 | assert.truthy(lfs.attributes(rockspec_filename)) |
diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 2ade5986..7a8554bb 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua | |||
| @@ -55,13 +55,21 @@ describe("luarocks ##write_rockspec tests #integration", function() | |||
| 55 | -- TODO check contents | 55 | -- TODO check contents |
| 56 | end) | 56 | end) |
| 57 | 57 | ||
| 58 | it("runs with format flag", function() | 58 | local formats = { |
| 59 | finally(function() os.remove("testrock-dev-1.rockspec") end) | 59 | "1.0", |
| 60 | assert.is_true(run.luarocks_bool("write_rockspec git://localhost/testrock --rockspec-format=1.1 --lua-versions=5.1,5.2")) | 60 | "1.1", |
| 61 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) | 61 | "3.0", |
| 62 | assert.truthy(run.luarocks_bool("lint " .. "testrock-dev-1.rockspec")) | 62 | "3.1", |
| 63 | -- TODO check contents | 63 | } |
| 64 | end) | 64 | for i, format in ipairs(formats) do |
| 65 | it("runs with format flag " .. format, function() | ||
| 66 | finally(function() os.remove("testrock-dev-1.rockspec") end) | ||
| 67 | assert.is_true(run.luarocks_bool("write_rockspec git://localhost/testrock --rockspec-format=" .. format .. " --lua-versions=5.1,5.2")) | ||
| 68 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) | ||
| 69 | assert.truthy(run.luarocks_bool("lint " .. "testrock-dev-1.rockspec")) | ||
| 70 | -- TODO check contents | ||
| 71 | end) | ||
| 72 | end | ||
| 65 | 73 | ||
| 66 | it("runs with full flags", function() | 74 | it("runs with full flags", function() |
| 67 | finally(function() os.remove("testrock-dev-1.rockspec") end) | 75 | finally(function() os.remove("testrock-dev-1.rockspec") end) |
diff --git a/src/luarocks/cmd/write_rockspec.lua b/src/luarocks/cmd/write_rockspec.lua index 5710c982..2d663c1a 100644 --- a/src/luarocks/cmd/write_rockspec.lua +++ b/src/luarocks/cmd/write_rockspec.lua | |||
| @@ -264,23 +264,32 @@ local function rockspec_cleanup(rockspec) | |||
| 264 | rockspec.source.pathname = nil | 264 | rockspec.source.pathname = nil |
| 265 | rockspec.variables = nil | 265 | rockspec.variables = nil |
| 266 | rockspec.name = nil | 266 | rockspec.name = nil |
| 267 | rockspec.format_is_at_least = nil | ||
| 268 | rockspec.local_abs_filename = nil | 267 | rockspec.local_abs_filename = nil |
| 269 | rockspec.rocks_provided = nil | 268 | rockspec.rocks_provided = nil |
| 270 | 269 | ||
| 271 | local dep_lists = { | 270 | local dep_lists = { |
| 272 | dependencies = rockspec.dependencies, | 271 | dependencies = rockspec.dependencies, |
| 273 | build_dependencies = rockspec.build_dependencies, | ||
| 274 | test_dependencies = rockspec.test_dependencies, | ||
| 275 | } | 272 | } |
| 273 | if rockspec:format_is_at_least("3.0") then | ||
| 274 | dep_lists.build_dependencies = rockspec.build_dependencies | ||
| 275 | dep_lists.test_dependencies = rockspec.test_dependencies | ||
| 276 | else | ||
| 277 | rockspec.build_dependencies = nil | ||
| 278 | rockspec.test_dependencies = nil | ||
| 279 | end | ||
| 280 | rockspec.format_is_at_least = nil | ||
| 276 | 281 | ||
| 277 | for name, data in pairs(dep_lists) do | 282 | for name, data in pairs(dep_lists) do |
| 278 | if not next(data) then | 283 | if not next(data) then |
| 279 | (rockspec)[name] = nil | 284 | (rockspec)[name] = nil |
| 280 | else | 285 | else |
| 286 | local new_data = {} | ||
| 281 | for i, item in ipairs(data) do | 287 | for i, item in ipairs(data) do |
| 282 | data[i] = tostring(item) | 288 | if type(item) == "string" then |
| 289 | new_data[i] = tostring(item) | ||
| 290 | end | ||
| 283 | end | 291 | end |
| 292 | (rockspec)[name] = new_data | ||
| 284 | end | 293 | end |
| 285 | end | 294 | end |
| 286 | end | 295 | end |
| @@ -350,6 +359,7 @@ function write_rockspec.command(args) | |||
| 350 | }, | 359 | }, |
| 351 | build = {}, | 360 | build = {}, |
| 352 | }) | 361 | }) |
| 362 | |||
| 353 | assert(not err, err) | 363 | assert(not err, err) |
| 354 | rockspec.source.protocol = protocol | 364 | rockspec.source.protocol = protocol |
| 355 | 365 | ||
diff --git a/src/luarocks/cmd/write_rockspec.tl b/src/luarocks/cmd/write_rockspec.tl index cb48ca3f..2e4df014 100644 --- a/src/luarocks/cmd/write_rockspec.tl +++ b/src/luarocks/cmd/write_rockspec.tl | |||
| @@ -264,23 +264,32 @@ local function rockspec_cleanup(rockspec: Rockspec) | |||
| 264 | rockspec.source.pathname = nil | 264 | rockspec.source.pathname = nil |
| 265 | rockspec.variables = nil | 265 | rockspec.variables = nil |
| 266 | rockspec.name = nil | 266 | rockspec.name = nil |
| 267 | rockspec.format_is_at_least = nil | ||
| 268 | rockspec.local_abs_filename = nil | 267 | rockspec.local_abs_filename = nil |
| 269 | rockspec.rocks_provided = nil | 268 | rockspec.rocks_provided = nil |
| 270 | 269 | ||
| 271 | local dep_lists: {string: Dependencies} = { | 270 | local dep_lists: {string: Dependencies} = { |
| 272 | dependencies = rockspec.dependencies, | 271 | dependencies = rockspec.dependencies, |
| 273 | build_dependencies = rockspec.build_dependencies, | ||
| 274 | test_dependencies = rockspec.test_dependencies, | ||
| 275 | } | 272 | } |
| 273 | if rockspec:format_is_at_least("3.0") then | ||
| 274 | dep_lists.build_dependencies = rockspec.build_dependencies | ||
| 275 | dep_lists.test_dependencies = rockspec.test_dependencies | ||
| 276 | else | ||
| 277 | rockspec.build_dependencies = nil | ||
| 278 | rockspec.test_dependencies = nil | ||
| 279 | end | ||
| 280 | rockspec.format_is_at_least = nil | ||
| 276 | 281 | ||
| 277 | for name, data in pairs(dep_lists) do | 282 | for name, data in pairs(dep_lists) do |
| 278 | if not next(data) then | 283 | if not next(data) then |
| 279 | (rockspec as {string: Dependencies})[name] = nil | 284 | (rockspec as {string: Dependencies})[name] = nil |
| 280 | else | 285 | else |
| 286 | local new_data: {string} = {} | ||
| 281 | for i, item in ipairs(data) do | 287 | for i, item in ipairs(data) do |
| 282 | data[i] = tostring(item) | 288 | if type(item) == "string" then |
| 289 | new_data[i] = tostring(item) | ||
| 290 | end | ||
| 283 | end | 291 | end |
| 292 | (rockspec as {string: Dependencies})[name] = new_data | ||
| 284 | end | 293 | end |
| 285 | end | 294 | end |
| 286 | end | 295 | end |
| @@ -350,6 +359,7 @@ function write_rockspec.command(args: Args): boolean, string | |||
| 350 | }, | 359 | }, |
| 351 | build = {}, | 360 | build = {}, |
| 352 | }) | 361 | }) |
| 362 | |||
| 353 | assert(not err, err) | 363 | assert(not err, err) |
| 354 | rockspec.source.protocol = protocol | 364 | rockspec.source.protocol = protocol |
| 355 | 365 | ||
