From 08df24ac4f1ac5ef3b5bb59629e65e4b90b2a51d Mon Sep 17 00:00:00 2001 From: hisham Date: Thu, 23 Apr 2009 18:56:38 +0000 Subject: LuaRocks can now use itself to load its own dependencies! git-svn-id: http://luarocks.org/svn/luarocks/trunk@13 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/bin/luarocks | 2 +- src/luarocks.lua | 13 ++++++------- src/luarocks/command_line.lua | 2 +- src/luarocks/deps.lua | 9 +++++---- src/luarocks/dir.lua | 16 ++++++++++++++++ src/luarocks/fetch.lua | 6 +++--- src/luarocks/fs/lua.lua | 19 ------------------- src/luarocks/fs/unix.lua | 19 ------------------- src/luarocks/manif.lua | 2 +- src/luarocks/path.lua | 1 + src/luarocks/require.lua | 6 +++--- src/luarocks/search.lua | 6 ++++-- src/luarocks/validate.lua | 2 +- 13 files changed, 42 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/bin/luarocks b/src/bin/luarocks index 8812ecc8..ae0c2b42 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -1,4 +1,4 @@ -#!/usr/bin/env lua +#!/usr/bin/lua local command_line = require("luarocks.command_line") diff --git a/src/luarocks.lua b/src/luarocks.lua index fad62e07..aef93363 100644 --- a/src/luarocks.lua +++ b/src/luarocks.lua @@ -61,17 +61,16 @@ local function add_context(name, version, manifest) for _, dep in ipairs(pkgdeps) do local package, constraints = dep.name, dep.constraints - for _, tree in pairs(rocks_trees) do do + for _, tree in pairs(rocks_trees) do local entries = tree.manifest.repository[package] if entries then - break -- continue for - end - for version, packages in pairs(entries) do - if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then - add_context(package, version, tree.manifest) + for version, packages in pairs(entries) do + if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then + add_context(package, version, tree.manifest) + end end end - end end + end end end diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 9688343e..9368e8ad 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -76,7 +76,7 @@ function run_command(...) if flags["from"] == true then die("Argument error: use --from=") end - local protocol, path = fs.split_url(flags["from"]) + local protocol, path = dir.split_url(flags["from"]) table.insert(cfg.rocks_servers, 1, protocol.."://"..path) end diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index d7d6e103..7ad0b23e 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -13,12 +13,8 @@ -- insights on what these criteria are. module("luarocks.deps", package.seeall) -local rep = require("luarocks.rep") -local search = require("luarocks.search") -local install = require("luarocks.install") local cfg = require("luarocks.cfg") local manif_core = require("luarocks.manif_core") -local fetch = require("luarocks.fetch") local path = require("luarocks.path") local dir = require("luarocks.dir") @@ -404,6 +400,9 @@ end -- error code. function fulfill_dependencies(rockspec) + local search = require("luarocks.search") + local install = require("luarocks.install") + if rockspec.supported_platforms then if not platforms_set then platforms_set = values_set(cfg.platforms) @@ -588,6 +587,8 @@ function scan_deps(results, missing, manifest, name, version) assert(type(name) == "string") assert(type(version) == "string") + local fetch = require("luarocks.fetch") + local err if results[name] then return results, missing diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index 5cb3b846..38bb49d2 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -45,3 +45,19 @@ function path(...) end return table.concat(items, "/") end + +--- Split protocol and path from an URL or local pathname. +-- URLs should be in the "protocol://path" format. +-- For local pathnames, "file" is returned as the protocol. +-- @param url string: an URL or a local pathname. +-- @return string, string: the protocol, and the absolute pathname without the protocol. +function split_url(url) + assert(type(url) == "string") + + local protocol, pathname = url:match("^([^:]*)://(.*)") + if not protocol then + protocol = "file" + pathname = url + end + return protocol, pathname +end diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 5b2d20cb..57e641cf 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -26,7 +26,7 @@ function fetch_url(url, filename) assert(type(url) == "string") assert(type(filename) == "string" or not filename) - local protocol, pathname = fs.split_url(url) + local protocol, pathname = dir.split_url(url) if protocol == "file" then return fs.absolute_name(pathname) elseif protocol == "http" or protocol == "ftp" or protocol == "https" then @@ -57,7 +57,7 @@ function fetch_url_at_temp_dir(url, tmpname, filename) assert(type(filename) == "string" or not filename) filename = filename or dir.base_name(url) - local protocol, pathname = fs.split_url(url) + local protocol, pathname = dir.split_url(url) if protocol == "file" then return pathname, dir.dir_name(pathname) else @@ -151,7 +151,7 @@ function load_local_rockspec(filename) return nil, "Expected filename in format 'name-version-revision.rockspec'." end - local protocol, pathname = fs.split_url(rockspec.source.url) + local protocol, pathname = dir.split_url(rockspec.source.url) if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) end diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 9f9a4b63..80a4c2fd 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -74,25 +74,6 @@ function make_temp_dir(name) end end ---- Split protocol and path from an URL or local pathname. --- URLs should be in the "protocol://path" format. --- For local pathnames, "file" is returned as the protocol. --- @param url string: an URL or a local pathname. --- @return string, string: the protocol, and the absolute pathname without the protocol. -function split_url(url) - assert(type(url) == "string") - - local protocol, pathname = url:match("^([^:]*)://(.*)") - if not protocol then - protocol = "file" - pathname = url - end - if protocol == "file" then - pathname = fs.absolute_name(pathname) - end - return protocol, pathname -end - --- Run the given command, quoting its arguments. -- The command is executed in the current directory in the dir stack. -- @param command string: The command to be executed. No quoting/escaping diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index dba152ef..0e91eea0 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -31,25 +31,6 @@ function absolute_name(pathname, relative_to) end end ---- Split protocol and path from an URL or local pathname. --- URLs should be in the "protocol://path" format. --- For local pathnames, "file" is returned as the protocol. --- @param url string: an URL or a local pathname. --- @return string, string: the protocol, and the absolute pathname without the protocol. -function split_url(url) - assert(type(url) == "string") - - local protocol, pathname = url:match("^([^:]*)://(.*)") - if not protocol then - protocol = "file" - pathname = url - end - if protocol == "file" then - pathname = fs.absolute_name(pathname) - end - return protocol, pathname -end - --- Create a wrapper to make a script executable from the command-line. -- @param file string: Pathname of script to be made executable. -- @param dest string: Directory where to put the wrapper. diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 3e5790ae..f9c53d4f 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -26,7 +26,7 @@ function load_manifest(repo_url) return manif_core.manifest_cache[repo_url] end - local protocol, pathname = fs.split_url(repo_url) + local protocol, pathname = dir.split_url(repo_url) if protocol == "file" then pathname = dir.path(pathname, "manifest") else diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index ae9c7fae..c9085431 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -222,3 +222,4 @@ function configure_paths(rockspec) vars.DOCDIR = doc_dir(name, version) rockspec.variables = vars end + diff --git a/src/luarocks/require.lua b/src/luarocks/require.lua index 21d6511a..7d083fca 100644 --- a/src/luarocks/require.lua +++ b/src/luarocks/require.lua @@ -13,7 +13,7 @@ local package, assert, ipairs, pairs, os, print, table, type, next = module("luarocks.require") local path = plain_require("luarocks.path") -local manif = plain_require("luarocks.manif_core") +local manif_core = plain_require("luarocks.manif_core") local deps = plain_require("luarocks.deps") local cfg = plain_require("luarocks.cfg") @@ -29,7 +29,7 @@ local function load_rocks_trees() local trees = {} for _, tree in pairs(cfg.rocks_trees) do local rocks_dir = tree .. "/rocks/" - local manifest, err = manif.load_local_manifest(rocks_dir) + local manifest, err = manif_core.load_local_manifest(rocks_dir) if manifest then any_ok = true table.insert(trees, {rocks_dir=rocks_dir, manifest=manifest}) @@ -115,7 +115,7 @@ function set_context(name, version) break end else - local versions = manif.get_versions(name, tree.manifest) + local versions = manif_core.get_versions(name, tree.manifest) for _, version in ipairs(versions) do table.insert(vtables, {version = deps.parse_version(version), manifest = tree.manifest}) end diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index eae3809f..20aea970 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -3,7 +3,6 @@ -- Queries LuaRocks servers. module("luarocks.search", package.seeall) -local fs = require("luarocks.fs") local dir = require("luarocks.dir") local path = require("luarocks.path") local manif = require("luarocks.manif") @@ -129,6 +128,9 @@ function disk_search(repo, query, results) assert(type(repo) == "string") assert(type(query) == "table") assert(type(results) == "table" or not results) + + local fs = require("luarocks.fs") + if not results then results = {} end @@ -194,7 +196,7 @@ local function search_repos(query) local results = {} for _, repo in ipairs(cfg.rocks_servers) do - local protocol, pathname = fs.split_url(repo) + local protocol, pathname = dir.split_url(repo) if protocol == "file" then repo = pathname end diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua index 1bf001c7..36163afe 100644 --- a/src/luarocks/validate.lua +++ b/src/luarocks/validate.lua @@ -15,7 +15,7 @@ help = [[ ]] local function save_settings(repo) - local protocol, path = fs.split_url(repo) + local protocol, path = dir.split_url(repo) table.insert(cfg.rocks_servers, 1, protocol.."://"..path) return { root_dir = cfg.root_dir, -- cgit v1.2.3-55-g6feb