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 | |
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')
-rw-r--r-- | spec/build_spec.lua | 41 | ||||
-rw-r--r-- | spec/doc_spec.lua | 2 | ||||
-rw-r--r-- | spec/fixtures/a_repo/a_rock-2.0-1.src.rock | bin | 0 -> 541 bytes | |||
-rw-r--r-- | spec/fixtures/a_repo/manifest | 5 | ||||
-rw-r--r-- | spec/fixtures/a_repo/manifest-5.1 | 5 | ||||
-rw-r--r-- | spec/fixtures/a_repo/manifest-5.1.zip | bin | 350 -> 358 bytes | |||
-rw-r--r-- | spec/fixtures/a_repo/manifest-5.2 | 5 | ||||
-rw-r--r-- | spec/fixtures/a_repo/manifest-5.2.zip | bin | 350 -> 358 bytes | |||
-rw-r--r-- | spec/fixtures/a_repo/manifest-5.3 | 5 | ||||
-rw-r--r-- | spec/fixtures/a_repo/manifest-5.3.zip | bin | 350 -> 358 bytes | |||
-rw-r--r-- | spec/install_spec.lua | 44 | ||||
-rw-r--r-- | spec/make_spec.lua | 119 |
12 files changed, 222 insertions, 4 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index eeca75cf..d64ace4d 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
@@ -116,11 +116,11 @@ describe("LuaRocks build #integration", function() | |||
116 | end) | 116 | end) |
117 | 117 | ||
118 | it("with --only-sources", function() | 118 | it("with --only-sources", function() |
119 | assert.is_true(run.luarocks_bool("download --server=" .. testing_paths.fixtures_dir .. "/a_repo --rockspec a_rock")) | 119 | assert.is_true(run.luarocks_bool("download --server=" .. testing_paths.fixtures_dir .. "/a_repo --rockspec a_rock 1.0")) |
120 | assert.is_false(run.luarocks_bool("build --only-sources=\"http://example.com\" a_rock-1.0-1.rockspec")) | 120 | assert.is_false(run.luarocks_bool("build --only-sources=\"http://example.com\" a_rock-1.0-1.rockspec")) |
121 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | 121 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) |
122 | 122 | ||
123 | assert.is_true(run.luarocks_bool("download --server=" .. testing_paths.fixtures_dir .. "/a_repo --source a_rock")) | 123 | assert.is_true(run.luarocks_bool("download --server=" .. testing_paths.fixtures_dir .. "/a_repo --source a_rock 1.0")) |
124 | assert.is_true(run.luarocks_bool("build --only-sources=\"http://example.com\" a_rock-1.0-1.src.rock")) | 124 | assert.is_true(run.luarocks_bool("build --only-sources=\"http://example.com\" a_rock-1.0-1.src.rock")) |
125 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | 125 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) |
126 | 126 | ||
@@ -199,7 +199,42 @@ describe("LuaRocks build #integration", function() | |||
199 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 199 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
200 | end) | 200 | end) |
201 | end) | 201 | end) |
202 | 202 | ||
203 | it("supports --pin #pinning", function() | ||
204 | test_env.run_in_tmp(function(tmpdir) | ||
205 | write_file("test-1.0-1.rockspec", [[ | ||
206 | package = "test" | ||
207 | version = "1.0-1" | ||
208 | source = { | ||
209 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
210 | } | ||
211 | dependencies = { | ||
212 | "a_rock >= 0.8" | ||
213 | } | ||
214 | build = { | ||
215 | type = "builtin", | ||
216 | modules = { | ||
217 | test = "test.lua" | ||
218 | } | ||
219 | } | ||
220 | ]], finally) | ||
221 | write_file("test.lua", "return {}", finally) | ||
222 | |||
223 | assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --tree=lua_modules")) | ||
224 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
225 | 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")) | ||
226 | local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/luarocks.lock" | ||
227 | assert.is.truthy(lfs.attributes(lockfilename)) | ||
228 | local lockdata = loadfile(lockfilename)() | ||
229 | assert.same({ | ||
230 | dependencies = { | ||
231 | ["a_rock"] = "2.0-1", | ||
232 | ["lua"] = test_env.lua_version .. "-1", | ||
233 | } | ||
234 | }, lockdata) | ||
235 | end) | ||
236 | end) | ||
237 | |||
203 | it("lmathx deps partial match", function() | 238 | it("lmathx deps partial match", function() |
204 | assert.is_true(run.luarocks_bool("build lmathx")) | 239 | assert.is_true(run.luarocks_bool("build lmathx")) |
205 | 240 | ||
diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index bf5214d4..2c0f4bce 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua | |||
@@ -70,7 +70,7 @@ describe("LuaRocks doc tests #integration", function() | |||
70 | describe("#namespaces", function() | 70 | describe("#namespaces", function() |
71 | it("retrieves docs for a namespaced package from the command-line", function() | 71 | it("retrieves docs for a namespaced package from the command-line", function() |
72 | assert(run.luarocks_bool("build a_user/a_rock --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) | 72 | assert(run.luarocks_bool("build a_user/a_rock --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) |
73 | assert(run.luarocks_bool("build a_rock --keep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) | 73 | assert(run.luarocks_bool("build a_rock 1.0 --keep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) |
74 | assert.match("a_rock 2.0", run.luarocks("doc a_user/a_rock")) | 74 | assert.match("a_rock 2.0", run.luarocks("doc a_user/a_rock")) |
75 | end) | 75 | end) |
76 | end) | 76 | end) |
diff --git a/spec/fixtures/a_repo/a_rock-2.0-1.src.rock b/spec/fixtures/a_repo/a_rock-2.0-1.src.rock new file mode 100644 index 00000000..5824c767 --- /dev/null +++ b/spec/fixtures/a_repo/a_rock-2.0-1.src.rock | |||
Binary files differ | |||
diff --git a/spec/fixtures/a_repo/manifest b/spec/fixtures/a_repo/manifest index 3b01b427..5ab87d25 100644 --- a/spec/fixtures/a_repo/manifest +++ b/spec/fixtures/a_repo/manifest | |||
@@ -19,6 +19,11 @@ repository = { | |||
19 | { | 19 | { |
20 | arch = "rockspec" | 20 | arch = "rockspec" |
21 | } | 21 | } |
22 | }, | ||
23 | ["2.0-1"] = { | ||
24 | { | ||
25 | arch = "src" | ||
26 | } | ||
22 | } | 27 | } |
23 | }, | 28 | }, |
24 | busted_project = { | 29 | busted_project = { |
diff --git a/spec/fixtures/a_repo/manifest-5.1 b/spec/fixtures/a_repo/manifest-5.1 index 3b01b427..5ab87d25 100644 --- a/spec/fixtures/a_repo/manifest-5.1 +++ b/spec/fixtures/a_repo/manifest-5.1 | |||
@@ -19,6 +19,11 @@ repository = { | |||
19 | { | 19 | { |
20 | arch = "rockspec" | 20 | arch = "rockspec" |
21 | } | 21 | } |
22 | }, | ||
23 | ["2.0-1"] = { | ||
24 | { | ||
25 | arch = "src" | ||
26 | } | ||
22 | } | 27 | } |
23 | }, | 28 | }, |
24 | busted_project = { | 29 | busted_project = { |
diff --git a/spec/fixtures/a_repo/manifest-5.1.zip b/spec/fixtures/a_repo/manifest-5.1.zip index 7b53aeb0..65e316df 100644 --- a/spec/fixtures/a_repo/manifest-5.1.zip +++ b/spec/fixtures/a_repo/manifest-5.1.zip | |||
Binary files differ | |||
diff --git a/spec/fixtures/a_repo/manifest-5.2 b/spec/fixtures/a_repo/manifest-5.2 index 3b01b427..5ab87d25 100644 --- a/spec/fixtures/a_repo/manifest-5.2 +++ b/spec/fixtures/a_repo/manifest-5.2 | |||
@@ -19,6 +19,11 @@ repository = { | |||
19 | { | 19 | { |
20 | arch = "rockspec" | 20 | arch = "rockspec" |
21 | } | 21 | } |
22 | }, | ||
23 | ["2.0-1"] = { | ||
24 | { | ||
25 | arch = "src" | ||
26 | } | ||
22 | } | 27 | } |
23 | }, | 28 | }, |
24 | busted_project = { | 29 | busted_project = { |
diff --git a/spec/fixtures/a_repo/manifest-5.2.zip b/spec/fixtures/a_repo/manifest-5.2.zip index d2eddc40..b4334a65 100644 --- a/spec/fixtures/a_repo/manifest-5.2.zip +++ b/spec/fixtures/a_repo/manifest-5.2.zip | |||
Binary files differ | |||
diff --git a/spec/fixtures/a_repo/manifest-5.3 b/spec/fixtures/a_repo/manifest-5.3 index 3b01b427..5ab87d25 100644 --- a/spec/fixtures/a_repo/manifest-5.3 +++ b/spec/fixtures/a_repo/manifest-5.3 | |||
@@ -19,6 +19,11 @@ repository = { | |||
19 | { | 19 | { |
20 | arch = "rockspec" | 20 | arch = "rockspec" |
21 | } | 21 | } |
22 | }, | ||
23 | ["2.0-1"] = { | ||
24 | { | ||
25 | arch = "src" | ||
26 | } | ||
22 | } | 27 | } |
23 | }, | 28 | }, |
24 | busted_project = { | 29 | busted_project = { |
diff --git a/spec/fixtures/a_repo/manifest-5.3.zip b/spec/fixtures/a_repo/manifest-5.3.zip index 686fe232..bab15712 100644 --- a/spec/fixtures/a_repo/manifest-5.3.zip +++ b/spec/fixtures/a_repo/manifest-5.3.zip | |||
Binary files differ | |||
diff --git a/spec/install_spec.lua b/spec/install_spec.lua index bf50ced7..76dc2201 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua | |||
@@ -267,6 +267,50 @@ describe("luarocks install #integration", function() | |||
267 | end) | 267 | end) |
268 | end) | 268 | end) |
269 | 269 | ||
270 | it("respects luarocks.lock in package #pinning", function() | ||
271 | test_env.run_in_tmp(function(tmpdir) | ||
272 | write_file("test-1.0-1.rockspec", [[ | ||
273 | package = "test" | ||
274 | version = "1.0-1" | ||
275 | source = { | ||
276 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
277 | } | ||
278 | dependencies = { | ||
279 | "a_rock >= 0.8" | ||
280 | } | ||
281 | build = { | ||
282 | type = "builtin", | ||
283 | modules = { | ||
284 | test = "test.lua" | ||
285 | } | ||
286 | } | ||
287 | ]], finally) | ||
288 | write_file("test.lua", "return {}", finally) | ||
289 | write_file("luarocks.lock", [[ | ||
290 | return { | ||
291 | dependencies = { | ||
292 | ["a_rock"] = "1.0-1", | ||
293 | } | ||
294 | } | ||
295 | ]], finally) | ||
296 | |||
297 | assert.is_true(run.luarocks_bool("make --pack-binary-rock --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec")) | ||
298 | assert.is_true(os.remove("luarocks.lock")) | ||
299 | |||
300 | assert.is.truthy(lfs.attributes("./test-1.0-1.all.rock")) | ||
301 | |||
302 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
303 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | ||
304 | |||
305 | print(run.luarocks("install ./test-1.0-1.all.rock --tree=lua_modules --server=" .. testing_paths.fixtures_dir .. "/a_repo")) | ||
306 | |||
307 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
308 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/luarocks.lock")) | ||
309 | 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")) | ||
310 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1")) | ||
311 | end) | ||
312 | end) | ||
313 | |||
270 | describe("#unix install runs build from #git", function() | 314 | describe("#unix install runs build from #git", function() |
271 | local git | 315 | local git |
272 | 316 | ||
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 |