aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-10-04 16:12:07 +0000
committerhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-10-04 16:12:07 +0000
commitc9c83162748bea1f9c1b6574ce3cc6560e5490b4 (patch)
treedddafb3f264cae08a077c34f38e96919355208a3
parent57bd8fe99a3374f7890b7dfe1e2ffd726ea5f8cf (diff)
downloadluarocks-c9c83162748bea1f9c1b6574ce3cc6560e5490b4.tar.gz
luarocks-c9c83162748bea1f9c1b6574ce3cc6560e5490b4.tar.bz2
luarocks-c9c83162748bea1f9c1b6574ce3cc6560e5490b4.zip
Simplify the way things are handled for the new LuaRocks tree by creating rock_manifest files for each rock.
git-svn-id: http://luarocks.org/svn/luarocks/trunk@62 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
-rw-r--r--src/luarocks/build.lua16
-rw-r--r--src/luarocks/install.lua25
-rw-r--r--src/luarocks/make_manifest.lua3
-rw-r--r--src/luarocks/manif.lua371
-rw-r--r--src/luarocks/pack.lua9
-rw-r--r--src/luarocks/rep.lua148
6 files changed, 253 insertions, 319 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index a6fe1c45..997929a8 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -211,18 +211,18 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode)
211 fs.pop_dir() 211 fs.pop_dir()
212 end 212 end
213 213
214 ok, err = rep.install_bins(name, version) 214 ok, err = manif.make_rock_manifest(name, version)
215 if not ok then return nil, err end 215 if err then return nil, err end
216
217 ok, err = rep.deploy_files(name, version)
218 if err then return nil, err end
216 219
217 ok, err = rep.run_hook(rockspec, "post_install") 220 ok, err = rep.run_hook(rockspec, "post_install")
218 if err then 221 if err then return nil, err end
219 return nil, err
220 end
221 222
222 ok, err = manif.update_manifest(name, version) 223 ok, err = manif.update_manifest(name, version)
223 if err then 224 if err then return nil, err end
224 return nil, err 225
225 end
226 util.remove_scheduled_function(rollback) 226 util.remove_scheduled_function(rollback)
227 return true 227 return true
228end 228end
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 3ef32c99..15e905e1 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -38,38 +38,35 @@ function install_binary_rock(rock_file)
38 if rep.is_installed(name, version) then 38 if rep.is_installed(name, version) then
39 rep.delete_version(name, version) 39 rep.delete_version(name, version)
40 end 40 end
41
41 local rollback = util.schedule_function(function() 42 local rollback = util.schedule_function(function()
42 fs.delete(path.install_dir(name, version)) 43 fs.delete(path.install_dir(name, version))
43 fs.remove_dir_if_empty(path.versions_dir(name)) 44 fs.remove_dir_if_empty(path.versions_dir(name))
44 end) 45 end)
46
45 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, path.install_dir(name, version)) 47 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, path.install_dir(name, version))
46 if not ok then return nil, err, errcode end 48 if not ok then return nil, err, errcode end
47 ok, err = rep.install_bins(name, version) 49
48
49 local rockspec, err, errcode = fetch.load_rockspec(path.rockspec_file(name, version)) 50 local rockspec, err, errcode = fetch.load_rockspec(path.rockspec_file(name, version))
50 if err then 51 if err then
51 return nil, "Failed loading rockspec for installed package: "..err, errcode 52 return nil, "Failed loading rockspec for installed package: "..err, errcode
52 end 53 end
53 54
54 ok, err, errcode = deps.check_external_deps(rockspec, "install") 55 ok, err, errcode = deps.check_external_deps(rockspec, "install")
55 if err then 56 if err then return nil, err, errcode end
56 return nil, err, errcode
57 end
58 57
59 ok, err, errcode = deps.fulfill_dependencies(rockspec) 58 ok, err, errcode = deps.fulfill_dependencies(rockspec)
60 if err then 59 if err then return nil, err, errcode end
61 return nil, err, errcode
62 end
63 60
64 ok, err = rep.run_hook(rockspec, "post_install") 61 ok, err = rep.run_hook(rockspec, "post_install")
65 if err then 62 if err then return nil, err end
66 return nil, err 63
67 end 64 ok, err = rep.deploy_files(name, version)
65 if err then return nil, err end
68 66
69 ok, err = manif.update_manifest(name, version) 67 ok, err = manif.update_manifest(name, version)
70 if err then 68 if err then return nil, err end
71 return nil, err 69
72 end
73 util.remove_scheduled_function(rollback) 70 util.remove_scheduled_function(rollback)
74 return true 71 return true
75end 72end
diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua
index 622c21a0..bec1b704 100644
--- a/src/luarocks/make_manifest.lua
+++ b/src/luarocks/make_manifest.lua
@@ -4,6 +4,7 @@
4module("luarocks.make_manifest", package.seeall) 4module("luarocks.make_manifest", package.seeall)
5 5
6local manif = require("luarocks.manif") 6local manif = require("luarocks.manif")
7local index = require("luarocks.index")
7local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
8 9
9help_summary = "Compile a manifest file for a repository." 10help_summary = "Compile a manifest file for a repository."
@@ -26,7 +27,7 @@ function run(repo)
26 ok, err = manif.make_manifest(repo) 27 ok, err = manif.make_manifest(repo)
27 if ok then 28 if ok then
28 print("Generating index.html for "..repo) 29 print("Generating index.html for "..repo)
29 manif.make_index(repo) 30 index.make_index(repo)
30 end 31 end
31 return ok, err 32 return ok, err
32end 33end
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index 2343489b..de885ca5 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -1,85 +1,77 @@
1 1
2--- Functions for querying and manipulating manifest files.
3module("luarocks.manif", package.seeall) 2module("luarocks.manif", package.seeall)
4 3
5local util = require("luarocks.util") 4local manif_core = require("luarocks.manif_core")
5local persist = require("luarocks.persist")
6local fetch = require("luarocks.fetch")
7local dir = require("luarocks.dir")
6local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
7local search = require("luarocks.search") 9local search = require("luarocks.search")
10local util = require("luarocks.util")
11local cfg = require("luarocks.cfg")
12local path = require("luarocks.path")
8local rep = require("luarocks.rep") 13local rep = require("luarocks.rep")
9local deps = require("luarocks.deps") 14local deps = require("luarocks.deps")
10local cfg = require("luarocks.cfg")
11local persist = require("luarocks.persist")
12local fetch = require("luarocks.fetch")
13local dir = require("luarocks.dir")
14local manif_core = require("luarocks.manif_core")
15 15
16local function find_module_at_file(file, modules) 16rock_manifest_cache = {}
17 for module, location in pairs(modules) do 17
18 if file == location then 18--- Commit a table to disk in given local path.
19 return module 19-- @param where string: The directory where the table should be saved.
20 end 20-- @param name string: The filename.
21 end 21-- @param tbl table: The table to be saved.
22end 22-- @return boolean or (nil, string): true if successful, or nil and a
23-- message in case of errors.
24local function save_table(where, name, tbl)
25 assert(type(where) == "string")
26 assert(type(name) == "string")
27 assert(type(tbl) == "table")
23 28
24local function rename_module(file, pkgid) 29 local filename = dir.path(where, name)
25 local path = dir.dir_name(file) 30 return persist.save_from_table(filename, tbl)
26 local name = dir.base_name(file)
27 local pkgid = pkgid:gsub("[/.-]", "_")
28 return dir.path(path, pkgid.."-"..name)
29end 31end
30 32
31local function update_global_lib(repo, manifest) 33function load_rock_manifest(name, version)
32 fs.make_dir(cfg.lua_modules_dir) 34 assert(type(name) == "string")
33 fs.make_dir(cfg.bin_modules_dir) 35 assert(type(version) == "string")
34 for rock, modules in pairs(manifest.modules) do
35 for module, file in pairs(modules) do
36 local module_type, modules_dir
37
38 if file:match("%."..cfg.lua_extension.."$") then
39 module_type = "lua"
40 modules_dir = cfg.lua_modules_dir
41 else
42 module_type = "bin"
43 modules_dir = cfg.bin_modules_dir
44 end
45 36
46 if not file:match("^"..modules_dir) then 37 local name_version = name.."/"..version
47 local path_in_rock = dir.strip_base_dir(file:sub(#dir.path(repo, module)+2)) 38 if rock_manifest_cache[name_version] then
48 local module_dir = dir.dir_name(path_in_rock) 39 return rock_manifest_cache[name_version].rock_manifest
49 local dest = dir.path(modules_dir, path_in_rock) 40 end
50 if module_dir ~= "" then 41 local install_dir = path.install_dir(name, version)
51 fs.make_dir(dir.dir_name(dest)) 42 local pathname = dir.path(install_dir, "rock_manifest")
52 end 43 local rock_manifest = persist.load_into_table(pathname)
53 if not fs.exists(dest) then 44 if not rock_manifest then return nil end
54 fs.move(file, dest) 45 rock_manifest_cache[name_version] = rock_manifest
55 fs.remove_dir_tree_if_empty(dir.dir_name(file)) 46 return rock_manifest.rock_manifest
56 manifest.modules[rock][module] = dest 47end
57 else 48
58 local current = find_module_at_file(dest, modules) 49function make_rock_manifest(name, version)
59 if not current then 50 local install_dir = path.install_dir(name, version)
60 util.warning("installed file not tracked by LuaRocks: "..dest) 51 local rock_manifest = dir.path(install_dir, "rock_manifest")
61 else 52 local tree = {}
62 local newname = rename_module(dest, current) 53 for _, file in ipairs(fs.find(install_dir)) do
63 if fs.exists(newname) then 54 local full_path = dir.path(install_dir, file)
64 util.warning("conflict when tracking modules: "..newname.." exists.") 55 local walk = tree
65 else 56 local last
66 local ok, err = fs.move(dest, newname) 57 local last_name
67 if ok then 58 for name in file:gmatch("[^/]+") do
68 manifest.modules[rock][current] = newname 59 local next = walk[name]
69 fs.move(file, dest) 60 if not next then
70 fs.remove_dir_tree_if_empty(dir.dir_name(file)) 61 next = {}
71 manifest.modules[rock][module] = dest 62 walk[name] = next
72 else
73 util.warning(err)
74 end
75 end
76 end
77 end
78 else
79 -- print("File already in place.")
80 end 63 end
64 last = walk
65 last_name = name
66 walk = next
67 end
68 if fs.is_file(full_path) then
69 last[last_name] = fs.get_md5(full_path)
81 end 70 end
82 end 71 end
72 local rock_manifest = { rock_manifest=tree }
73 rock_manifest_cache[name.."/"..version] = rock_manifest
74 save_table(install_dir, "rock_manifest", rock_manifest )
83end 75end
84 76
85--- Load a local or remote manifest describing a repository. 77--- Load a local or remote manifest describing a repository.
@@ -110,23 +102,6 @@ function load_manifest(repo_url)
110 return manif_core.manifest_loader(pathname, repo_url) 102 return manif_core.manifest_loader(pathname, repo_url)
111end 103end
112 104
113--- Sort function for ordering rock identifiers in a manifest's
114-- modules table. Rocks are ordered alphabetically by name, and then
115-- by version which greater first.
116-- @param a string: Version to compare.
117-- @param b string: Version to compare.
118-- @return boolean: The comparison result, according to the
119-- rule outlined above.
120local function sort_pkgs(a, b)
121 assert(type(a) == "string")
122 assert(type(b) == "string")
123
124 local na, va = a:match("(.*)/(.*)$")
125 local nb, vb = b:match("(.*)/(.*)$")
126
127 return (na == nb) and deps.compare_versions(va, vb) or na < nb
128end
129
130--- Output a table listing items of a package. 105--- Output a table listing items of a package.
131-- @param itemsfn function: a function for obtaining items of a package. 106-- @param itemsfn function: a function for obtaining items of a package.
132-- pkg and version will be passed to it; it should return a table with 107-- pkg and version will be passed to it; it should return a table with
@@ -143,16 +118,34 @@ local function store_package_items(itemsfn, pkg, version, tbl)
143 118
144 local pkg_version = pkg.."/"..version 119 local pkg_version = pkg.."/"..version
145 local result = {} 120 local result = {}
121
146 for item, path in pairs(itemsfn(pkg, version)) do 122 for item, path in pairs(itemsfn(pkg, version)) do
147 result[item] = path 123 result[item] = path
148 if not tbl[item] then 124 if not tbl[item] then
149 tbl[item] = {} 125 tbl[item] = {}
150 end 126 end
151 tbl[item][pkg_version] = path 127 table.insert(tbl[item], pkg_version)
152 end 128 end
153 return result 129 return result
154end 130end
155 131
132--- Sort function for ordering rock identifiers in a manifest's
133-- modules table. Rocks are ordered alphabetically by name, and then
134-- by version which greater first.
135-- @param a string: Version to compare.
136-- @param b string: Version to compare.
137-- @return boolean: The comparison result, according to the
138-- rule outlined above.
139local function sort_pkgs(a, b)
140 assert(type(a) == "string")
141 assert(type(b) == "string")
142
143 local na, va = a:match("(.*)/(.*)$")
144 local nb, vb = b:match("(.*)/(.*)$")
145
146 return (na == nb) and deps.compare_versions(va, vb) or na < nb
147end
148
156--- Sort items of a package matching table by version number (higher versions first). 149--- Sort items of a package matching table by version number (higher versions first).
157-- @param tbl table: the package matching table: keys should be strings 150-- @param tbl table: the package matching table: keys should be strings
158-- and values arrays of strings with packages names in "name/version" format. 151-- and values arrays of strings with packages names in "name/version" format.
@@ -180,19 +173,6 @@ local function sort_package_matching_table(tbl)
180 end 173 end
181end 174end
182 175
183--- Commit manifest to disk in given local repository.
184-- @param repo string: The directory of the local repository.
185-- @param manifest table: The manifest table
186-- @return boolean or (nil, string): true if successful, or nil and a
187-- message in case of errors.
188local function save_manifest(repo, manifest)
189 assert(type(repo) == "string")
190 assert(type(manifest) == "table")
191
192 local filename = dir.path(repo, "manifest")
193 return persist.save_from_table(filename, manifest)
194end
195
196--- Process the dependencies of a package to determine its dependency 176--- Process the dependencies of a package to determine its dependency
197-- chain for loading modules. 177-- chain for loading modules.
198-- @param name string: Package name. 178-- @param name string: Package name.
@@ -252,6 +232,34 @@ local function store_results(results, manifest)
252 sort_package_matching_table(manifest.commands) 232 sort_package_matching_table(manifest.commands)
253end 233end
254 234
235--- Scan a LuaRocks repository and output a manifest file.
236-- A file called 'manifest' will be written in the root of the given
237-- repository directory.
238-- @param repo A local repository directory.
239-- @return boolean or (nil, string): True if manifest was generated,
240-- or nil and an error message.
241function make_manifest(repo)
242 assert(type(repo) == "string")
243
244 if not fs.is_dir(repo) then
245 return nil, "Cannot access repository at "..repo
246 end
247
248 local query = search.make_query("")
249 query.exact_name = false
250 query.arch = "any"
251 local results = search.disk_search(repo, query)
252 local manifest = { repository = {}, modules = {}, commands = {} }
253 manif_core.manifest_cache[repo] = manifest
254
255 print(util.show_table(results, "results"))
256 print(util.show_table(manifest, "manifest"))
257
258 store_results(results, manifest)
259
260 return save_table(repo, "manifest", manifest)
261end
262
255--- Load a manifest file from a local repository and add to the repository 263--- Load a manifest file from a local repository and add to the repository
256-- information with regard to the given name and version. 264-- information with regard to the given name and version.
257-- A file called 'manifest' will be written in the root of the given 265-- A file called 'manifest' will be written in the root of the given
@@ -284,173 +292,10 @@ function update_manifest(name, version, repo)
284 end 292 end
285 293
286 local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} 294 local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}}
287
288 store_results(results, manifest)
289 update_global_lib(repo, manifest)
290 return save_manifest(repo, manifest)
291end
292
293 --- Scan a LuaRocks repository and output a manifest file.
294-- A file called 'manifest' will be written in the root of the given
295-- repository directory.
296-- @param repo A local repository directory.
297-- @return boolean or (nil, string): True if manifest was generated,
298-- or nil and an error message.
299function make_manifest(repo)
300 assert(type(repo) == "string")
301
302 if not fs.is_dir(repo) then
303 return nil, "Cannot access repository at "..repo
304 end
305 295
306 local query = search.make_query("") 296 print("TODO LR2 update manifest")
307 query.exact_name = false
308 query.arch = "any"
309 local results = search.disk_search(repo, query)
310 local manifest = { repository = {}, modules = {}, commands = {} }
311 manif_core.manifest_cache[repo] = manifest
312
313 --print(util.show_table(results, "results"))
314 --print(util.show_table(manifest, "manifest"))
315 297
316 store_results(results, manifest) 298 store_results(results, manifest)
317
318 --print(util.show_table(manifest, "manifest after store"))
319
320 update_global_lib(repo, manifest)
321
322 --print(util.show_table(manifest, "manifest after update"))
323
324 return save_manifest(repo, manifest)
325end
326
327local index_header = [[
328<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
329<html>
330<head>
331<title>Available rocks</title>
332<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
333<style>
334body {
335 background-color: white;
336 font-family: "bitstream vera sans", "verdana", "sans";
337 font-size: 14px;
338}
339a {
340 color: #0000c0;
341 text-decoration: none;
342}
343a:hover {
344 text-decoration: underline;
345}
346td.main {
347 border-style: none;
348}
349blockquote {
350 font-size: 12px;
351}
352td.package {
353 background-color: #f0f0f0;
354 vertical-align: top;
355}
356td.spacer {
357 height: 5px;
358}
359td.version {
360 background-color: #d0d0d0;
361 vertical-align: top;
362 text-align: left;
363 padding: 5px;
364 width: 100px;
365}
366p.manifest {
367 font-size: 8px;
368}
369</style>
370</head>
371<body>
372<h1>Available rocks</h1>
373<p>
374Lua modules avaliable from this location for use with <a href="http://www.luarocks.org">LuaRocks</a>:
375</p>
376<table class="main">
377]]
378
379local index_package_start = [[
380<td class="package">
381<p><a name="$anchor"></a><b>$package</b> - $summary<br/>
382</p><blockquote><p>$detailed<br/>
383<font size="-1"><a href="$original">latest sources</a> $homepage | License: $license</font></p>
384</blockquote></a></td>
385<td class="version">
386]]
387
388local index_package_end = [[
389</td></tr>
390<tr><td colspan="2" class="spacer"></td></tr>
391]]
392
393local index_footer = [[
394</table>
395<p class="manifest">
396<a href="manifest">manifest file</a>
397</p>
398</body>
399</html>
400]]
401
402function make_index(repo)
403 if not fs.is_dir(repo) then
404 return nil, "Cannot access repository at "..repo
405 end
406 local manifest = load_manifest(repo)
407 local out = io.open(dir.path(repo, "index.html"), "w")
408 299
409 out:write(index_header) 300 return save_table(repo, "manifest", manifest)
410 for package, version_list in util.sortedpairs(manifest.repository) do
411 local latest_rockspec = nil
412 local output = index_package_start
413 for version, data in util.sortedpairs(version_list, deps.compare_versions) do
414 local out_versions = {}
415 local arches = 0
416 output = output..version
417 local sep = ':&nbsp;'
418 for _, item in ipairs(data) do
419 output = output .. sep .. '<a href="$url">'..item.arch..'</a>'
420 sep = ',&nbsp;'
421 if item.arch == 'rockspec' then
422 local rs = ("%s-%s.rockspec"):format(package, version)
423 if not latest_rockspec then latest_rockspec = rs end
424 output = output:gsub("$url", rs)
425 else
426 output = output:gsub("$url", ("%s-%s.%s.rock"):format(package, version, item.arch))
427 end
428 end
429 output = output .. '<br/>'
430 output = output:gsub("$na", arches)
431 end
432 output = output .. index_package_end
433 if latest_rockspec then
434 local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec))
435 local vars = {
436 anchor = package,
437 package = rockspec.package,
438 original = rockspec.source.url,
439 summary = rockspec.description.summary or "",
440 detailed = rockspec.description.detailed or "",
441 license = rockspec.description.license or "N/A",
442 homepage = rockspec.description.homepage and ("| <a href="..rockspec.description.homepage..">project homepage</a>") or ""
443 }
444 vars.detailed = vars.detailed:gsub("\n\n", "</p><p>"):gsub("%s+", " ")
445 output = output:gsub("$(%w+)", vars)
446 else
447 output = output:gsub("$anchor", package)
448 output = output:gsub("$package", package)
449 output = output:gsub("$(%w+)", "")
450 end
451 out:write(output)
452 end
453 out:write(index_footer)
454 out:close()
455end 301end
456
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index 4bfdb320..e4dc1794 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -95,11 +95,12 @@ local function pack_binary_rock(name, version)
95 for package, file in pairs(module_data) do 95 for package, file in pairs(module_data) do
96 if package == name.."/"..version then 96 if package == name.."/"..version then
97 local dest 97 local dest
98 if file:match("^"..cfg.lua_modules_dir) then 98 print("TODO LR2 do this based on rock_manifest")
99 local pathname = file:sub(#cfg.lua_modules_dir + 1) 99 if file:match("^"..cfg.deploy_lua_dir) then
100 local pathname = file:sub(#cfg.deploy_lua_dir + 1)
100 dest = dir.path(temp_dir, "lua", dir.dir_name(pathname)) 101 dest = dir.path(temp_dir, "lua", dir.dir_name(pathname))
101 elseif file:match("^"..cfg.bin_modules_dir) then 102 elseif file:match("^"..cfg.deploy_lib_dir) then
102 local pathname = file:sub(#cfg.bin_modules_dir + 1) 103 local pathname = file:sub(#cfg.deploy_lib_dir + 1)
103 dest = dir.path(temp_dir, "lib", dir.dir_name(pathname)) 104 dest = dir.path(temp_dir, "lib", dir.dir_name(pathname))
104 is_binary = true 105 is_binary = true
105 end 106 end
diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua
index 2c7659c1..0a2e9cbb 100644
--- a/src/luarocks/rep.lua
+++ b/src/luarocks/rep.lua
@@ -7,6 +7,7 @@ local path = require("luarocks.path")
7local cfg = require("luarocks.cfg") 7local cfg = require("luarocks.cfg")
8local util = require("luarocks.util") 8local util = require("luarocks.util")
9local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
10local manif = require("luarocks.manif")
10 11
11--- Get all installed versions of a package. 12--- Get all installed versions of a package.
12-- @param name string: a package name. 13-- @param name string: a package name.
@@ -41,19 +42,13 @@ function delete_version(name, version)
41 assert(type(version) == "string") 42 assert(type(version) == "string")
42 43
43 fs.delete(path.install_dir(name, version)) 44 fs.delete(path.install_dir(name, version))
45 print("TODO LR2 remove deployed files based on rock_manifest")
44 if not get_versions(name) then 46 if not get_versions(name) then
45 fs.delete(dir.path(cfg.rocks_dir, name)) 47 fs.delete(dir.path(cfg.rocks_dir, name))
46 end 48 end
47end 49end
48 50
49--- Delete a command-line item from the bin directory. 51--[[
50-- @param command string: name of script
51function delete_bin(command)
52 assert(type(command) == "string")
53
54 fs.delete(dir.path(cfg.scripts_dir, command))
55end
56
57--- Install bin entries in the repository bin dir. 52--- Install bin entries in the repository bin dir.
58-- @param name string: name of package 53-- @param name string: name of package
59-- @param version string: package version in string format 54-- @param version string: package version in string format
@@ -68,9 +63,9 @@ function install_bins(name, version, single_file)
68 63
69 local bindir = path.bin_dir(name, version) 64 local bindir = path.bin_dir(name, version)
70 if fs.exists(bindir) then 65 if fs.exists(bindir) then
71 local ok, err = fs.make_dir(cfg.scripts_dir) 66 local ok, err = fs.make_dir(cfg.deploy_bin_dir)
72 if not ok then 67 if not ok then
73 return nil, "Could not create "..cfg.scripts_dir 68 return nil, "Could not create "..cfg.deploy_bin_dir
74 end 69 end
75 local files = single_file and {single_file} or fs.list_dir(bindir) 70 local files = single_file and {single_file} or fs.list_dir(bindir)
76 for _, file in pairs(files) do 71 for _, file in pairs(files) do
@@ -81,9 +76,9 @@ function install_bins(name, version, single_file)
81 file = io.open(fullname) 76 file = io.open(fullname)
82 end 77 end
83 if match or (file and file:read():match("#!.*lua.*")) then 78 if match or (file and file:read():match("#!.*lua.*")) then
84 ok, err = fs.wrap_script(fullname, cfg.scripts_dir) 79 ok, err = fs.wrap_script(fullname, cfg.deploy_bin_dir)
85 else 80 else
86 ok, err = fs.copy_binary(fullname, cfg.scripts_dir) 81 ok, err = fs.copy_binary(fullname, cfg.deploy_bin_dir)
87 end 82 end
88 if file then file:close() end 83 if file then file:close() end
89 if not ok then 84 if not ok then
@@ -93,6 +88,23 @@ function install_bins(name, version, single_file)
93 end 88 end
94 return true 89 return true
95end 90end
91]]
92
93local function store_package_data(result, name, sub, prefix)
94 assert(type(result) == "table")
95 assert(type(name) == "string")
96 assert(type(sub) == "table" or type(sub) == "string")
97 assert(type(prefix) == "string")
98
99 if type(sub) == "table" then
100 for sname, ssub in pairs(sub) do
101 store_package_data(result, sname, ssub, prefix..name.."/")
102 end
103 elseif type(sub) == "string" then
104 local pathname = prefix..name
105 result[path.path_to_module(pathname)] = pathname
106 end
107end
96 108
97--- Obtain a list of modules within an installed package. 109--- Obtain a list of modules within an installed package.
98-- @param package string: The package name; for example "luasocket" 110-- @param package string: The package name; for example "luasocket"
@@ -107,14 +119,18 @@ function package_modules(package, version)
107 assert(type(version) == "string") 119 assert(type(version) == "string")
108 120
109 local result = {} 121 local result = {}
110 for _, pathdir in pairs{ path.lua_dir, path.lib_dir } do 122 local rock_manifest = manif.load_rock_manifest(package, version)
111 local basedir = pathdir(package, version) 123
112 local files = fs.find(basedir) 124 print(pkg, version, util.show_table(rock_manifest))
113 for _, file in ipairs(files) do 125
114 local name = path.path_to_module(file) 126 if rock_manifest.lib then
115 if name then 127 for name,sub in pairs(rock_manifest.lib) do
116 result[name] = dir.path(basedir, file) 128 store_package_data(result, name, sub, "", "")
117 end 129 end
130 end
131 if rock_manifest.lua then
132 for name,sub in pairs(rock_manifest.lua) do
133 store_package_data(result, name, sub, "", "")
118 end 134 end
119 end 135 end
120 return result 136 return result
@@ -133,26 +149,30 @@ function package_commands(package, version)
133 assert(type(version) == "string") 149 assert(type(version) == "string")
134 150
135 local result = {} 151 local result = {}
136 local bindir = path.bin_dir(package, version) 152 local rock_manifest = manif.load_rock_manifest(package, version)
137 local bins = fs.find(bindir) 153 if rock_manifest.bin then
138 for _, file in ipairs(bins) do 154 for name,sub in pairs(rock_manifest.bin) do
139 if file then 155 store_package_data(result, name, sub, "", "")
140 result[file] = dir.path(bindir, file)
141 end 156 end
142 end 157 end
143 return result 158 return result
144end 159end
145 160
161
146--- Check if a rock contains binary executables. 162--- Check if a rock contains binary executables.
147-- @param name string: name of an installed rock 163-- @param name string: name of an installed rock
148-- @param version string: version of an installed rock 164-- @param version string: version of an installed rock
149-- @return boolean: returns true if rock contains platform-specific 165-- @return boolean: returns true if rock contains platform-specific
150-- binary executables, or false if it is a pure-Lua rock. 166-- binary executables, or false if it is a pure-Lua rock.
151function has_binaries(name, version) 167function has_binaries(name, version)
152 local bin_dir = path.bin_dir(name, version) 168 assert(type(name) == "string")
153 if fs.exists(bin_dir) then 169 assert(type(version) == "string")
154 for _, name in pairs(fs.find(bin_dir)) do 170
155 if fs.is_actual_binary(dir.path(bin_dir, name)) then 171 local rock_manifest = manif.load_rock_manifest(name, version)
172 if rock_manifest.bin then
173 for name, md5 in pairs(rock_manifest.bin) do
174 -- TODO verify that it is the same file. If it isn't, find the actual command.
175 if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, name)) then
156 return true 176 return true
157 end 177 end
158 end 178 end
@@ -161,6 +181,9 @@ function has_binaries(name, version)
161end 181end
162 182
163function run_hook(rockspec, hook_name) 183function run_hook(rockspec, hook_name)
184 assert(type(rockspec) == "table")
185 assert(type(hook_name) == "string")
186
164 local hooks = rockspec.hooks 187 local hooks = rockspec.hooks
165 if not hooks then 188 if not hooks then
166 return true 189 return true
@@ -178,3 +201,70 @@ function run_hook(rockspec, hook_name)
178 end 201 end
179 return true 202 return true
180end 203end
204
205local function deploy_file_tree(file_tree, source_dir, deploy_dir, move_fn)
206 assert(type(file_tree) == "table")
207 assert(type(source_dir) == "string")
208 assert(type(deploy_dir) == "string")
209 assert(type(move_fn) == "function" or not move_fn)
210
211 print("TODO LR2 actually fs.move")
212 if not move_fn then move_fn = fs.copy end
213
214 local ok, err = fs.make_dir(deploy_dir)
215 if not ok then
216 return nil, "Could not create "..deploy_dir
217 end
218 for file, sub in pairs(file_tree) do
219 if type(sub) == "table" then
220 ok, err = deploy_file_tree(sub, dir.path(source_dir, file), dir.path(deploy_dir, file))
221 if not ok then return nil, err end
222 else
223 local target = dir.path(deploy_dir, file)
224 if fs.exists(target) then
225 print("TODO LR2 make_way_for_new_version(target)")
226 end
227 local source = dir.path(source_dir, file)
228 ok, err = move_fn(source, deploy_dir)
229 if not ok then return nil, err end
230 end
231 end
232end
233
234local function install_binary(source, target)
235 assert(type(source) == "string")
236 assert(type(target) == "string")
237
238 local match = source:match("%.lua$")
239 local file, ok, err
240 if not match then
241 file = io.open(source)
242 end
243 if match or (file and file:read():match("^#!.*lua.*")) then
244 ok, err = fs.wrap_script(source, target)
245 else
246 ok, err = fs.copy_binary(source, target)
247 end
248 if file then file:close() end
249 return ok, err
250end
251
252function deploy_files(name, version)
253 assert(type(name) == "string")
254 assert(type(version) == "string")
255
256 local rock_manifest = manif.load_rock_manifest(name, version)
257
258 if rock_manifest.bin then
259 local ok, err = deploy_file_tree(rock_manifest.bin, path_bin_dir(name, version), cfg.deploy_bin_dir, install_binary)
260 if err then return nil, err end
261 end
262 if rock_manifest.lua then
263 local ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir(name, version), cfg.deploy_lua_dir)
264 if err then return nil, err end
265 end
266 if rock_manifest.lib then
267 local ok, err = deploy_file_tree(rock_manifest.lib, path.lib_dir(name, version), cfg.deploy_lib_dir)
268 if err then return nil, err end
269 end
270end