From 294f30af4f9af2cf1f7bbd2c787b132dcc954aa4 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Tue, 6 Aug 2024 19:45:49 +0300 Subject: removed more redefined variables and deps --- src/luarocks/core/manif.tl | 4 +- src/luarocks/core/util.tl | 6 +- src/luarocks/core/vers.tl | 6 +- src/luarocks/deps.tl | 7 +- src/luarocks/fetch/cvs.tl | 4 +- src/luarocks/fetch/svn.tl | 8 +- src/luarocks/queries.tl | 6 +- src/luarocks/rockspecs-original.lua | 183 ------------------------------------ src/luarocks/rockspecs.lua | 132 +++++++++++--------------- src/luarocks/rockspecs.tl | 5 +- src/luarocks/search.tl | 4 +- src/luarocks/tools/patch.tl | 2 +- src/luarocks/upload/api.tl | 5 +- 13 files changed, 88 insertions(+), 284 deletions(-) delete mode 100644 src/luarocks/rockspecs-original.lua (limited to 'src') diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl index 7ef018db..683ec741 100644 --- a/src/luarocks/core/manif.tl +++ b/src/luarocks/core/manif.tl @@ -12,8 +12,8 @@ local path = require("luarocks.core.path") -------------------------------------------------------------------------------- -local type t = require("luarocks.core.types.tree") -local type Tree = t.Tree +local type tr = require("luarocks.core.types.tree") +local type Tree = tr.Tree local type q = require("luarocks.core.types.query") local type Query = q.Query diff --git a/src/luarocks/core/util.tl b/src/luarocks/core/util.tl index ede0e75f..183deaab 100644 --- a/src/luarocks/core/util.tl +++ b/src/luarocks/core/util.tl @@ -4,9 +4,9 @@ end -------------------------------------------------------------------------------- -local type o = require("luarocks.core.types.ordering") -local type Ordering = o.Ordering -local type SortBy = o.SortBy +local type ord = require("luarocks.core.types.ordering") +local type Ordering = ord.Ordering +local type SortBy = ord.SortBy local dir_sep = package.config:sub(1, 1) diff --git a/src/luarocks/core/vers.tl b/src/luarocks/core/vers.tl index f7ecdb98..62701f74 100644 --- a/src/luarocks/core/vers.tl +++ b/src/luarocks/core/vers.tl @@ -2,9 +2,9 @@ local record vers end local util = require("luarocks.core.util") -local type v = require("luarocks.core.types.version") -local type Version = v.Version -local type Constraint = v.Constraint +local type ver = require("luarocks.core.types.version") +local type Version = ver.Version +local type Constraint = ver.Constraint -------------------------------------------------------------------------------- local deltas: {string: integer} = { diff --git a/src/luarocks/deps.tl b/src/luarocks/deps.tl index f65594fb..d9d66892 100644 --- a/src/luarocks/deps.tl +++ b/src/luarocks/deps.tl @@ -26,10 +26,11 @@ local type Tree = t.Tree local type q = require("luarocks.core.types.query") local type Query = q.Query -local type Version = require("luarocks.core.types.version").Version +local type ver = require("luarocks.core.types.version") +local type Version = ver.Version -local type p = require("luarocks.core.types.persist") -local type PersistableTable = p.PersistableTable +local type per = require("luarocks.core.types.persist") +local type PersistableTable = per.PersistableTable local type res = require("luarocks.core.types.result") local type Result = res.Result diff --git a/src/luarocks/fetch/cvs.tl b/src/luarocks/fetch/cvs.tl index a2f67dcf..0532cecb 100644 --- a/src/luarocks/fetch/cvs.tl +++ b/src/luarocks/fetch/cvs.tl @@ -41,8 +41,8 @@ function cvs.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string else store_dir = dest_dir end - local ok, err = fs.change_dir(store_dir) - if not ok then return nil, err end + local okchange, err = fs.change_dir(store_dir) + if not okchange then return nil, err end if not fs.execute(table.unpack(command)) then return nil, "Failed fetching files from CVS." end diff --git a/src/luarocks/fetch/svn.tl b/src/luarocks/fetch/svn.tl index 3db136e9..fc4ba2a5 100644 --- a/src/luarocks/fetch/svn.tl +++ b/src/luarocks/fetch/svn.tl @@ -43,13 +43,13 @@ function svn.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string else store_dir = dest_dir end - local ok, err = fs.change_dir(store_dir) - if not ok then return nil, err end + local okchange, err = fs.change_dir(store_dir) + if not okchange then return nil, err end if not fs.execute(table.unpack(command)) then return nil, "Failed fetching files from Subversion." end - ok, err = fs.change_dir(module) - if not ok then return nil, err end + okchange, err = fs.change_dir(module) + if not okchange then return nil, err end for _, d in ipairs(fs.find(".")) do if dir.base_name(d) == ".svn" then fs.delete(dir.path(store_dir, module, d)) diff --git a/src/luarocks/queries.tl b/src/luarocks/queries.tl index bed7612c..b6e7a392 100644 --- a/src/luarocks/queries.tl +++ b/src/luarocks/queries.tl @@ -9,9 +9,9 @@ local cfg = require("luarocks.core.cfg") local type q = require("luarocks.core.types.query") local type Query = q.Query -local type v = require("luarocks.core.types.version") -local type Version = v.Version -local type Constraint = v.Constraint +local type ver = require("luarocks.core.types.version") +local type Version = ver.Version +local type Constraint = ver.Constraint local query_mt: metatable = {} diff --git a/src/luarocks/rockspecs-original.lua b/src/luarocks/rockspecs-original.lua deleted file mode 100644 index 454bab77..00000000 --- a/src/luarocks/rockspecs-original.lua +++ /dev/null @@ -1,183 +0,0 @@ -local rockspecs = {} - -local cfg = require("luarocks.core.cfg") -local dir = require("luarocks.dir") -local path = require("luarocks.path") -local queries = require("luarocks.queries") -local type_rockspec = require("luarocks.type.rockspec") -local util = require("luarocks.util") -local vers = require("luarocks.core.vers") - -local vendored_build_type_set = { - ["builtin"] = true, - ["cmake"] = true, - ["command"] = true, - ["make"] = true, - ["module"] = true, -- compatibility alias - ["none"] = true, -} - -local rockspec_mt = {} - -rockspec_mt.__index = rockspec_mt - -function rockspec_mt.type() - return "rockspec" -end - ---- Perform platform-specific overrides on a table. --- Overrides values of table with the contents of the appropriate --- subset of its "platforms" field. The "platforms" field should --- be a table containing subtables keyed with strings representing --- platform names. Names that match the contents of the global --- detected platforms setting are used. For example, if --- platform "unix" is detected, then the fields of --- tbl.platforms.unix will overwrite those of tbl with the same --- names. For table values, the operation is performed recursively --- (tbl.platforms.foo.x.y.z overrides tbl.x.y.z; other contents of --- tbl.x are preserved). --- @param tbl table or nil: Table which may contain a "platforms" field; --- if it doesn't (or if nil is passed), this function does nothing. -local function platform_overrides(tbl) - assert(type(tbl) == "table" or not tbl) - - if not tbl then return end - - if tbl.platforms then - for platform in cfg.each_platform() do - local platform_tbl = tbl.platforms[platform] - if platform_tbl then - util.deep_merge(tbl, platform_tbl) - end - end - end - tbl.platforms = nil -end - -local function convert_dependencies(rockspec, key) - if rockspec[key] then - for i = 1, #rockspec[key] do - local parsed, err = queries.from_dep_string(rockspec[key][i]) - if not parsed then - return nil, "Parse error processing dependency '"..rockspec[key][i].."': "..tostring(err) - end - rockspec[key][i] = parsed - end - else - rockspec[key] = {} - end - return true -end - ---- Set up path-related variables for a given rock. --- Create a "variables" table in the rockspec table, containing --- adjusted variables according to the configuration file. --- @param rockspec table: The rockspec table. -local function configure_paths(rockspec) - local vars = {} - for k,v in pairs(cfg.variables) do - vars[k] = v - end - local name, version = rockspec.name, rockspec.version - vars.PREFIX = path.install_dir(name, version) - vars.LUADIR = path.lua_dir(name, version) - vars.LIBDIR = path.lib_dir(name, version) - vars.CONFDIR = path.conf_dir(name, version) - vars.BINDIR = path.bin_dir(name, version) - vars.DOCDIR = path.doc_dir(name, version) - rockspec.variables = vars -end - -function rockspecs.from_persisted_table(filename, rockspec, globals, quick) - assert(type(rockspec) == "table") - assert(type(globals) == "table" or globals == nil) - assert(type(filename) == "string") - assert(type(quick) == "boolean" or quick == nil) - - if rockspec.rockspec_format then - if vers.compare_versions(rockspec.rockspec_format, type_rockspec.rockspec_format) then - return nil, "Rockspec format "..rockspec.rockspec_format.." is not supported, please upgrade LuaRocks." - end - end - - if not quick then - local ok, err = type_rockspec.check(rockspec, globals or {}) - if not ok then - return nil, err - end - end - - --- Check if rockspec format version satisfies version requirement. - -- @param rockspec table: The rockspec table. - -- @param version string: required version. - -- @return boolean: true if rockspec format matches version or is newer, false otherwise. - do - local parsed_format = vers.parse_version(rockspec.rockspec_format or "1.0") - rockspec.format_is_at_least = function(self, version) - return parsed_format >= vers.parse_version(version) - end - end - - platform_overrides(rockspec.build) - platform_overrides(rockspec.dependencies) - platform_overrides(rockspec.build_dependencies) - platform_overrides(rockspec.test_dependencies) - platform_overrides(rockspec.external_dependencies) - platform_overrides(rockspec.source) - platform_overrides(rockspec.hooks) - platform_overrides(rockspec.test) - - rockspec.name = rockspec.package:lower() - - local protocol, pathname = dir.split_url(rockspec.source.url) - if dir.is_basic_protocol(protocol) then - rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) - end - rockspec.source.protocol, rockspec.source.pathname = protocol, pathname - - -- Temporary compatibility - if rockspec.source.cvs_module then rockspec.source.module = rockspec.source.cvs_module end - if rockspec.source.cvs_tag then rockspec.source.tag = rockspec.source.cvs_tag end - - rockspec.local_abs_filename = filename - rockspec.source.dir_set = rockspec.source.dir ~= nil - rockspec.source.dir = rockspec.source.dir or rockspec.source.module - - rockspec.rocks_provided = util.get_rocks_provided(rockspec) - - for _, key in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do - local ok, err = convert_dependencies(rockspec, key) - if not ok then - return nil, err - end - end - - if rockspec.build - and rockspec.build.type - and not vendored_build_type_set[rockspec.build.type] then - local build_pkg_name = "luarocks-build-" .. rockspec.build.type - if not rockspec.build_dependencies then - rockspec.build_dependencies = {} - end - - local found = false - for _, dep in ipairs(rockspec.build_dependencies) do - if dep.name == build_pkg_name then - found = true - break - end - end - - if not found then - table.insert(rockspec.build_dependencies, queries.from_dep_string(build_pkg_name)) - end - end - - if not quick then - configure_paths(rockspec) - end - - return setmetatable(rockspec, rockspec_mt) -end - -return rockspecs diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.lua index 559a874a..454bab77 100644 --- a/src/luarocks/rockspecs.lua +++ b/src/luarocks/rockspecs.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 pairs = _tl_compat and _tl_compat.pairs or pairs; local table = _tl_compat and _tl_compat.table or table; local rockspecs = {} - +local rockspecs = {} local cfg = require("luarocks.core.cfg") local dir = require("luarocks.dir") @@ -9,53 +8,45 @@ local type_rockspec = require("luarocks.type.rockspec") local util = require("luarocks.util") local vers = require("luarocks.core.vers") -local r = require("luarocks.core.types.rockspec") - - - - - - local vendored_build_type_set = { ["builtin"] = true, ["cmake"] = true, ["command"] = true, ["make"] = true, - ["module"] = true, + ["module"] = true, -- compatibility alias ["none"] = true, } local rockspec_mt = {} -rockspec_mt.__index = r.Rockspec +rockspec_mt.__index = rockspec_mt -function r.Rockspec.type() +function rockspec_mt.type() return "rockspec" end - - - - - - - - - - - - - +--- Perform platform-specific overrides on a table. +-- Overrides values of table with the contents of the appropriate +-- subset of its "platforms" field. The "platforms" field should +-- be a table containing subtables keyed with strings representing +-- platform names. Names that match the contents of the global +-- detected platforms setting are used. For example, if +-- platform "unix" is detected, then the fields of +-- tbl.platforms.unix will overwrite those of tbl with the same +-- names. For table values, the operation is performed recursively +-- (tbl.platforms.foo.x.y.z overrides tbl.x.y.z; other contents of +-- tbl.x are preserved). +-- @param tbl table or nil: Table which may contain a "platforms" field; +-- if it doesn't (or if nil is passed), this function does nothing. local function platform_overrides(tbl) + assert(type(tbl) == "table" or not tbl) if not tbl then return end - local tblp = tbl.platforms - - if type(tblp) == "table" then + if tbl.platforms then for platform in cfg.each_platform() do - local platform_tbl = tblp[platform] - if type(platform_tbl) == "table" then + local platform_tbl = tbl.platforms[platform] + if platform_tbl then util.deep_merge(tbl, platform_tbl) end end @@ -63,28 +54,28 @@ local function platform_overrides(tbl) tbl.platforms = nil end -local function convert_dependencies(dependencies) - if not dependencies then - return {} - end - local qs = {} - for i = 1, #dependencies do - local parsed, err = queries.from_dep_string(dependencies[i]) - if not parsed then - return nil, "Parse error processing dependency '" .. dependencies[i] .. "': " .. tostring(err) +local function convert_dependencies(rockspec, key) + if rockspec[key] then + for i = 1, #rockspec[key] do + local parsed, err = queries.from_dep_string(rockspec[key][i]) + if not parsed then + return nil, "Parse error processing dependency '"..rockspec[key][i].."': "..tostring(err) + end + rockspec[key][i] = parsed end - qs[i] = parsed + else + rockspec[key] = {} end - return qs + return true end - - - - +--- Set up path-related variables for a given rock. +-- Create a "variables" table in the rockspec table, containing +-- adjusted variables according to the configuration file. +-- @param rockspec table: The rockspec table. local function configure_paths(rockspec) local vars = {} - for k, v in pairs(cfg.variables) do + for k,v in pairs(cfg.variables) do vars[k] = v end local name, version = rockspec.name, rockspec.version @@ -98,10 +89,14 @@ local function configure_paths(rockspec) end function rockspecs.from_persisted_table(filename, rockspec, globals, quick) + assert(type(rockspec) == "table") + assert(type(globals) == "table" or globals == nil) + assert(type(filename) == "string") + assert(type(quick) == "boolean" or quick == nil) if rockspec.rockspec_format then if vers.compare_versions(rockspec.rockspec_format, type_rockspec.rockspec_format) then - return nil, "Rockspec format " .. rockspec.rockspec_format .. " is not supported, please upgrade LuaRocks." + return nil, "Rockspec format "..rockspec.rockspec_format.." is not supported, please upgrade LuaRocks." end end @@ -112,10 +107,10 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick) end end - - - - + --- Check if rockspec format version satisfies version requirement. + -- @param rockspec table: The rockspec table. + -- @param version string: required version. + -- @return boolean: true if rockspec format matches version or is newer, false otherwise. do local parsed_format = vers.parse_version(rockspec.rockspec_format or "1.0") rockspec.format_is_at_least = function(self, version) @@ -140,7 +135,7 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick) end rockspec.source.protocol, rockspec.source.pathname = protocol, pathname - + -- Temporary compatibility if rockspec.source.cvs_module then rockspec.source.module = rockspec.source.cvs_module end if rockspec.source.cvs_tag then rockspec.source.tag = rockspec.source.cvs_tag end @@ -150,32 +145,23 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick) rockspec.rocks_provided = util.get_rocks_provided(rockspec) - local err - rockspec.dependencies.queries, err = convert_dependencies(rockspec.dependencies) - if err then - return nil, err - end - - rockspec.build_dependencies.queries, err = convert_dependencies(rockspec.build_dependencies) - if err then - return nil, err - end - - rockspec.test_dependencies.queries, err = convert_dependencies(rockspec.test_dependencies) - if err then - return nil, err + for _, key in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do + local ok, err = convert_dependencies(rockspec, key) + if not ok then + return nil, err + end end - if rockspec.build and - rockspec.build.type and - not vendored_build_type_set[rockspec.build.type] then + if rockspec.build + and rockspec.build.type + and not vendored_build_type_set[rockspec.build.type] then local build_pkg_name = "luarocks-build-" .. rockspec.build.type if not rockspec.build_dependencies then rockspec.build_dependencies = {} end local found = false - for _, dep in ipairs(rockspec.build_dependencies.queries) do + for _, dep in ipairs(rockspec.build_dependencies) do if dep.name == build_pkg_name then found = true break @@ -183,11 +169,7 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick) end if not found then - local query, err = queries.from_dep_string(build_pkg_name) - if err then - return nil, "Invalid dependency in rockspec: " .. err - end - table.insert(rockspec.build_dependencies.queries, query) + table.insert(rockspec.build_dependencies, queries.from_dep_string(build_pkg_name)) end end diff --git a/src/luarocks/rockspecs.tl b/src/luarocks/rockspecs.tl index 3ea6c147..b65227da 100644 --- a/src/luarocks/rockspecs.tl +++ b/src/luarocks/rockspecs.tl @@ -1,3 +1,4 @@ + local record rockspecs end @@ -183,8 +184,8 @@ function rockspecs.from_persisted_table(filename: string, rockspec: Rockspec, gl end if not found then - local query, err = queries.from_dep_string(build_pkg_name) - if err then + local query, errfromdep = queries.from_dep_string(build_pkg_name) + if errfromdep then return nil, "Invalid dependency in rockspec: " .. err end table.insert(rockspec.build_dependencies.queries, query) diff --git a/src/luarocks/search.tl b/src/luarocks/search.tl index 7d8a9055..caf01221 100644 --- a/src/luarocks/search.tl +++ b/src/luarocks/search.tl @@ -15,8 +15,8 @@ local type Result = r.Result local type q = require("luarocks.core.types.query") local type Query = q.Query -local type v = require("luarocks.core.types.version") -local type Version = v.Version +local type ver = require("luarocks.core.types.version") +local type Version = ver.Version local type t = require("luarocks.core.types.tree") local type Tree = t.Tree diff --git a/src/luarocks/tools/patch.tl b/src/luarocks/tools/patch.tl index a5d67e18..f204cd63 100644 --- a/src/luarocks/tools/patch.tl +++ b/src/luarocks/tools/patch.tl @@ -465,7 +465,7 @@ end local function check_patched(file: {string}, hunks: {Hunk}): boolean local lineno: integer = 1 - local ok, err: boolean, string = pcall(function() + local _, err: boolean, string = pcall(function() if #file == 0 then error('nomatch', 0) end diff --git a/src/luarocks/upload/api.tl b/src/luarocks/upload/api.tl index 6863f6f0..4ea9f922 100644 --- a/src/luarocks/upload/api.tl +++ b/src/luarocks/upload/api.tl @@ -35,6 +35,9 @@ local type Args = api.Args local type Configuration = api.Configuration local type File = multipart.File +local type p = require("luarocks.core.types.persist") +local type PersistableTable = p.PersistableTable + local function upload_config_file(): string if not cfg.config_files.user.file then return nil @@ -284,7 +287,7 @@ function api.Api:save_config(): boolean, string --! nil? if not ok then return nil, errmake end - persist.save_from_table(upload_conf, self.config as persist.PersistableTable) + persist.save_from_table(upload_conf, self.config as PersistableTable) fs.set_permissions(upload_conf, "read", "user") return true end -- cgit v1.2.3-55-g6feb