From b537a1c1caa235d09698bd298be03996d8efaf14 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Fri, 5 Jul 2024 03:00:43 +0300 Subject: fixed more bugs (inc. vers bug), implemented tree and other config values, and created a prototype for manifest --- src/luarocks/core/cfg.d.tl | 17 +++++++++++++-- src/luarocks/core/dir.lua | 41 ++++++++++++++++++------------------ src/luarocks/core/manif.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++ src/luarocks/core/manif.tl | 51 +++++++++++++++++++++++++++++++++++++++++++++ src/luarocks/core/path.lua | 6 ++++-- src/luarocks/core/path.tl | 24 +++++++++++---------- src/luarocks/core/util.lua | 11 ++++++---- src/luarocks/core/vers.lua | 39 ++++++++++++++++++++-------------- src/luarocks/core/vers.tl | 12 ++++++----- 9 files changed, 192 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index 09815260..11d647ff 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl @@ -3,5 +3,18 @@ local record cfg make_platforms: function(system: string): {any: boolean} make_defaults: function(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any} use_defaults: function(cfg, defaults: {any: any}) - --! -end \ No newline at end of file + root_dir: string | Tree + rocks_subdir: string + lua_modules_path: string + lib_modules_path: string + rocks_trees: {string| Tree} + lua_version: string + record Tree + root: string + rocks_dir: string + lua_dir: string + lib_dir: string + end +end + +return cfg \ No newline at end of file diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua index cccc1333..7d9702ba 100644 --- a/src/luarocks/core/dir.lua +++ b/src/luarocks/core/dir.lua @@ -18,26 +18,6 @@ end - - - - -function dir.path(...) - local t = { ... } - while t[1] == "" do - table.remove(t, 1) - end - for i, c in ipairs(t) do - t[i] = unquote(c) - end - return dir.normalize(table.concat(t, "/")) -end - - - - - - function dir.split_url(url) assert(type(url) == "string") @@ -92,4 +72,25 @@ function dir.normalize(name) return pathname end + + + + + + + + + + +function dir.path(...) + local t = { ... } + while t[1] == "" do + table.remove(t, 1) + end + for i, c in ipairs(t) do + t[i] = unquote(c) + end + return dir.normalize(table.concat(t, "/")) +end + return dir diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index 8b917590..758b76db 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua @@ -3,6 +3,57 @@ local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 th local manif = {} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + local persist = require("luarocks.core.persist") local cfg = require("luarocks.core.cfg") local dir = require("luarocks.core.dir") diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl index e5e72eaf..2ae908e0 100644 --- a/src/luarocks/core/manif.tl +++ b/src/luarocks/core/manif.tl @@ -3,6 +3,57 @@ local record manif end +local record Command + name: string + version: string +end + +local record Lua_version + major: integer + minor: integer + string: string +end + +local record Constraints + op: string + lua_version: {Lua_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 +end + +local record RepositoryVersion + version: string + manifests: {Manifest} +end + +local record Repository + name: string + version: {RepositoryVersion} --! multiple versions in the same repository + +end + +local record Manifest --! + arch: string --! only for repository + commands: {Command} + dependencies: {Dependency} + 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") diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index 5dd0091b..07542a1f 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua @@ -6,6 +6,8 @@ local path = {} local cfg = require("luarocks.core.cfg") local dir = require("luarocks.core.dir") + + local dir_sep = package.config:sub(1, 1) @@ -16,7 +18,7 @@ function path.rocks_dir(tree) if type(tree) == "string" then return dir.path(tree, cfg.rocks_subdir) end - return tostring(tree.rocks_dir) or dir.path(tree.root, cfg.rocks_subdir) + return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) end @@ -74,7 +76,7 @@ function path.deploy_lua_dir(tree) return dir.path(tree, cfg.lua_modules_path) else assert(type(tree) == "table") - return tostring(tree.lua_dir) or dir.path(tree.root, cfg.lua_modules_path) + return tree.lua_dir or dir.path(tree.root, cfg.lua_modules_path) end end diff --git a/src/luarocks/core/path.tl b/src/luarocks/core/path.tl index a866f4d7..5834ef53 100644 --- a/src/luarocks/core/path.tl +++ b/src/luarocks/core/path.tl @@ -3,20 +3,22 @@ local record path end -local cfg = require("luarocks.core.cfg") --? cannot index key ... in boolean 'cfg' of type boolean +local cfg = require("luarocks.core.cfg") local dir = require("luarocks.core.dir") +local type Tree = cfg.Tree + local dir_sep = package.config:sub(1, 1) -------------------------------------------------------------------------------- -function path.rocks_dir(tree: string | {any: any}): string +function path.rocks_dir(tree: string | Tree): string if tree == nil then tree = cfg.root_dir end if tree is string then return dir.path(tree, cfg.rocks_subdir) end - return tostring(tree.rocks_dir) or dir.path(tree.root, cfg.rocks_subdir) --? tostring(tree.root) + return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) end --- Produce a versioned version of a filename. @@ -69,21 +71,21 @@ function path.path_to_module(file: string): string return name end -function path.deploy_lua_dir(tree: string | {any: any}): string +function path.deploy_lua_dir(tree: string | Tree): string if tree is string then return dir.path(tree, cfg.lua_modules_path) else assert(type(tree) == "table") - return tostring(tree.lua_dir) or dir.path(tree.root, cfg.lua_modules_path) --? tostring(tree.root) + return tree.lua_dir or dir.path(tree.root, cfg.lua_modules_path) end end -function path.deploy_lib_dir(tree: string | {any: any}): string +function path.deploy_lib_dir(tree: string | Tree): string if tree is 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) --? tostring(tree.root) + return tostring(tree.lib_dir) or dir.path(tree.root, cfg.lib_modules_path) end end @@ -113,11 +115,11 @@ function path.which_i(file_name: string, name: string, version: string, tree: st return file_name end -function path.rocks_tree_to_string(tree: string | {any: any}): string +function path.rocks_tree_to_string(tree: string | Tree): string if tree is string then return tree else - return tostring(tree.root) --? + return tostring(tree.root) end end @@ -138,8 +140,8 @@ function path.map_trees(deps_mode: string, fn: function, ...: string): {any} if deps_mode == "all" then use = true end - for _, tree in ipairs(cfg.rocks_trees or {}) do --! no mention of rocks_trees in the cfg file - if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(current)) then --! + 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 diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 31aa5c25..38d7ae45 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua @@ -126,9 +126,10 @@ function util.deep_merge(dst, src) local dstk = dst[k] if dstk == nil then dst[k] = {} + dstk = dst[k] end if type(dstk) == "table" then - util.deep_merge(dst[k], v) + util.deep_merge(dstk, v) else dst[k] = v end @@ -145,11 +146,13 @@ end function util.deep_merge_under(dst, src) for k, v in pairs(src) do if type(v) == "table" then - if dst[k] == nil then + local dstk = dst[k] + if dstk == nil then dst[k] = {} + dstk = dst[k] end - if type(dst[k]) == "table" then - util.deep_merge_under(dst[k], v) + if type(dstk) == "table" then + util.deep_merge_under(dstk, v) end elseif dst[k] == nil then dst[k] = v diff --git a/src/luarocks/core/vers.lua b/src/luarocks/core/vers.lua index 231b9683..a5a1a0a9 100644 --- a/src/luarocks/core/vers.lua +++ b/src/luarocks/core/vers.lua @@ -1,5 +1,4 @@ -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 = {} local util = require("luarocks.core.util") @@ -22,6 +21,8 @@ local deltas = { + + local version_mt = { @@ -148,7 +149,7 @@ function vers.compare_versions(a, b) if a == b then return false end - return vers.parse_version(a) > vers.parse_version(b) + return vers.parse_version(b) < vers.parse_version(a) end @@ -167,8 +168,10 @@ local function partial_match(version_for_parse, requested_for_parce) local version, requested - if not (type(version_for_parse) == "table") then version = vers.parse_version(version_for_parse) end - if not (type(requested_for_parce) == "table") then requested = vers.parse_version(requested_for_parce) end + if not (type(version_for_parse) == "table") then version = vers.parse_version(version_for_parse) + else version = version_for_parse end + if not (type(requested_for_parce) == "table") then requested = vers.parse_version(requested_for_parce) + else requested = requested_for_parce end if not (type(version) == "table") or not (type(requested) == "table") then return false end for i, ri in ipairs(requested) do @@ -190,18 +193,22 @@ function vers.match_constraints(version, constraints) local ok = true setmetatable(version, version_mt) for _, constr in pairs(constraints) do - if type(constr.version) == "string" then - constr.version = vers.parse_version(constr.version) - end local constr_version, constr_op = constr.version, constr.op - setmetatable(constr_version, version_mt) - if constr_op == "==" then ok = version == constr_version - elseif constr_op == "~=" then ok = version ~= constr_version - elseif constr_op == ">" then ok = version > constr_version - elseif constr_op == "<" then ok = version < constr_version - elseif constr_op == ">=" then ok = version >= constr_version - elseif constr_op == "<=" then ok = version <= constr_version - elseif constr_op == "~>" then ok = partial_match(version, constr_version) + local cv + if type(constr_version) == "string" then + cv = vers.parse_version(constr_version) + constr.version = cv + else + cv = constr_version + end + setmetatable(cv, version_mt) + if constr_op == "==" then ok = version == cv + elseif constr_op == "~=" then ok = version ~= cv + elseif constr_op == ">" then ok = cv < version + elseif constr_op == "<" then ok = version < cv + elseif constr_op == ">=" then ok = cv <= version + elseif constr_op == "<=" then ok = version <= cv + elseif constr_op == "~>" then ok = partial_match(version, cv) end if not ok then break end end diff --git a/src/luarocks/core/vers.tl b/src/luarocks/core/vers.tl index 7d0f0a83..8953a730 100644 --- a/src/luarocks/core/vers.tl +++ b/src/luarocks/core/vers.tl @@ -4,7 +4,7 @@ end local util = require("luarocks.core.util") -------------------------------------------------------------------------------- -local deltas: {string: integer} = { --?1 +local deltas: {string: integer} = { dev = 120000000, scm = 110000000, cvs = 100000000, @@ -23,7 +23,7 @@ local record Version metamethod __le: function(Version, Version): boolean end -local version_mt: metatable = { --? anything to do here +local version_mt: metatable = { --- Equality comparison for versions. -- All version numbers must be equal. -- If both versions have revision numbers, they must be equal; @@ -132,7 +132,7 @@ function vers.parse_version(vstring: string): Version version[i] = 0 break end - version[i] = deltas[token] or (token:byte() / 1000) --?1 + version[i] = deltas[token] or (token:byte() / 1000) end v = rest end @@ -168,8 +168,10 @@ local function partial_match(version_for_parse: string | Version, requested_for_ local version, requested: Version, Version - if not version_for_parse is Version then version = vers.parse_version(version_for_parse) end - if not requested_for_parce is Version then requested = vers.parse_version(requested_for_parce) end + if not version_for_parse is Version then version = vers.parse_version(version_for_parse) + else version = version_for_parse end + if not requested_for_parce is Version then requested = vers.parse_version(requested_for_parce) + else requested = requested_for_parce end if not version is Version or not requested is Version then return false end for i, ri in ipairs(requested) do -- cgit v1.2.3-55-g6feb