From f559b586ed3b8b3bc3f42cf24babd75c907402d5 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 20 Jun 2013 00:50:17 -0300 Subject: 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. --- src/luarocks/add.lua | 11 ++++++-- src/luarocks/manif.lua | 75 +++++++++++++++++++++++++++++++++++++++++-------- src/luarocks/unpack.lua | 4 +-- 3 files changed, 73 insertions(+), 17 deletions(-) (limited to 'src') 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) fs.change_dir(local_cache) util.printout("Updating manifest...") - manif.make_manifest(local_cache, "one") + manif.make_manifest(local_cache, "one", {"5.1", "5.2"}) util.printout("Updating index.html...") index.make_index(local_cache) @@ -76,6 +76,11 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) login_url = login_url .. "/" end + table.insert(files, "index.html") + table.insert(files, "manifest") + table.insert(files, "manifest-5.1") + table.insert(files, "manifest-5.2") + -- TODO abstract away explicit 'curl' call local cmd @@ -84,9 +89,9 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) cmd = cfg.variables.RSYNC.." --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" elseif upload_server and upload_server.sftp then local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") - cmd = cfg.variables.SCP.." manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 + cmd = cfg.variables.SCP.." "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 else - cmd = cfg.variables.CURL.." "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url + cmd = cfg.variables.CURL.." "..login_info.." -T '{"..table.concat(files, ",").."}' "..login_url end 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) save_table(install_dir, "rock_manifest", rock_manifest ) end +local function fetch_manifest_from(repo_url, filename) + local url = dir.path(repo_url, filename) + local name = repo_url:gsub("[/:]","_") + local file, err, errcode = fetch.fetch_url_at_temp_dir(url, "luarocks-manifest-"..name) + if not file then + return nil, "Failed fetching manifest for "..repo_url..(err and " - "..err or ""), errcode + end + return file +end + --- Load a local or remote manifest describing a repository. -- All functions that use manifest tables assume they were obtained -- through either this function or load_local_manifest. @@ -94,15 +104,21 @@ function load_manifest(repo_url) return manif_core.manifest_cache[repo_url] end + local vmanifest = "manifest-"..cfg.lua_version + local protocol, pathname = dir.split_url(repo_url) if protocol == "file" then - pathname = dir.path(pathname, "manifest") + pathname = dir.path(pathname, vmanifest) + if not fs.exists(pathname) then + pathname = dir.path(pathname, "manifest") + end else - local url = dir.path(repo_url, "manifest") - local name = repo_url:gsub("[/:]","_") - local file, err, errcode = fetch.fetch_url_at_temp_dir(url, "luarocks-manifest-"..name) + local file, err = fetch_manifest_from(repo_url, vmanifest) if not file then - return nil, "Failed fetching manifest for "..repo_url..(err and " - "..err or ""), errcode + file, err = fetch_manifest_from(repo_url, "manifest") + end + if not file then + return nil, err end pathname = file end @@ -188,11 +204,16 @@ end -- @param deps_mode string: Dependency mode: "one" for the current default tree, -- "all" for all trees, "order" for all trees with priority >= the current default, -- "none" for no trees. -local function update_dependencies(manifest, deps_mode) +-- @param repodir string: directory of repository being scanned +-- @param filter_lua string or nil: filter by Lua version +local function update_dependencies(manifest, deps_mode, repodir, filter_lua) assert(type(manifest) == "table") assert(type(deps_mode) == "string") - + + local lua_version = filter_lua and deps.parse_version(filter_lua) + for pkg, versions in pairs(manifest.repository) do + local to_remove = {} for version, repositories in pairs(versions) do local current = pkg.." "..version for _, repo in ipairs(repositories) do @@ -209,9 +230,27 @@ local function update_dependencies(manifest, deps_mode) end end end + elseif filter_lua and repo.arch == "rockspec" then + local rockspec = fetch.load_local_rockspec(dir.path(repodir, pkg.."-"..version..".rockspec")) + for _, dep in ipairs(rockspec.dependencies) do + if dep.name == "lua" then + if not deps.match_constraints(lua_version, dep.constraints) then + table.insert(to_remove, version) + end + break + end + end end end end + if next(to_remove) then + for _, incompat in ipairs(to_remove) do + manifest.repository[pkg][incompat] = nil + end + if not next(manifest.repository[pkg]) then + manifest.repository[pkg] = nil + end + end end end @@ -222,8 +261,9 @@ end -- @param deps_mode string: Dependency mode: "one" for the current default tree, -- "all" for all trees, "order" for all trees with priority >= the current default, -- "none" for no trees. +-- @param repo string: directory of repository -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. -local function store_results(results, manifest, deps_mode) +local function store_results(results, manifest, deps_mode, repo, filter_lua) assert(type(results) == "table") assert(type(manifest) == "table") assert(type(deps_mode) == "string") @@ -249,7 +289,7 @@ local function store_results(results, manifest, deps_mode) end manifest.repository[name] = pkgtable end - update_dependencies(manifest, deps_mode) + update_dependencies(manifest, deps_mode, repo, filter_lua) sort_package_matching_table(manifest.modules) sort_package_matching_table(manifest.commands) return true @@ -262,9 +302,11 @@ end -- @param deps_mode string: Dependency mode: "one" for the current default tree, -- "all" for all trees, "order" for all trees with priority >= the current default, -- "none" for the default dependency mode from the configuration. +-- @param versioned nil or array of string: a table of Lua versions, if versioned +-- versions of the manifest should be created. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. -function make_manifest(repo, deps_mode) +function make_manifest(repo, deps_mode, versioned) assert(type(repo) == "string") assert(type(deps_mode) == "string") @@ -279,11 +321,20 @@ function make_manifest(repo, deps_mode) query.arch = "any" local results = search.disk_search(repo, query) local manifest = { repository = {}, modules = {}, commands = {} } + manif_core.manifest_cache[repo] = manifest - local ok, err = store_results(results, manifest, deps_mode) + local ok, err = store_results(results, manifest, deps_mode, repo) if not ok then return nil, err end + if versioned then + for _, ver in ipairs(versioned) do + local vmanifest = { repository = {}, modules = {}, commands = {} } + local ok, err = store_results(results, vmanifest, deps_mode, repo, ver) + save_table(repo, "manifest-"..ver, vmanifest) + end + end + return save_table(repo, "manifest", manifest) end @@ -325,7 +376,7 @@ function update_manifest(name, version, repo, deps_mode) local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} - local ok, err = store_results(results, manifest, deps_mode) + local ok, err = store_results(results, manifest, deps_mode, repo) if not ok then return nil, err end 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. local function unpack_rockspec(rockspec_file, dir_name) assert(type(rockspec_file) == "string") assert(type(dir_name) == "string") - + local rockspec, err = fetch.load_rockspec(rockspec_file) if not rockspec then return nil, "Failed loading rockspec "..rockspec_file..": "..err @@ -52,7 +52,7 @@ end local function unpack_rock(rock_file, dir_name, kind) assert(type(rock_file) == "string") assert(type(dir_name) == "string") - + local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) if not ok then return nil, "Failed unzipping rock "..rock_file, errcode -- cgit v1.2.3-55-g6feb