diff options
author | Hisham <hisham@gobolinux.org> | 2016-10-29 17:47:27 -0200 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-10-29 17:47:27 -0200 |
commit | bcdb901611b05870692de69bd2a7cd1eec88a114 (patch) | |
tree | d81dae90741c06b9d416ad0b6269327629d3ef77 /src | |
parent | 5b8d37cdbdd93e0cbd4e78d564dd0018972b3a44 (diff) | |
download | luarocks-bcdb901611b05870692de69bd2a7cd1eec88a114.tar.gz luarocks-bcdb901611b05870692de69bd2a7cd1eec88a114.tar.bz2 luarocks-bcdb901611b05870692de69bd2a7cd1eec88a114.zip |
Adjust changes by @mpeterv in #638 to new locations.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/manif/writer.lua | 189 | ||||
-rw-r--r-- | src/luarocks/repos.lua | 4 |
2 files changed, 126 insertions, 67 deletions
diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index 1eb5ee7c..df971fca 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua | |||
@@ -13,33 +13,60 @@ local path = require("luarocks.path") | |||
13 | local persist = require("luarocks.persist") | 13 | local persist = require("luarocks.persist") |
14 | local manif = require("luarocks.manif") | 14 | local manif = require("luarocks.manif") |
15 | 15 | ||
16 | --- Output a table listing items of a package. | 16 | --- Update storage table to account for items provided by a package. |
17 | -- @param itemsfn function: a function for obtaining items of a package. | 17 | -- @param storage table: a table storing items in the following format: |
18 | -- pkg and version will be passed to it; it should return a table with | 18 | -- keys are item names and values are arrays of packages providing each item, |
19 | -- items as keys. | 19 | -- where a package is specified as string `name/version`. |
20 | -- @param pkg string: package name | 20 | -- @param items table: a table mapping item names to paths. |
21 | -- @param version string: package version | 21 | -- @param name string: package name. |
22 | -- @param tbl table: the package matching table: keys should be item names | 22 | -- @param version string: package version. |
23 | -- and values arrays of strings with packages names in "name/version" format. | 23 | local function store_package_items(storage, name, version, items) |
24 | local function store_package_items(itemsfn, pkg, version, tbl) | 24 | assert(type(storage) == "table") |
25 | assert(type(itemsfn) == "function") | 25 | assert(type(items) == "table") |
26 | assert(type(pkg) == "string") | 26 | assert(type(name) == "string") |
27 | assert(type(version) == "string") | 27 | assert(type(version) == "string") |
28 | assert(type(tbl) == "table") | ||
29 | 28 | ||
30 | local pkg_version = pkg.."/"..version | 29 | local package_identifier = name.."/"..version |
31 | local result = {} | ||
32 | 30 | ||
33 | for item, path in pairs(itemsfn(pkg, version)) do | 31 | for item_name, path in pairs(items) do |
34 | result[item] = path | 32 | if not storage[item_name] then |
35 | if not tbl[item] then | 33 | storage[item_name] = {} |
36 | tbl[item] = {} | ||
37 | end | 34 | end |
38 | table.insert(tbl[item], pkg_version) | 35 | |
36 | table.insert(storage[item_name], package_identifier) | ||
39 | end | 37 | end |
40 | return result | ||
41 | end | 38 | end |
42 | 39 | ||
40 | --- Update storage table removing items provided by a package. | ||
41 | -- @param storage table: a table storing items in the following format: | ||
42 | -- keys are item names and values are arrays of packages providing each item, | ||
43 | -- where a package is specified as string `name/version`. | ||
44 | -- @param items table: a table mapping item names to paths. | ||
45 | -- @param name string: package name. | ||
46 | -- @param version string: package version. | ||
47 | local function remove_package_items(storage, name, version, items) | ||
48 | assert(type(storage) == "table") | ||
49 | assert(type(items) == "table") | ||
50 | assert(type(name) == "string") | ||
51 | assert(type(version) == "string") | ||
52 | |||
53 | local package_identifier = name.."/"..version | ||
54 | |||
55 | for item_name, path in pairs(items) do | ||
56 | local all_identifiers = storage[item_name] | ||
57 | |||
58 | for i, identifier in ipairs(all_identifiers) do | ||
59 | if identifier == package_identifier then | ||
60 | table.remove(all_identifiers, i) | ||
61 | break | ||
62 | end | ||
63 | end | ||
64 | |||
65 | if #all_identifiers == 0 then | ||
66 | storage[item_name] = nil | ||
67 | end | ||
68 | end | ||
69 | end | ||
43 | 70 | ||
44 | --- Process the dependencies of a manifest table to determine its dependency | 71 | --- Process the dependencies of a manifest table to determine its dependency |
45 | -- chains for loading modules. The manifest dependencies information is filled | 72 | -- chains for loading modules. The manifest dependencies information is filled |
@@ -174,12 +201,10 @@ end | |||
174 | -- @param results table: The search results as returned by search.disk_search. | 201 | -- @param results table: The search results as returned by search.disk_search. |
175 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). | 202 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). |
176 | -- It will be altered to include the search results. | 203 | -- It will be altered to include the search results. |
177 | -- @param dep_handler: dependency handler function | ||
178 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. | 204 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. |
179 | local function store_results(results, manifest, dep_handler) | 205 | local function store_results(results, manifest) |
180 | assert(type(results) == "table") | 206 | assert(type(results) == "table") |
181 | assert(type(manifest) == "table") | 207 | assert(type(manifest) == "table") |
182 | assert((not dep_handler) or type(dep_handler) == "function") | ||
183 | 208 | ||
184 | for name, versions in pairs(results) do | 209 | for name, versions in pairs(results) do |
185 | local pkgtable = manifest.repository[name] or {} | 210 | local pkgtable = manifest.repository[name] or {} |
@@ -189,10 +214,15 @@ local function store_results(results, manifest, dep_handler) | |||
189 | local entrytable = {} | 214 | local entrytable = {} |
190 | entrytable.arch = entry.arch | 215 | entrytable.arch = entry.arch |
191 | if entry.arch == "installed" then | 216 | if entry.arch == "installed" then |
192 | local rock_manifest, err = manif.load_rock_manifest(name, version) | 217 | local rock_manifest = manif.load_rock_manifest(name, version) |
193 | if not rock_manifest then return nil, err end | 218 | if not rock_manifest then |
194 | entrytable.modules = store_package_items(repos.package_modules, name, version, manifest.modules) | 219 | return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" |
195 | entrytable.commands = store_package_items(repos.package_commands, name, version, manifest.commands) | 220 | end |
221 | |||
222 | entrytable.modules = repos.package_modules(name, version) | ||
223 | store_package_items(manifest.modules, name, version, entrytable.modules) | ||
224 | entrytable.commands = repos.package_commands(name, version) | ||
225 | store_package_items(manifest.commands, name, version, entrytable.commands) | ||
196 | end | 226 | end |
197 | table.insert(versiontable, entrytable) | 227 | table.insert(versiontable, entrytable) |
198 | end | 228 | end |
@@ -200,9 +230,6 @@ local function store_results(results, manifest, dep_handler) | |||
200 | end | 230 | end |
201 | manifest.repository[name] = pkgtable | 231 | manifest.repository[name] = pkgtable |
202 | end | 232 | end |
203 | if dep_handler then | ||
204 | dep_handler(manifest) | ||
205 | end | ||
206 | sort_package_matching_table(manifest.modules) | 233 | sort_package_matching_table(manifest.modules) |
207 | sort_package_matching_table(manifest.commands) | 234 | sort_package_matching_table(manifest.commands) |
208 | return true | 235 | return true |
@@ -265,7 +292,7 @@ end | |||
265 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 292 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
266 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 293 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
267 | -- "none" for the default dependency mode from the configuration. | 294 | -- "none" for the default dependency mode from the configuration. |
268 | -- @param versioned boolean: if versioned versions of the manifest should be created. | 295 | -- @param remote boolean: 'true' if making a manifest for a rocks server. |
269 | -- @return boolean or (nil, string): True if manifest was generated, | 296 | -- @return boolean or (nil, string): True if manifest was generated, |
270 | -- or nil and an error message. | 297 | -- or nil and an error message. |
271 | function writer.make_manifest(repo, deps_mode, remote) | 298 | function writer.make_manifest(repo, deps_mode, remote) |
@@ -286,34 +313,26 @@ function writer.make_manifest(repo, deps_mode, remote) | |||
286 | 313 | ||
287 | manif.cache_manifest(repo, nil, manifest) | 314 | manif.cache_manifest(repo, nil, manifest) |
288 | 315 | ||
289 | local dep_handler = nil | 316 | local ok, err = store_results(results, manifest) |
290 | if not remote then | ||
291 | dep_handler = function(manifest) | ||
292 | update_dependencies(manifest, deps_mode) | ||
293 | end | ||
294 | end | ||
295 | local ok, err = store_results(results, manifest, dep_handler) | ||
296 | if not ok then return nil, err end | 317 | if not ok then return nil, err end |
297 | 318 | ||
298 | if remote then | 319 | if remote then |
299 | local cache = {} | 320 | local cache = {} |
300 | for luaver in util.lua_versions() do | 321 | for luaver in util.lua_versions() do |
301 | local vmanifest = { repository = {}, modules = {}, commands = {} } | 322 | local vmanifest = { repository = {}, modules = {}, commands = {} } |
302 | local dep_handler = function(manifest) | 323 | local ok, err = store_results(results, vmanifest) |
303 | filter_by_lua_version(manifest, luaver, repo, cache) | 324 | filter_by_lua_version(vmanifest, luaver, repo, cache) |
304 | end | ||
305 | store_results(results, vmanifest, dep_handler) | ||
306 | save_table(repo, "manifest-"..luaver, vmanifest) | 325 | save_table(repo, "manifest-"..luaver, vmanifest) |
307 | end | 326 | end |
327 | else | ||
328 | update_dependencies(manifest, deps_mode) | ||
308 | end | 329 | end |
309 | 330 | ||
310 | return save_table(repo, "manifest", manifest) | 331 | return save_table(repo, "manifest", manifest) |
311 | end | 332 | end |
312 | 333 | ||
313 | --- Load a manifest file from a local repository and add to the repository | 334 | --- Update manifest file for a local repository |
314 | -- information with regard to the given name and version. | 335 | -- adding information about a version of a package installed in that repository. |
315 | -- A file called 'manifest' will be written in the root of the given | ||
316 | -- repository directory. | ||
317 | -- @param name string: Name of a package from the repository. | 336 | -- @param name string: Name of a package from the repository. |
318 | -- @param version string: Version of a package from the repository. | 337 | -- @param version string: Version of a package from the repository. |
319 | -- @param repo string or nil: Pathname of a local repository. If not given, | 338 | -- @param repo string or nil: Pathname of a local repository. If not given, |
@@ -321,38 +340,78 @@ end | |||
321 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 340 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
322 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 341 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
323 | -- "none" for using the default dependency mode from the configuration. | 342 | -- "none" for using the default dependency mode from the configuration. |
324 | -- @return boolean or (nil, string): True if manifest was generated, | 343 | -- @return boolean or (nil, string): True if manifest was updated successfully, |
325 | -- or nil and an error message. | 344 | -- or nil and an error message. |
326 | function writer.update_manifest(name, version, repo, deps_mode) | 345 | function writer.add_to_manifest(name, version, repo, deps_mode) |
327 | assert(type(name) == "string") | 346 | assert(type(name) == "string") |
328 | assert(type(version) == "string") | 347 | assert(type(version) == "string") |
329 | repo = path.rocks_dir(repo or cfg.root_dir) | 348 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
330 | assert(type(deps_mode) == "string") | 349 | assert(type(deps_mode) == "string") |
331 | 350 | ||
332 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 351 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
333 | 352 | ||
334 | local manifest, err = manif.load_manifest(repo) | 353 | local manifest, err = manif.load_local_manifest(rocks_dir) |
335 | if not manifest then | 354 | if not manifest then |
336 | util.printerr("No existing manifest. Attempting to rebuild...") | 355 | util.printerr("No existing manifest. Attempting to rebuild...") |
337 | local ok, err = writer.make_manifest(repo, deps_mode) | 356 | -- Manifest built by `manif.make_manifest` should already |
338 | if not ok then | 357 | -- include information about given name and version, |
339 | return nil, err | 358 | -- no need to update it. |
340 | end | 359 | return manif.make_manifest(rocks_dir, deps_mode) |
341 | manifest, err = manif.load_manifest(repo) | ||
342 | if not manifest then | ||
343 | return nil, err | ||
344 | end | ||
345 | end | 360 | end |
346 | 361 | ||
347 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} | 362 | local results = {[name] = {[version] = {{arch = "installed", repo = rocks_dir}}}} |
348 | 363 | ||
349 | local dep_handler = function(manifest) | 364 | local ok, err = store_results(results, manifest) |
350 | update_dependencies(manifest, deps_mode) | ||
351 | end | ||
352 | local ok, err = store_results(results, manifest, dep_handler) | ||
353 | if not ok then return nil, err end | 365 | if not ok then return nil, err end |
354 | 366 | ||
355 | return save_table(repo, "manifest", manifest) | 367 | update_dependencies(manifest, deps_mode) |
368 | return save_table(rocks_dir, "manifest", manifest) | ||
369 | end | ||
370 | |||
371 | --- Update manifest file for a local repository | ||
372 | -- removing information about a version of a package. | ||
373 | -- @param name string: Name of a package removed from the repository. | ||
374 | -- @param version string: Version of a package removed from the repository. | ||
375 | -- @param repo string or nil: Pathname of a local repository. If not given, | ||
376 | -- the default local repository is used. | ||
377 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | ||
378 | -- "all" for all trees, "order" for all trees with priority >= the current default, | ||
379 | -- "none" for using the default dependency mode from the configuration. | ||
380 | -- @return boolean or (nil, string): True if manifest was updated successfully, | ||
381 | -- or nil and an error message. | ||
382 | function writer.remove_from_manifest(name, version, repo, deps_mode) | ||
383 | assert(type(name) == "string") | ||
384 | assert(type(version) == "string") | ||
385 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | ||
386 | assert(type(deps_mode) == "string") | ||
387 | |||
388 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | ||
389 | |||
390 | local manifest, err = manif.load_local_manifest(rocks_dir) | ||
391 | if not manifest then | ||
392 | util.printerr("No existing manifest. Attempting to rebuild...") | ||
393 | -- Manifest built by `manif.make_manifest` should already | ||
394 | -- include up-to-date information, no need to update it. | ||
395 | return manif.make_manifest(rocks_dir, deps_mode) | ||
396 | end | ||
397 | |||
398 | local package_entry = manifest.repository[name] | ||
399 | |||
400 | local version_entry = package_entry[version][1] | ||
401 | remove_package_items(manifest.modules, name, version, version_entry.modules) | ||
402 | remove_package_items(manifest.commands, name, version, version_entry.commands) | ||
403 | |||
404 | package_entry[version] = nil | ||
405 | manifest.dependencies[name][version] = nil | ||
406 | |||
407 | if not next(package_entry) then | ||
408 | -- No more versions of this package. | ||
409 | manifest.repository[name] = nil | ||
410 | manifest.dependencies[name] = nil | ||
411 | end | ||
412 | |||
413 | update_dependencies(manifest, deps_mode) | ||
414 | return save_table(rocks_dir, "manifest", manifest) | ||
356 | end | 415 | end |
357 | 416 | ||
358 | return writer | 417 | return writer |
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 9616fe03..bbc9da79 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
@@ -315,7 +315,7 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
315 | end | 315 | end |
316 | 316 | ||
317 | local writer = require("luarocks.manif.writer") | 317 | local writer = require("luarocks.manif.writer") |
318 | return writer.update_manifest(name, version, nil, deps_mode) | 318 | return writer.add_to_manifest(name, version, nil, deps_mode) |
319 | end | 319 | end |
320 | 320 | ||
321 | --- Delete a package from the local repository. | 321 | --- Delete a package from the local repository. |
@@ -400,7 +400,7 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
400 | end | 400 | end |
401 | 401 | ||
402 | local writer = require("luarocks.manif.writer") | 402 | local writer = require("luarocks.manif.writer") |
403 | return writer.make_manifest(cfg.rocks_dir, deps_mode) | 403 | return writer.remove_from_manifest(name, version, nil, deps_mode) |
404 | end | 404 | end |
405 | 405 | ||
406 | return repos | 406 | return repos |