From 3f6df3b29d5e7b4e4bf7d8b9dbe51bd5e2febd7f Mon Sep 17 00:00:00 2001 From: sylvanaar Date: Sat, 20 Aug 2011 13:43:45 -0400 Subject: added an hg scc provider --- src/luarocks/fetch.lua | 8 ++++--- src/luarocks/fetch/hg.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/luarocks/type_check.lua | 1 + 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/luarocks/fetch/hg.lua (limited to 'src') diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 2ea2c906..98e10609 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -156,7 +156,8 @@ function load_local_rockspec(filename) end local protocol, pathname = dir.split_url(rockspec.source.url) - if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then + local vccs = rockspec.source.vccs + if vccs ~= nil and ( 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 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname @@ -293,11 +294,12 @@ function fetch_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local protocol = rockspec.source.protocol + local vccs = rockspec.source.protocol local ok, proto - if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then + if vccs == nil or ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then proto = require("luarocks.fetch") else - ok, proto = pcall(require, "luarocks.fetch."..protocol) + ok, proto = pcall(require, "luarocks.fetch."..vccs or protocol) if not ok then return nil, "Unknown protocol "..protocol end diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua new file mode 100644 index 00000000..885060a2 --- /dev/null +++ b/src/luarocks/fetch/hg.lua @@ -0,0 +1,52 @@ + +--- Fetch back-end for retrieving sources from HG. +module("luarocks.fetch.hg", package.seeall) + +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") +local util = require("luarocks.util") + +--- Download sources for building a rock, using hg. +-- @param rockspec table: The rockspec table +-- @param extract boolean: Unused in this module (required for API purposes.) +-- @param dest_dir string or nil: If set, will extract to the given directory. +-- @return (string, string) or (nil, string): The absolute pathname of +-- the fetched source tarball and the temporary directory created to +-- store it; or nil and an error message. +function get_sources(rockspec, extract, dest_dir) + assert(type(rockspec) == "table") + assert(type(dest_dir) == "string" or not dest_dir) + + local hg_cmd = rockspec.variables.HG + local name_version = rockspec.name .. "-" .. rockspec.version + local module = dir.base_name(rockspec.source.url) + -- Strip off .hg from base name if present + module = module:gsub("%.hg$", "") + local command = {hg_cmd, "clone", "--startrev HEAD", rockspec.source.url, module} + local tag_or_branch = rockspec.source.tag or rockspec.source.branch + if tag_or_branch then + command = {hg_cmd, "clone", "--startrev HEAD", "--rev", rockspec.source.url, module} + end + local store_dir + if not dest_dir then + store_dir = fs.make_temp_dir(name_version) + if not store_dir then + return nil, "Failed creating temporary directory." + end + util.schedule_function(fs.delete, store_dir) + else + store_dir = dest_dir + end + fs.change_dir(store_dir) + if not fs.execute(unpack(command)) then + return nil, "Failed cloning hg repository." + end + fs.change_dir(module) + + fs.delete(dir.path(store_dir, module, ".hg")) + fs.delete(dir.path(store_dir, module, ".hgignore")) + fs.pop_dir() + fs.pop_dir() + return module, store_dir +end + diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 0e4a73af..87617bcd 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua @@ -38,6 +38,7 @@ rockspec_types = { md5 = "string", file = "string", dir = "string", + vccs = "string", tag = "string", branch = "string", module = "string", -- cgit v1.2.3-55-g6feb