From ee55c132b3415b1cd6993b6cf80a7c03a1090651 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 1 Aug 2024 17:00:24 +0300 Subject: csv finished --- src/luarocks/core/cfg.d.tl | 20 ++++++++++---- src/luarocks/fetch/cvs-original.lua | 55 +++++++++++++++++++++++++++++++++++++ src/luarocks/fetch/cvs.lua | 27 +++++++++--------- src/luarocks/fetch/cvs.tl | 54 ++++++++++++++++++++++++++++++++++++ src/luarocks/fs.d.tl | 3 ++ 5 files changed, 140 insertions(+), 19 deletions(-) create mode 100644 src/luarocks/fetch/cvs-original.lua create mode 100644 src/luarocks/fetch/cvs.tl (limited to 'src') diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index eff86971..97f10a35 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl @@ -22,10 +22,6 @@ local record cfg lib_dir: string end -- util - record Source - url: string - end - record Description summary: string detailed: string @@ -44,11 +40,19 @@ local record cfg rockspec_format: string name: string --? package version: string - source: {Source} + record source + url: string + module: string + pathname: string + tag: string + end description: Description test_dependencies: {string} test: Test format_is_at_least: function(Rockspec, string): boolean + record variables + CVS: string + end end record cache @@ -66,6 +70,12 @@ local record cfg home: string -- queries arch: string + -- api + record config_files + record user + file: string + end + end end return cfg \ No newline at end of file diff --git a/src/luarocks/fetch/cvs-original.lua b/src/luarocks/fetch/cvs-original.lua new file mode 100644 index 00000000..d78e6e60 --- /dev/null +++ b/src/luarocks/fetch/cvs-original.lua @@ -0,0 +1,55 @@ + +--- Fetch back-end for retrieving sources from CVS. +local cvs = {} + +local unpack = unpack or table.unpack + +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") +local util = require("luarocks.util") + +--- Download sources for building a rock, using CVS. +-- @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 cvs.get_sources(rockspec, extract, dest_dir) + assert(rockspec:type() == "rockspec") + assert(type(dest_dir) == "string" or not dest_dir) + + local cvs_cmd = rockspec.variables.CVS + local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") + if not ok then + return nil, err_msg + end + + local name_version = rockspec.name .. "-" .. rockspec.version + local module = rockspec.source.module or dir.base_name(rockspec.source.url) + local command = {cvs_cmd, "-d"..rockspec.source.pathname, "export", module} + if rockspec.source.tag then + table.insert(command, 4, "-r") + table.insert(command, 5, rockspec.source.tag) + 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 + local ok, err = fs.change_dir(store_dir) + if not ok then return nil, err end + if not fs.execute(unpack(command)) then + return nil, "Failed fetching files from CVS." + end + fs.pop_dir() + return module, store_dir +end + + +return cvs diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua index d78e6e60..1c6616ff 100644 --- a/src/luarocks/fetch/cvs.lua +++ b/src/luarocks/fetch/cvs.lua @@ -1,24 +1,23 @@ +local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local table = _tl_compat and _tl_compat.table or table; local _tl_table_unpack = unpack or table.unpack ---- Fetch back-end for retrieving sources from CVS. local cvs = {} -local unpack = unpack or table.unpack local fs = require("luarocks.fs") local dir = require("luarocks.dir") local util = require("luarocks.util") +local cfg = require("luarocks.core.cfg") + + + + ---- Download sources for building a rock, using CVS. --- @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 cvs.get_sources(rockspec, extract, dest_dir) - assert(rockspec:type() == "rockspec") - assert(type(dest_dir) == "string" or not dest_dir) + + + + +function cvs.get_sources(rockspec, extract, dest_dir) local cvs_cmd = rockspec.variables.CVS local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") if not ok then @@ -27,7 +26,7 @@ function cvs.get_sources(rockspec, extract, dest_dir) local name_version = rockspec.name .. "-" .. rockspec.version local module = rockspec.source.module or dir.base_name(rockspec.source.url) - local command = {cvs_cmd, "-d"..rockspec.source.pathname, "export", module} + local command = { cvs_cmd, "-d" .. rockspec.source.pathname, "export", module } if rockspec.source.tag then table.insert(command, 4, "-r") table.insert(command, 5, rockspec.source.tag) @@ -44,7 +43,7 @@ function cvs.get_sources(rockspec, extract, dest_dir) end local ok, err = fs.change_dir(store_dir) if not ok then return nil, err end - if not fs.execute(unpack(command)) then + if not fs.execute(_tl_table_unpack(command)) then return nil, "Failed fetching files from CVS." end fs.pop_dir() diff --git a/src/luarocks/fetch/cvs.tl b/src/luarocks/fetch/cvs.tl new file mode 100644 index 00000000..1d874daf --- /dev/null +++ b/src/luarocks/fetch/cvs.tl @@ -0,0 +1,54 @@ + +--- Fetch back-end for retrieving sources from CVS. +local record cvs +end + +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") +local util = require("luarocks.util") +local cfg = require("luarocks.core.cfg") --! import for Rockspec + +local type Rockspec = cfg.Rockspec + +--- Download sources for building a rock, using CVS. +-- @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 cvs.get_sources(rockspec: Rockspec, extract, dest_dir?: string): string, string --? extract not needed + local cvs_cmd = rockspec.variables.CVS + local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") + if not ok then + return nil, err_msg + end + + local name_version = rockspec.name .. "-" .. rockspec.version + local module = rockspec.source.module or dir.base_name(rockspec.source.url) + local command = {cvs_cmd, "-d"..rockspec.source.pathname, "export", module} + if rockspec.source.tag then + table.insert(command, 4, "-r") + table.insert(command, 5, rockspec.source.tag) + end + local store_dir: string + 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 + local ok, err = fs.change_dir(store_dir) + if not ok then return nil, err end + if not fs.execute(table.unpack(command)) then + return nil, "Failed fetching files from CVS." + end + fs.pop_dir() + return module, store_dir +end + + +return cvs diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index 88034b65..24f3e61f 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl @@ -17,6 +17,9 @@ local record fs -- signing is_tool_available: function(string, string): string, string execute: function(...: string): boolean --? boolean? src/luarocks/signing.tl: 27 + make_temp_dir: function(string): string, string + change_dir: function(string): boolean, string + pop_dir: function(): boolean end return fs -- cgit v1.2.3-55-g6feb