diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-11-08 18:19:17 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-11-29 18:36:42 -0300 |
| commit | acf8bcb82ae697a5bac94bfbe93c3ad9d7487795 (patch) | |
| tree | 62b7239b8701526d69833d9a64f5757bdee2e1df /spec/make_spec.lua | |
| parent | dfc277954d2fe2586dc491cdc1216bae22399251 (diff) | |
| download | luarocks-acf8bcb82ae697a5bac94bfbe93c3ad9d7487795.tar.gz luarocks-acf8bcb82ae697a5bac94bfbe93c3ad9d7487795.tar.bz2 luarocks-acf8bcb82ae697a5bac94bfbe93c3ad9d7487795.zip | |
dependency pinning: luarocks.lock file and --pin flag
This adds support for pinning dependencies in projects and rocks:
* Adds a new flag called `--pin` which creates a `luarocks.lock`
when building a rock with `luarocks build` or `luarocks make`.
This lock file contains the exact version numbers of every
direct or indirect dependency of the rock (in other words,
it is the transitive closure of the dependencies.)
For `make`, the `luarocks.lock` file is created in the current
directory.
The lock file is also installed as part of the rock in
its metadata directory alongside its rockspec.
When using `--pin`, if a lock file already exists, it is
ignored and overwritten.
* When building a rock with `luarocks make`, if there is a
`luarocks.lock` file in the current directory, the exact
versions specified there will be used for resolving dependencies.
* When building a rock with `luarocks build`, if there is a
`luarocks.lock` file in root of its sources, the exact
versions specified there will be used for resolving dependencies.
* When installing a `.rock` file with `luarocks install`, if the
rock contains a `luarocks.lock` file (i.e., if its dependencies
were pinned with `--pin` when the rock was built), the exact
versions specified there will be used for resolving dependencies.
Diffstat (limited to 'spec/make_spec.lua')
| -rw-r--r-- | spec/make_spec.lua | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 5ec99fa7..8baa3561 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua | |||
| @@ -3,6 +3,7 @@ local lfs = require("lfs") | |||
| 3 | local run = test_env.run | 3 | local run = test_env.run |
| 4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
| 5 | local env_variables = test_env.env_variables | 5 | local env_variables = test_env.env_variables |
| 6 | local write_file = test_env.write_file | ||
| 6 | 7 | ||
| 7 | test_env.unload_luarocks() | 8 | test_env.unload_luarocks() |
| 8 | 9 | ||
| @@ -125,6 +126,124 @@ describe("LuaRocks make tests #integration", function() | |||
| 125 | end) | 126 | end) |
| 126 | end) | 127 | end) |
| 127 | 128 | ||
| 129 | it("supports --pin #pinning", function() | ||
| 130 | test_env.run_in_tmp(function(tmpdir) | ||
| 131 | write_file("test-1.0-1.rockspec", [[ | ||
| 132 | package = "test" | ||
| 133 | version = "1.0-1" | ||
| 134 | source = { | ||
| 135 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
| 136 | } | ||
| 137 | dependencies = { | ||
| 138 | "a_rock 1.0" | ||
| 139 | } | ||
| 140 | build = { | ||
| 141 | type = "builtin", | ||
| 142 | modules = { | ||
| 143 | test = "test.lua" | ||
| 144 | } | ||
| 145 | } | ||
| 146 | ]], finally) | ||
| 147 | write_file("test.lua", "return {}", finally) | ||
| 148 | |||
| 149 | assert.is_true(run.luarocks_bool("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --pin --tree=lua_modules")) | ||
| 150 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
| 151 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | ||
| 152 | local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/luarocks.lock" | ||
| 153 | assert.is.truthy(lfs.attributes(lockfilename)) | ||
| 154 | local lockdata = loadfile(lockfilename)() | ||
| 155 | assert.same({ | ||
| 156 | dependencies = { | ||
| 157 | ["a_rock"] = "1.0-1", | ||
| 158 | ["lua"] = test_env.lua_version .. "-1", | ||
| 159 | } | ||
| 160 | }, lockdata) | ||
| 161 | end) | ||
| 162 | end) | ||
| 163 | |||
| 164 | it("respects luarocks.lock when present #pinning", function() | ||
| 165 | test_env.run_in_tmp(function(tmpdir) | ||
| 166 | write_file("test-2.0-1.rockspec", [[ | ||
| 167 | package = "test" | ||
| 168 | version = "2.0-1" | ||
| 169 | source = { | ||
| 170 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
| 171 | } | ||
| 172 | dependencies = { | ||
| 173 | "a_rock >= 0.8" | ||
| 174 | } | ||
| 175 | build = { | ||
| 176 | type = "builtin", | ||
| 177 | modules = { | ||
| 178 | test = "test.lua" | ||
| 179 | } | ||
| 180 | } | ||
| 181 | ]], finally) | ||
| 182 | write_file("test.lua", "return {}", finally) | ||
| 183 | write_file("luarocks.lock", [[ | ||
| 184 | return { | ||
| 185 | dependencies = { | ||
| 186 | ["a_rock"] = "1.0-1", | ||
| 187 | } | ||
| 188 | } | ||
| 189 | ]], finally) | ||
| 190 | |||
| 191 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules")) | ||
| 192 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) | ||
| 193 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | ||
| 194 | local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/luarocks.lock" | ||
| 195 | assert.is.truthy(lfs.attributes(lockfilename)) | ||
| 196 | local lockdata = loadfile(lockfilename)() | ||
| 197 | assert.same({ | ||
| 198 | dependencies = { | ||
| 199 | ["a_rock"] = "1.0-1", | ||
| 200 | } | ||
| 201 | }, lockdata) | ||
| 202 | end) | ||
| 203 | end) | ||
| 204 | |||
| 205 | it("overrides luarocks.lock with --pin #pinning", function() | ||
| 206 | test_env.run_in_tmp(function(tmpdir) | ||
| 207 | write_file("test-2.0-1.rockspec", [[ | ||
| 208 | package = "test" | ||
| 209 | version = "2.0-1" | ||
| 210 | source = { | ||
| 211 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
| 212 | } | ||
| 213 | dependencies = { | ||
| 214 | "a_rock >= 0.8" | ||
| 215 | } | ||
| 216 | build = { | ||
| 217 | type = "builtin", | ||
| 218 | modules = { | ||
| 219 | test = "test.lua" | ||
| 220 | } | ||
| 221 | } | ||
| 222 | ]], finally) | ||
| 223 | write_file("test.lua", "return {}", finally) | ||
| 224 | write_file("luarocks.lock", [[ | ||
| 225 | return { | ||
| 226 | dependencies = { | ||
| 227 | ["a_rock"] = "1.0-1", | ||
| 228 | } | ||
| 229 | } | ||
| 230 | ]], finally) | ||
| 231 | |||
| 232 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules --pin")) | ||
| 233 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) | ||
| 234 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1/a_rock-2.0-1.rockspec")) | ||
| 235 | local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/luarocks.lock" | ||
| 236 | assert.is.truthy(lfs.attributes(lockfilename)) | ||
| 237 | local lockdata = loadfile(lockfilename)() | ||
| 238 | assert.same({ | ||
| 239 | dependencies = { | ||
| 240 | ["a_rock"] = "2.0-1", | ||
| 241 | ["lua"] = test_env.lua_version .. "-1", | ||
| 242 | } | ||
| 243 | }, lockdata) | ||
| 244 | end) | ||
| 245 | end) | ||
| 246 | |||
| 128 | describe("#ddt LuaRocks make upgrading rockspecs with double deploy types", function() | 247 | describe("#ddt LuaRocks make upgrading rockspecs with double deploy types", function() |
| 129 | local deploy_lib_dir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION | 248 | local deploy_lib_dir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION |
| 130 | local deploy_lua_dir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION | 249 | local deploy_lua_dir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION |
