From 179802ab0b5ce7792824f34116d58b2bdacb1a65 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Fri, 5 Jul 2024 15:22:19 +0300 Subject: small bug in vers + potential fix in path --- src/luarocks/core/manif.tl | 38 +++----- src/luarocks/core/path-incomplete.lua | 155 --------------------------------- src/luarocks/core/path-original.lua | 157 ++++++++++++++++++++++++++++++++++ src/luarocks/core/path.lua | 78 ++++++++--------- src/luarocks/core/path.tl | 6 +- src/luarocks/core/vers.lua | 17 ++-- src/luarocks/core/vers.tl | 17 ++-- 7 files changed, 227 insertions(+), 241 deletions(-) delete mode 100644 src/luarocks/core/path-incomplete.lua create mode 100644 src/luarocks/core/path-original.lua (limited to 'src') diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl index 2ae908e0..6f7fd458 100644 --- a/src/luarocks/core/manif.tl +++ b/src/luarocks/core/manif.tl @@ -3,33 +3,24 @@ local record manif end -local record Command - name: string - version: string -end - -local record Lua_version - major: integer - minor: integer - string: string -end +local persist = require("luarocks.core.persist") --! +local cfg = require("luarocks.core.cfg") +local dir = require("luarocks.core.dir") +local util = require("luarocks.core.util") +local vers = require("luarocks.core.vers") +local path = require("luarocks.core.path") +-------------------------------------------------------------------------------- local record Constraints op: string - lua_version: {Lua_version} + version: {vers.Version} end local record DependencyVersion - version: string constraints: {Constraints} name: string end -local record Dependency - name: string - version: {DependencyVersion} --! multiple versions in the same dependency -end - local record Module name: string --! ["tl.tl"] = {"tl/0.15.3-1"} name_version: string --! or file location @@ -48,19 +39,12 @@ end local record Manifest --! arch: string --! only for repository - commands: {Command} - dependencies: {Dependency} + commands: {string:{string}} + dependencies: {string: {string: DependencyVersion}} modules: {Module} repository: {Repository} --! no repository for repositoyry end - -local persist = require("luarocks.core.persist") --! -local cfg = require("luarocks.core.cfg") -local dir = require("luarocks.core.dir") -local util = require("luarocks.core.util") -local vers = require("luarocks.core.vers") -local path = require("luarocks.core.path") --------------------------------------------------------------------------------- + -- Table with repository identifiers as keys and tables mapping -- Lua versions to cached loaded manifests as values. diff --git a/src/luarocks/core/path-incomplete.lua b/src/luarocks/core/path-incomplete.lua deleted file mode 100644 index 59ab9c7f..00000000 --- a/src/luarocks/core/path-incomplete.lua +++ /dev/null @@ -1,155 +0,0 @@ -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 assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local package = _tl_compat and _tl_compat.package or package; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table - -local path = {} - - -local cfg = require("luarocks.core.cfg") -local dir = require("luarocks.core.dir") - - - -local dir_sep = package.config:sub(1, 1) - - -function path.rocks_dir(tree) - if tree == nil then - tree = cfg.root_dir - end - if type(tree) == "string" then - return dir.path(tree, cfg.rocks_subdir) - end - return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) -end - - - - - - - -function path.versioned_name(file, prefix, name, version) - assert(not name:match(dir_sep)) - - local rest = file:sub(#prefix + 1):gsub("^" .. dir_sep .. "*", "") - local name_version = (name .. "_" .. version):gsub("%-", "_"):gsub("%.", "_") - return dir.path(prefix, name_version .. "-" .. rest) -end - - - - - - - - -function path.path_to_module(file) - assert(type(file) == "string") - - local exts = {} - local paths = package.path .. ";" .. package.cpath - for entry in paths:gmatch("[^;]+") do - local ext = entry:match("%.([a-z]+)$") - if ext then - exts[ext] = true - end - end - - local name - for ext, _ in pairs(exts) do - name = file:match("(.*)%." .. ext .. "$") - if name then - name = name:gsub("[\\/]", ".") - break - end - end - - if not name then name = file end - - - name = name:gsub("^%.+", ""):gsub("%.+$", "") - - return name -end - -function path.deploy_lua_dir(tree) - if type(tree) == "string" then - return dir.path(tree, cfg.lua_modules_path) - else - assert(type(tree) == "table") - return tree.lua_dir or dir.path(tree.root, cfg.lua_modules_path) - end -end - -function path.deploy_lib_dir(tree) - if type(tree) == "string" then - return dir.path(tree, cfg.lib_modules_path) - else - assert(type(tree) == "table") - return tostring(tree.lib_dir) or dir.path(tree.root, cfg.lib_modules_path) - end -end - -local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } - - - - - - - - - -function path.which_i(file_name, name, version, tree, i) - local deploy_dir - local extension = file_name:match("%.[a-z]+$") - if is_src_extension[extension] then - deploy_dir = path.deploy_lua_dir(tree) - file_name = dir.path(deploy_dir, file_name) - else - deploy_dir = path.deploy_lib_dir(tree) - file_name = dir.path(deploy_dir, file_name) - end - if i > 1 then - file_name = path.versioned_name(file_name, deploy_dir, name, version) - end - return file_name -end - -function path.rocks_tree_to_string(tree) - if type(tree) == "string" then - return tree - else - return tostring(tree.root) - end -end - - - - - - - - -function path.map_trees(deps_mode, fn, ...) - local result = {} - local current = cfg.root_dir or cfg.rocks_trees[1] - if deps_mode == "one" then - table.insert(result, (fn(current, ...)) or 0) - else - local use = false - if deps_mode == "all" then - use = true - end - for _, tree in ipairs(cfg.rocks_trees or {}) do - if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(current)) then - use = true - end - if use then - table.insert(result, (fn(tree, ...)) or 0) - end - end - end - return result -end - -return path diff --git a/src/luarocks/core/path-original.lua b/src/luarocks/core/path-original.lua new file mode 100644 index 00000000..2f037b41 --- /dev/null +++ b/src/luarocks/core/path-original.lua @@ -0,0 +1,157 @@ + +--- Core LuaRocks-specific path handling functions. +local path = {} + +local cfg = require("luarocks.core.cfg") +local dir = require("luarocks.core.dir") +local require = nil + +local dir_sep = package.config:sub(1, 1) +-------------------------------------------------------------------------------- + +function path.rocks_dir(tree) + if tree == nil then + tree = cfg.root_dir + end + if type(tree) == "string" then + return dir.path(tree, cfg.rocks_subdir) + end + assert(type(tree) == "table") + return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) +end + +--- Produce a versioned version of a filename. +-- @param file string: filename (must start with prefix) +-- @param prefix string: Path prefix for file +-- @param name string: Rock name +-- @param version string: Rock version +-- @return string: a pathname with the same directory parts and a versioned basename. +function path.versioned_name(file, prefix, name, version) + assert(type(file) == "string") + assert(type(name) == "string" and not name:match(dir_sep)) + assert(type(version) == "string") + + local rest = file:sub(#prefix+1):gsub("^" .. dir_sep .. "*", "") + local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") + return dir.path(prefix, name_version.."-"..rest) +end + +--- Convert a pathname to a module identifier. +-- In Unix, for example, a path "foo/bar/baz.lua" is converted to +-- "foo.bar.baz"; "bla/init.lua" returns "bla.init"; "foo.so" returns "foo". +-- @param file string: Pathname of module +-- @return string: The module identifier, or nil if given path is +-- not a conformant module path (the function does not check if the +-- path actually exists). +function path.path_to_module(file) + assert(type(file) == "string") + + local exts = {} + local paths = package.path .. ";" .. package.cpath + for entry in paths:gmatch("[^;]+") do + local ext = entry:match("%.([a-z]+)$") + if ext then + exts[ext] = true + end + end + + local name + for ext, _ in pairs(exts) do + name = file:match("(.*)%." .. ext .. "$") + if name then + name = name:gsub("[\\/]", ".") + break + end + end + + if not name then name = file end + + -- remove any beginning and trailing slashes-converted-to-dots + name = name:gsub("^%.+", ""):gsub("%.+$", "") + + return name +end + +function path.deploy_lua_dir(tree) + if type(tree) == "string" then + return dir.path(tree, cfg.lua_modules_path) + else + assert(type(tree) == "table") + return tree.lua_dir or dir.path(tree.root, cfg.lua_modules_path) + end +end + +function path.deploy_lib_dir(tree) + if type(tree) == "string" then + return dir.path(tree, cfg.lib_modules_path) + else + assert(type(tree) == "table") + return tree.lib_dir or dir.path(tree.root, cfg.lib_modules_path) + end +end + +local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } + +--- Return the pathname of the file that would be loaded for a module, indexed. +-- @param file_name string: module file name as in manifest (eg. "socket/core.so") +-- @param name string: name of the package (eg. "luasocket") +-- @param version string: version number (eg. "2.0.2-1") +-- @param tree string: repository path (eg. "/usr/local") +-- @param i number: the index, 1 if version is the current default, > 1 otherwise. +-- This is done this way for use by select_module in luarocks.loader. +-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") +function path.which_i(file_name, name, version, tree, i) + local deploy_dir + local extension = file_name:match("%.[a-z]+$") + if is_src_extension[extension] then + deploy_dir = path.deploy_lua_dir(tree) + file_name = dir.path(deploy_dir, file_name) + else + deploy_dir = path.deploy_lib_dir(tree) + file_name = dir.path(deploy_dir, file_name) + end + if i > 1 then + file_name = path.versioned_name(file_name, deploy_dir, name, version) + end + return file_name +end + +function path.rocks_tree_to_string(tree) + if type(tree) == "string" then + return tree + else + assert(type(tree) == "table") + return tree.root + end +end + +--- Apply a given function to the active rocks trees based on chosen dependency mode. +-- @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 (this function becomes a nop). +-- @param fn function: function to be applied, with the tree dir (string) as the first +-- argument and the remaining varargs of map_trees as the following arguments. +-- @return a table with all results of invocations of fn collected. +function path.map_trees(deps_mode, fn, ...) + local result = {} + local current = cfg.root_dir or cfg.rocks_trees[1] + if deps_mode == "one" then + table.insert(result, (fn(current, ...)) or 0) + else + local use = false + if deps_mode == "all" then + use = true + end + for _, tree in ipairs(cfg.rocks_trees or {}) do + if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(current)) then + use = true + end + if use then + table.insert(result, (fn(tree, ...)) or 0) + end + end + end + return result +end + +return path diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index 2f037b41..20a90f79 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua @@ -1,13 +1,15 @@ +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 assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local package = _tl_compat and _tl_compat.package or package; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table ---- Core LuaRocks-specific path handling functions. local path = {} + local cfg = require("luarocks.core.cfg") local dir = require("luarocks.core.dir") -local require = nil + + local dir_sep = package.config:sub(1, 1) --------------------------------------------------------------------------------- + function path.rocks_dir(tree) if tree == nil then @@ -16,33 +18,30 @@ function path.rocks_dir(tree) if type(tree) == "string" then return dir.path(tree, cfg.rocks_subdir) end - assert(type(tree) == "table") return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) end ---- Produce a versioned version of a filename. --- @param file string: filename (must start with prefix) --- @param prefix string: Path prefix for file --- @param name string: Rock name --- @param version string: Rock version --- @return string: a pathname with the same directory parts and a versioned basename. + + + + + + function path.versioned_name(file, prefix, name, version) - assert(type(file) == "string") - assert(type(name) == "string" and not name:match(dir_sep)) - assert(type(version) == "string") + assert(not name:match(dir_sep)) - local rest = file:sub(#prefix+1):gsub("^" .. dir_sep .. "*", "") - local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") - return dir.path(prefix, name_version.."-"..rest) + local rest = file:sub(#prefix + 1):gsub("^" .. dir_sep .. "*", "") + local name_version = (name .. "_" .. version):gsub("%-", "_"):gsub("%.", "_") + return dir.path(prefix, name_version .. "-" .. rest) end ---- Convert a pathname to a module identifier. --- In Unix, for example, a path "foo/bar/baz.lua" is converted to --- "foo.bar.baz"; "bla/init.lua" returns "bla.init"; "foo.so" returns "foo". --- @param file string: Pathname of module --- @return string: The module identifier, or nil if given path is --- not a conformant module path (the function does not check if the --- path actually exists). + + + + + + + function path.path_to_module(file) assert(type(file) == "string") @@ -66,7 +65,7 @@ function path.path_to_module(file) if not name then name = file end - -- remove any beginning and trailing slashes-converted-to-dots + name = name:gsub("^%.+", ""):gsub("%.+$", "") return name @@ -92,14 +91,14 @@ end local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } ---- Return the pathname of the file that would be loaded for a module, indexed. --- @param file_name string: module file name as in manifest (eg. "socket/core.so") --- @param name string: name of the package (eg. "luasocket") --- @param version string: version number (eg. "2.0.2-1") --- @param tree string: repository path (eg. "/usr/local") --- @param i number: the index, 1 if version is the current default, > 1 otherwise. --- This is done this way for use by select_module in luarocks.loader. --- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") + + + + + + + + function path.which_i(file_name, name, version, tree, i) local deploy_dir local extension = file_name:match("%.[a-z]+$") @@ -120,18 +119,17 @@ function path.rocks_tree_to_string(tree) if type(tree) == "string" then return tree else - assert(type(tree) == "table") return tree.root end end ---- Apply a given function to the active rocks trees based on chosen dependency mode. --- @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 (this function becomes a nop). --- @param fn function: function to be applied, with the tree dir (string) as the first --- argument and the remaining varargs of map_trees as the following arguments. --- @return a table with all results of invocations of fn collected. + + + + + + + function path.map_trees(deps_mode, fn, ...) local result = {} local current = cfg.root_dir or cfg.rocks_trees[1] diff --git a/src/luarocks/core/path.tl b/src/luarocks/core/path.tl index 5834ef53..35f66e0c 100644 --- a/src/luarocks/core/path.tl +++ b/src/luarocks/core/path.tl @@ -28,7 +28,7 @@ end -- @param version string: Rock version -- @return string: a pathname with the same directory parts and a versioned basename. function path.versioned_name(file: string, prefix: string, name: string, version: string): string - assert(name:match(dir_sep)) --! + assert(not name:match(dir_sep)) --! local rest = file:sub(#prefix+1):gsub("^" .. dir_sep .. "*", "") local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") @@ -85,7 +85,7 @@ function path.deploy_lib_dir(tree: string | Tree): string return dir.path(tree, cfg.lib_modules_path) else assert(type(tree) == "table") - return tostring(tree.lib_dir) or dir.path(tree.root, cfg.lib_modules_path) + return tree.lib_dir or dir.path(tree.root, cfg.lib_modules_path) end end @@ -119,7 +119,7 @@ function path.rocks_tree_to_string(tree: string | Tree): string if tree is string then return tree else - return tostring(tree.root) + return tree.root end end diff --git a/src/luarocks/core/vers.lua b/src/luarocks/core/vers.lua index a5a1a0a9..097e8199 100644 --- a/src/luarocks/core/vers.lua +++ b/src/luarocks/core/vers.lua @@ -1,4 +1,12 @@ -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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local vers = {} +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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local vers = {Version = {}, } + + + + + + + + local util = require("luarocks.core.util") @@ -16,13 +24,6 @@ local deltas = { - - - - - - - local version_mt = { diff --git a/src/luarocks/core/vers.tl b/src/luarocks/core/vers.tl index 8953a730..7b2659e4 100644 --- a/src/luarocks/core/vers.tl +++ b/src/luarocks/core/vers.tl @@ -1,4 +1,12 @@ local record vers + record Version + {number} -- next version of Teal: "is {number}" + string: string + revision: number + metamethod __eq: function(Version, Version): boolean + metamethod __lt: function(Version, Version): boolean + metamethod __le: function(Version, Version): boolean + end end local util = require("luarocks.core.util") @@ -14,14 +22,7 @@ local deltas: {string: integer} = { alpha = -1000000 } -local record Version - {number} -- next version of Teal: "is {number}" - string: string - revision: number - metamethod __eq: function(Version, Version): boolean - metamethod __lt: function(Version, Version): boolean - metamethod __le: function(Version, Version): boolean -end +local type Version = vers.Version local version_mt: metatable = { --- Equality comparison for versions. -- cgit v1.2.3-55-g6feb