diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2013-06-20 00:50:17 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-06-20 00:50:17 -0300 |
| commit | f559b586ed3b8b3bc3f42cf24babd75c907402d5 (patch) | |
| tree | 1570cd07ace9a56be0b168cabf996588099a740d | |
| parent | 15922c3632092d08933bc75aeacd772a4621cf89 (diff) | |
| download | luarocks-f559b586ed3b8b3bc3f42cf24babd75c907402d5.tar.gz luarocks-f559b586ed3b8b3bc3f42cf24babd75c907402d5.tar.bz2 luarocks-f559b586ed3b8b3bc3f42cf24babd75c907402d5.zip | |
Add versioned manifest files for Lua 5.1 and 5.2. Make sure LuaRocks only finds rocks according to the Lua version it is using.
| -rw-r--r-- | src/luarocks/add.lua | 11 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 75 | ||||
| -rw-r--r-- | src/luarocks/unpack.lua | 4 |
3 files changed, 73 insertions, 17 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index 30db9a48..33b98f5c 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua | |||
| @@ -65,7 +65,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) | |||
| 65 | fs.change_dir(local_cache) | 65 | fs.change_dir(local_cache) |
| 66 | 66 | ||
| 67 | util.printout("Updating manifest...") | 67 | util.printout("Updating manifest...") |
| 68 | manif.make_manifest(local_cache, "one") | 68 | manif.make_manifest(local_cache, "one", {"5.1", "5.2"}) |
| 69 | util.printout("Updating index.html...") | 69 | util.printout("Updating index.html...") |
| 70 | index.make_index(local_cache) | 70 | index.make_index(local_cache) |
| 71 | 71 | ||
| @@ -76,6 +76,11 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) | |||
| 76 | login_url = login_url .. "/" | 76 | login_url = login_url .. "/" |
| 77 | end | 77 | end |
| 78 | 78 | ||
| 79 | table.insert(files, "index.html") | ||
| 80 | table.insert(files, "manifest") | ||
| 81 | table.insert(files, "manifest-5.1") | ||
| 82 | table.insert(files, "manifest-5.2") | ||
| 83 | |||
| 79 | -- TODO abstract away explicit 'curl' call | 84 | -- TODO abstract away explicit 'curl' call |
| 80 | 85 | ||
| 81 | local cmd | 86 | local cmd |
| @@ -84,9 +89,9 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) | |||
| 84 | cmd = cfg.variables.RSYNC.." --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" | 89 | cmd = cfg.variables.RSYNC.." --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" |
| 85 | elseif upload_server and upload_server.sftp then | 90 | elseif upload_server and upload_server.sftp then |
| 86 | local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") | 91 | local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") |
| 87 | cmd = cfg.variables.SCP.." manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 | 92 | cmd = cfg.variables.SCP.." "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 |
| 88 | else | 93 | else |
| 89 | cmd = cfg.variables.CURL.." "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url | 94 | cmd = cfg.variables.CURL.." "..login_info.." -T '{"..table.concat(files, ",").."}' "..login_url |
| 90 | end | 95 | end |
| 91 | 96 | ||
| 92 | util.printout(cmd) | 97 | util.printout(cmd) |
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 0ce539e9..bdfdd9ae 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -81,6 +81,16 @@ function make_rock_manifest(name, version) | |||
| 81 | save_table(install_dir, "rock_manifest", rock_manifest ) | 81 | save_table(install_dir, "rock_manifest", rock_manifest ) |
| 82 | end | 82 | end |
| 83 | 83 | ||
| 84 | local function fetch_manifest_from(repo_url, filename) | ||
| 85 | local url = dir.path(repo_url, filename) | ||
| 86 | local name = repo_url:gsub("[/:]","_") | ||
| 87 | local file, err, errcode = fetch.fetch_url_at_temp_dir(url, "luarocks-manifest-"..name) | ||
| 88 | if not file then | ||
| 89 | return nil, "Failed fetching manifest for "..repo_url..(err and " - "..err or ""), errcode | ||
| 90 | end | ||
| 91 | return file | ||
| 92 | end | ||
| 93 | |||
| 84 | --- Load a local or remote manifest describing a repository. | 94 | --- Load a local or remote manifest describing a repository. |
| 85 | -- All functions that use manifest tables assume they were obtained | 95 | -- All functions that use manifest tables assume they were obtained |
| 86 | -- through either this function or load_local_manifest. | 96 | -- through either this function or load_local_manifest. |
| @@ -94,15 +104,21 @@ function load_manifest(repo_url) | |||
| 94 | return manif_core.manifest_cache[repo_url] | 104 | return manif_core.manifest_cache[repo_url] |
| 95 | end | 105 | end |
| 96 | 106 | ||
| 107 | local vmanifest = "manifest-"..cfg.lua_version | ||
| 108 | |||
| 97 | local protocol, pathname = dir.split_url(repo_url) | 109 | local protocol, pathname = dir.split_url(repo_url) |
| 98 | if protocol == "file" then | 110 | if protocol == "file" then |
| 99 | pathname = dir.path(pathname, "manifest") | 111 | pathname = dir.path(pathname, vmanifest) |
| 112 | if not fs.exists(pathname) then | ||
| 113 | pathname = dir.path(pathname, "manifest") | ||
| 114 | end | ||
| 100 | else | 115 | else |
| 101 | local url = dir.path(repo_url, "manifest") | 116 | local file, err = fetch_manifest_from(repo_url, vmanifest) |
| 102 | local name = repo_url:gsub("[/:]","_") | ||
| 103 | local file, err, errcode = fetch.fetch_url_at_temp_dir(url, "luarocks-manifest-"..name) | ||
| 104 | if not file then | 117 | if not file then |
| 105 | return nil, "Failed fetching manifest for "..repo_url..(err and " - "..err or ""), errcode | 118 | file, err = fetch_manifest_from(repo_url, "manifest") |
| 119 | end | ||
| 120 | if not file then | ||
| 121 | return nil, err | ||
| 106 | end | 122 | end |
| 107 | pathname = file | 123 | pathname = file |
| 108 | end | 124 | end |
| @@ -188,11 +204,16 @@ end | |||
| 188 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 204 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
| 189 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 205 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
| 190 | -- "none" for no trees. | 206 | -- "none" for no trees. |
| 191 | local function update_dependencies(manifest, deps_mode) | 207 | -- @param repodir string: directory of repository being scanned |
| 208 | -- @param filter_lua string or nil: filter by Lua version | ||
| 209 | local function update_dependencies(manifest, deps_mode, repodir, filter_lua) | ||
| 192 | assert(type(manifest) == "table") | 210 | assert(type(manifest) == "table") |
| 193 | assert(type(deps_mode) == "string") | 211 | assert(type(deps_mode) == "string") |
| 194 | 212 | ||
| 213 | local lua_version = filter_lua and deps.parse_version(filter_lua) | ||
| 214 | |||
| 195 | for pkg, versions in pairs(manifest.repository) do | 215 | for pkg, versions in pairs(manifest.repository) do |
| 216 | local to_remove = {} | ||
| 196 | for version, repositories in pairs(versions) do | 217 | for version, repositories in pairs(versions) do |
| 197 | local current = pkg.." "..version | 218 | local current = pkg.." "..version |
| 198 | for _, repo in ipairs(repositories) do | 219 | for _, repo in ipairs(repositories) do |
| @@ -209,9 +230,27 @@ local function update_dependencies(manifest, deps_mode) | |||
| 209 | end | 230 | end |
| 210 | end | 231 | end |
| 211 | end | 232 | end |
| 233 | elseif filter_lua and repo.arch == "rockspec" then | ||
| 234 | local rockspec = fetch.load_local_rockspec(dir.path(repodir, pkg.."-"..version..".rockspec")) | ||
| 235 | for _, dep in ipairs(rockspec.dependencies) do | ||
| 236 | if dep.name == "lua" then | ||
| 237 | if not deps.match_constraints(lua_version, dep.constraints) then | ||
| 238 | table.insert(to_remove, version) | ||
| 239 | end | ||
| 240 | break | ||
| 241 | end | ||
| 242 | end | ||
| 212 | end | 243 | end |
| 213 | end | 244 | end |
| 214 | end | 245 | end |
| 246 | if next(to_remove) then | ||
| 247 | for _, incompat in ipairs(to_remove) do | ||
| 248 | manifest.repository[pkg][incompat] = nil | ||
| 249 | end | ||
| 250 | if not next(manifest.repository[pkg]) then | ||
| 251 | manifest.repository[pkg] = nil | ||
| 252 | end | ||
| 253 | end | ||
| 215 | end | 254 | end |
| 216 | end | 255 | end |
| 217 | 256 | ||
| @@ -222,8 +261,9 @@ end | |||
| 222 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 261 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
| 223 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 262 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
| 224 | -- "none" for no trees. | 263 | -- "none" for no trees. |
| 264 | -- @param repo string: directory of repository | ||
| 225 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. | 265 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. |
| 226 | local function store_results(results, manifest, deps_mode) | 266 | local function store_results(results, manifest, deps_mode, repo, filter_lua) |
| 227 | assert(type(results) == "table") | 267 | assert(type(results) == "table") |
| 228 | assert(type(manifest) == "table") | 268 | assert(type(manifest) == "table") |
| 229 | assert(type(deps_mode) == "string") | 269 | assert(type(deps_mode) == "string") |
| @@ -249,7 +289,7 @@ local function store_results(results, manifest, deps_mode) | |||
| 249 | end | 289 | end |
| 250 | manifest.repository[name] = pkgtable | 290 | manifest.repository[name] = pkgtable |
| 251 | end | 291 | end |
| 252 | update_dependencies(manifest, deps_mode) | 292 | update_dependencies(manifest, deps_mode, repo, filter_lua) |
| 253 | sort_package_matching_table(manifest.modules) | 293 | sort_package_matching_table(manifest.modules) |
| 254 | sort_package_matching_table(manifest.commands) | 294 | sort_package_matching_table(manifest.commands) |
| 255 | return true | 295 | return true |
| @@ -262,9 +302,11 @@ end | |||
| 262 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 302 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
| 263 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 303 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
| 264 | -- "none" for the default dependency mode from the configuration. | 304 | -- "none" for the default dependency mode from the configuration. |
| 305 | -- @param versioned nil or array of string: a table of Lua versions, if versioned | ||
| 306 | -- versions of the manifest should be created. | ||
| 265 | -- @return boolean or (nil, string): True if manifest was generated, | 307 | -- @return boolean or (nil, string): True if manifest was generated, |
| 266 | -- or nil and an error message. | 308 | -- or nil and an error message. |
| 267 | function make_manifest(repo, deps_mode) | 309 | function make_manifest(repo, deps_mode, versioned) |
| 268 | assert(type(repo) == "string") | 310 | assert(type(repo) == "string") |
| 269 | assert(type(deps_mode) == "string") | 311 | assert(type(deps_mode) == "string") |
| 270 | 312 | ||
| @@ -279,11 +321,20 @@ function make_manifest(repo, deps_mode) | |||
| 279 | query.arch = "any" | 321 | query.arch = "any" |
| 280 | local results = search.disk_search(repo, query) | 322 | local results = search.disk_search(repo, query) |
| 281 | local manifest = { repository = {}, modules = {}, commands = {} } | 323 | local manifest = { repository = {}, modules = {}, commands = {} } |
| 324 | |||
| 282 | manif_core.manifest_cache[repo] = manifest | 325 | manif_core.manifest_cache[repo] = manifest |
| 283 | 326 | ||
| 284 | local ok, err = store_results(results, manifest, deps_mode) | 327 | local ok, err = store_results(results, manifest, deps_mode, repo) |
| 285 | if not ok then return nil, err end | 328 | if not ok then return nil, err end |
| 286 | 329 | ||
| 330 | if versioned then | ||
| 331 | for _, ver in ipairs(versioned) do | ||
| 332 | local vmanifest = { repository = {}, modules = {}, commands = {} } | ||
| 333 | local ok, err = store_results(results, vmanifest, deps_mode, repo, ver) | ||
| 334 | save_table(repo, "manifest-"..ver, vmanifest) | ||
| 335 | end | ||
| 336 | end | ||
| 337 | |||
| 287 | return save_table(repo, "manifest", manifest) | 338 | return save_table(repo, "manifest", manifest) |
| 288 | end | 339 | end |
| 289 | 340 | ||
| @@ -325,7 +376,7 @@ function update_manifest(name, version, repo, deps_mode) | |||
| 325 | 376 | ||
| 326 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} | 377 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} |
| 327 | 378 | ||
| 328 | local ok, err = store_results(results, manifest, deps_mode) | 379 | local ok, err = store_results(results, manifest, deps_mode, repo) |
| 329 | if not ok then return nil, err end | 380 | if not ok then return nil, err end |
| 330 | 381 | ||
| 331 | return save_table(repo, "manifest", manifest) | 382 | return save_table(repo, "manifest", manifest) |
diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua index 1db66bbb..67153812 100644 --- a/src/luarocks/unpack.lua +++ b/src/luarocks/unpack.lua | |||
| @@ -26,7 +26,7 @@ In the latter case, the app version may be given as a second argument. | |||
| 26 | local function unpack_rockspec(rockspec_file, dir_name) | 26 | local function unpack_rockspec(rockspec_file, dir_name) |
| 27 | assert(type(rockspec_file) == "string") | 27 | assert(type(rockspec_file) == "string") |
| 28 | assert(type(dir_name) == "string") | 28 | assert(type(dir_name) == "string") |
| 29 | 29 | ||
| 30 | local rockspec, err = fetch.load_rockspec(rockspec_file) | 30 | local rockspec, err = fetch.load_rockspec(rockspec_file) |
| 31 | if not rockspec then | 31 | if not rockspec then |
| 32 | return nil, "Failed loading rockspec "..rockspec_file..": "..err | 32 | return nil, "Failed loading rockspec "..rockspec_file..": "..err |
| @@ -52,7 +52,7 @@ end | |||
| 52 | local function unpack_rock(rock_file, dir_name, kind) | 52 | local function unpack_rock(rock_file, dir_name, kind) |
| 53 | assert(type(rock_file) == "string") | 53 | assert(type(rock_file) == "string") |
| 54 | assert(type(dir_name) == "string") | 54 | assert(type(dir_name) == "string") |
| 55 | 55 | ||
| 56 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) | 56 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) |
| 57 | if not ok then | 57 | if not ok then |
| 58 | return nil, "Failed unzipping rock "..rock_file, errcode | 58 | return nil, "Failed unzipping rock "..rock_file, errcode |
