From 38f2dc2ab50e06d6b8be5eaec5d06f7c57e270c8 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 15 Aug 2024 01:36:44 +0300 Subject: remove asserts and builtin and build --- src/luarocks/build/builtin.tl | 52 ++++++++++++++++++++--------------- src/luarocks/core/cfg.d.tl | 4 +++ src/luarocks/core/dir.tl | 1 - src/luarocks/core/manif.tl | 1 - src/luarocks/core/path.tl | 3 -- src/luarocks/core/sysdetect.tl | 1 - src/luarocks/core/types/build.d.tl | 9 ++++-- src/luarocks/core/types/installs.d.tl | 1 + src/luarocks/core/types/rockspec.tl | 3 -- src/luarocks/core/util.tl | 4 +-- src/luarocks/deps.tl | 15 +++++----- src/luarocks/dir.tl | 2 -- src/luarocks/fetch.tl | 1 - src/luarocks/fs.d.tl | 1 + src/luarocks/queries.tl | 6 ---- src/luarocks/results.tl | 2 -- src/luarocks/search.tl | 1 - src/luarocks/test.tl | 2 +- src/luarocks/test/command.tl | 6 ++-- src/luarocks/tools/zip.tl | 4 +-- 20 files changed, 57 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/luarocks/build/builtin.tl b/src/luarocks/build/builtin.tl index e26ca5a4..b0857363 100644 --- a/src/luarocks/build/builtin.tl +++ b/src/luarocks/build/builtin.tl @@ -9,6 +9,12 @@ local type Rockspec = r.Rockspec local type i = require("luarocks.core.types.installs") local type Installs = i.Installs +local type Install = i.Install + +local type b = require("luarocks.core.types.build") +local type Build = b.Build +local type BuiltinBuild = b.BuiltinBuild +local type Module = BuiltinBuild.Module -- This build driver checks LUA_INCDIR and LUA_LIBDIR on demand, -- so that pure-Lua rocks don't need to have development headers @@ -58,8 +64,8 @@ do ["tests.lua"] = true, } - function builtin.autodetect_modules(libs: {string}, incdirs: {string}, libdirs: {string}) - local modules = {} + function builtin.autodetect_modules(libs: {string}, incdirs: {string}, libdirs: {string}): {string : string | Module}, Installs, {string} + local modules: {string: (string | Module)} = {} local install: Installs local copy_directories: {string} @@ -102,7 +108,7 @@ do if bindir then install = { bin = {} } for _, file in ipairs(fs.list_dir(bindir)) do - table.insert(install.bin, dir.path(bindir, file)) --! + table.insert(install.bin, dir.path(bindir, file)) end end @@ -131,10 +137,12 @@ end -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors occurred, -- nil and an error message otherwise. -function builtin.run(rockspec: Rockspec, no_install: boolean) - local compile_object, compile_library, compile_static_library +function builtin.run(rockspec: Rockspec, no_install: boolean): boolean, string, string + local compile_object: function(string, string, {string}, {string}): boolean, string, string + local compile_library: function(string, {string}, {string}, {string}, string): boolean, string, string + local compile_static_library: function(string, {string}, {string}, {string}, string): boolean, string, string - local build = rockspec.build + local build = rockspec.build as BuiltinBuild local variables = rockspec.variables local checked_lua_h = false @@ -161,7 +169,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) add_flags(extras, "-I%s", incdirs) return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o", object, "-I"..variables.LUA_INCDIR, source, table.unpack(extras)) end - compile_library = function(library, objects, libraries, libdirs, name) + compile_library = function(library: string, objects: {string}, libraries: {string}, libdirs: {string}, name: string): boolean, string, string local extras = { table.unpack(objects) } add_flags(extras, "-L%s", libdirs) add_flags(extras, "-l%s", libraries) @@ -188,13 +196,13 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) end ]] elseif cfg.is_platform("win32") then - compile_object = function(object, source, defines, incdirs) + compile_object = function(object: string, source: string, defines: {string}, incdirs: {string}): boolean, string, string local extras = {} add_flags(extras, "-D%s", defines) add_flags(extras, "-I%s", incdirs) return execute(variables.CC.." "..variables.CFLAGS, "-c", "-Fo"..object, "-I"..variables.LUA_INCDIR, source, table.unpack(extras)) end - compile_library = function(library, objects, libraries, libdirs, name) + compile_library = function(library: string, objects: {string}, libraries: {string}, libdirs: {string}, name: string): boolean, string, string local extras = { table.unpack(objects) } add_flags(extras, "-libpath:%s", libdirs) add_flags(extras, "%s.lib", libraries) @@ -226,13 +234,13 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) end ]] else - compile_object = function(object, source, defines, incdirs) + compile_object = function(object: string, source: string, defines: {string}, incdirs: {string}): boolean, string, string local extras = {} add_flags(extras, "-D%s", defines) add_flags(extras, "-I%s", incdirs) return execute(variables.CC.." "..variables.CFLAGS, "-I"..variables.LUA_INCDIR, "-c", source, "-o", object, table.unpack(extras)) end - compile_library = function (library, objects, libraries, libdirs) + compile_library = function (library: string, objects: {string}, libraries: {string}, libdirs: {string}, name: string): boolean, string, string local extras = { table.unpack(objects) } add_flags(extras, "-L%s", libdirs) if cfg.gcc_rpath then @@ -245,7 +253,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) end return execute(variables.LD.." "..variables.LDFLAGS.." "..variables.LIBFLAG, "-o", library, table.unpack(extras)) end - compile_static_library = function(library, objects, libraries, libdirs, name) -- luacheck: ignore 211 + compile_static_library = function(library: string, objects: {string}, libraries: {string}, libdirs: {string}, name: string): boolean, string, string -- luacheck: ignore 211 local ok = execute(variables.AR, "rc", library, table.unpack(objects)) if ok then ok = execute(variables.RANLIB, library) @@ -254,7 +262,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) end end - local ok, err + local ok, err: boolean, string local lua_modules = {} local lib_modules = {} local luadir = path.lua_dir(rockspec.name, rockspec.version) @@ -264,7 +272,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) if not build.modules then if rockspec:format_is_at_least("3.0") then - local install, copy_directories + local install, copy_directories: Installs, {string} build.modules, install, copy_directories = builtin.autodetect_modules(autolibs, autoincdirs, autolibdirs) build.install = build.install or install build.copy_directories = build.copy_directories or copy_directories @@ -273,10 +281,10 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) end end - local compile_temp_dir + local compile_temp_dir: string local mkdir_cache = {} - local function cached_make_dir(name) + local function cached_make_dir(name: string): boolean, string if name == "" or mkdir_cache[name] then return true end @@ -286,7 +294,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) for name, info in pairs(build.modules) do local moddir = path.module_to_path(name) - if type(info) == "string" then + if info is string then local ext = info:match("%.([^.]+)$") if ext == "lua" then local filename = dir.base_name(info) @@ -302,7 +310,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) info = {info} end end - if type(info) == "table" then + if info is Module then if not checked_lua_h then local ok, err, errcode = deps.check_lua_incdir(rockspec.variables) if not ok then @@ -320,12 +328,12 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) local objects = {} local sources = info.sources if info[1] then sources = info end - if type(sources) == "string" then sources = {sources} end - if type(sources) ~= "table" then + if sources is string then sources = {sources} end + if not sources is {string} then return nil, "error in rockspec: module '" .. name .. "' entry has no 'sources' list" end for _, source in ipairs(sources) do - if type(source) ~= "string" then + if not source is string then return nil, "error in rockspec: module '" .. name .. "' does not specify source correctly." end local object = source:gsub("%.[^.]*$", "."..cfg.obj_extension) @@ -354,7 +362,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean) cached_make_dir(build_dir) lib_modules[build_name] = dir.path(libdir, module_name) - ok = compile_library(build_name, objects, info.libraries, info.libdirs or autolibdirs, name) + ok = compile_library(build_name, objects, info.libraries as {string}, info.libdirs or autolibdirs, name) if not ok then return nil, "Failed compiling module "..module_name end diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index a342fe35..f87cc1e9 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl @@ -79,6 +79,10 @@ local record cfg -- writer no_manifest: boolean accepted_build_types: {boolean} + -- builtin + gcc_rpath: boolean + link_lua_explicitly: boolean + obj_extension: string end return cfg \ No newline at end of file diff --git a/src/luarocks/core/dir.tl b/src/luarocks/core/dir.tl index 87efec12..20068341 100644 --- a/src/luarocks/core/dir.tl +++ b/src/luarocks/core/dir.tl @@ -19,7 +19,6 @@ end -- @param url string: an URL or a local pathname. -- @return string, string: the protocol, and the pathname without the protocol. function dir.split_url(url: string): string, string - assert(type(url) == "string") url = unquote(url) local protocol, pathname = url:match("^([^:]*)://(.*)") diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl index 683ec741..0b0bf9f8 100644 --- a/src/luarocks/core/manif.tl +++ b/src/luarocks/core/manif.tl @@ -70,7 +70,6 @@ end -- @return table or (nil, string, string): A table representing the manifest, -- or nil followed by an error message and an error code, see manifest_loader. function manif.fast_load_local_manifest(repo_url: string): Manifest, string | {any: any}, string - assert(type(repo_url) == "string") local cached_manifest = manif.get_cached_manifest(repo_url) if cached_manifest then diff --git a/src/luarocks/core/path.tl b/src/luarocks/core/path.tl index 37421445..491fe484 100644 --- a/src/luarocks/core/path.tl +++ b/src/luarocks/core/path.tl @@ -43,7 +43,6 @@ end -- not a conformant module path (the function does not check if the -- path actually exists). function path.path_to_module(file: string): string - assert(type(file) == "string") local exts = {} local paths = package.path .. ";" .. package.cpath @@ -75,7 +74,6 @@ 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 tree.lua_dir or dir.path(tree.root, cfg.lua_modules_path) end end @@ -84,7 +82,6 @@ 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 tree.lib_dir or dir.path(tree.root, cfg.lib_modules_path) end end diff --git a/src/luarocks/core/sysdetect.tl b/src/luarocks/core/sysdetect.tl index a19a5f24..63692e4a 100644 --- a/src/luarocks/core/sysdetect.tl +++ b/src/luarocks/core/sysdetect.tl @@ -435,7 +435,6 @@ end -------------------------------------------------------------------------------- function sysdetect.detect_file(file: string): System, Processor - assert(type(file) == "string") local fd = io.open(file, "rb") if not fd then return nil diff --git a/src/luarocks/core/types/build.d.tl b/src/luarocks/core/types/build.d.tl index 0591aa33..98707c0b 100644 --- a/src/luarocks/core/types/build.d.tl +++ b/src/luarocks/core/types/build.d.tl @@ -6,8 +6,10 @@ local record build interface Build type: string install: Installs - copy_directories: string + copy_directories: {string} patches: {string : string} + extra_files: {string : string} + macosx_deployment_target: string end record BuiltinBuild @@ -15,14 +17,15 @@ local record build where self.type == "builtin" record Module + is {string} sources: string | {string} - libraries: {string} + libraries: string | {string} defines: {string} incdirs: {string} libdirs: {string} end - modules: {string: (string | {string} | Module)} + modules: {string: (string | Module)} end record MakeBuild diff --git a/src/luarocks/core/types/installs.d.tl b/src/luarocks/core/types/installs.d.tl index 9e919233..1e0747fc 100644 --- a/src/luarocks/core/types/installs.d.tl +++ b/src/luarocks/core/types/installs.d.tl @@ -12,4 +12,5 @@ local record installs bin: Install end end + return installs \ No newline at end of file diff --git a/src/luarocks/core/types/rockspec.tl b/src/luarocks/core/types/rockspec.tl index ca12bf94..f1e4895d 100644 --- a/src/luarocks/core/types/rockspec.tl +++ b/src/luarocks/core/types/rockspec.tl @@ -4,9 +4,6 @@ local type Query = q.Query local type b = require("luarocks.core.types.build") local type Build = b.Build -local type i = require("luarocks.core.types.installs") -local type Installs = i.Installs - local record rockspec record Description summary: string diff --git a/src/luarocks/core/util.tl b/src/luarocks/core/util.tl index 183deaab..d8d6c1b5 100644 --- a/src/luarocks/core/util.tl +++ b/src/luarocks/core/util.tl @@ -70,7 +70,7 @@ function util.show_table(t: {any:any}, tname: string, top_indent: string): strin -- the information is defined through lines return ("%q"):format(so .. ", defined in (" .. info.linedefined .. "-" .. info.lastlinedefined .. ")" .. info.source) end - elseif type(o) == "number" then + elseif o is number then return so else return ("%q"):format(so) @@ -110,7 +110,7 @@ function util.show_table(t: {any:any}, tname: string, top_indent: string): strin end tname = tname or "__unnamed__" - if type(t) ~= "table" then + if not t is {any:any} then return tname .. " = " .. basic_serialize(t) end cart, autoref = "", "" diff --git a/src/luarocks/deps.tl b/src/luarocks/deps.tl index 1ce163c3..30ff8e53 100644 --- a/src/luarocks/deps.tl +++ b/src/luarocks/deps.tl @@ -17,8 +17,10 @@ local type r = require("luarocks.core.types.rockspec") local type Rockspec = r.Rockspec local type Dependencies = r.Dependencies -local type b = require("luarocks.core.types.build") -local type Build = b.Build +local type bld = require("luarocks.core.types.build") +local type BuiltinBuild = bld.BuiltinBuild +local type Module = BuiltinBuild.Module +local type Build = bld.Build local type t = require("luarocks.core.types.tree") local type Tree = t.Tree @@ -592,14 +594,14 @@ end function deps.autodetect_external_dependencies(build: Build): {string : {string : string}} -- only applies to the 'builtin' build type - if not build or not build.modules then + if not build or not (build as BuiltinBuild).modules then return nil end local extdeps: {string: {string: string}} = {} local any = false - for _, data in pairs(build.modules) do - if data is {string : string | {string}} and data.libraries then + for _, data in pairs((build as BuiltinBuild).modules) do + if data is Module and data.libraries then local libraries: {string} local librariesstr: string | {string} = data.libraries if librariesstr is string then @@ -679,8 +681,6 @@ end -- @param name string: Package name. -- @param version string: Package version. function deps.scan_deps(results: {string: string}, mdeps: {string: {string: {Query}}}, name: string, version: string, deps_mode: string) - assert(type(results) == "table") - assert(type(mdeps) == "table") assert(not name:match("/")) local fetch = require("luarocks.fetch") @@ -858,7 +858,6 @@ end -- "none" for using the default dependency mode from the configuration. function deps.check_dependencies(repo: string, deps_mode: string) local rocks_dir = path.rocks_dir(repo or cfg.root_dir) - assert(type(deps_mode) == "string") if deps_mode == "none" then deps_mode = cfg.deps_mode end local manifest = manif.load_manifest(rocks_dir) diff --git a/src/luarocks/dir.tl b/src/luarocks/dir.tl index d349ac71..e9e16fbd 100644 --- a/src/luarocks/dir.tl +++ b/src/luarocks/dir.tl @@ -19,7 +19,6 @@ local dir_sep = package.config:sub(1, 1) -- or "\a\b\c". -- @return string: The filename without its path, such as "c". function dir.base_name(pathname: string): string - assert(type(pathname) == "string") local b: string b = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes @@ -36,7 +35,6 @@ end -- For entries such as "/a/b/", "/a" is returned. If there are -- no directory separators in input, "" is returned. function dir.dir_name(pathname: string): string - assert(type(pathname) == "string") local d: string d = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes diff --git a/src/luarocks/fetch.tl b/src/luarocks/fetch.tl index 5a42645b..30c45b56 100644 --- a/src/luarocks/fetch.tl +++ b/src/luarocks/fetch.tl @@ -436,7 +436,6 @@ end -- @return table or (nil, string): A table representing the rockspec -- or nil followed by an error message. function fetch.load_local_rockspec(rel_filename: string, quick?: boolean): Rockspec, string - assert(type(rel_filename) == "string") local abs_filename = fs.absolute_name(rel_filename) local basename = dir.base_name(abs_filename) diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index 86499bee..ce055567 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl @@ -61,6 +61,7 @@ local record fs get_md5: function(string): string, string -- build apply_patch: function(string, string, boolean): boolean, string + copy_contents: function(string, string): boolean, string end return fs diff --git a/src/luarocks/queries.tl b/src/luarocks/queries.tl index 7729ab5f..3bd0802f 100644 --- a/src/luarocks/queries.tl +++ b/src/luarocks/queries.tl @@ -57,11 +57,6 @@ end -- @param operator string?: operator for version matching (default is "==") -- @return table: A query in table format function queries.new(name: string, namespace?: string, version?: string, substring?: boolean, arch?: string, operator?: string): Query - -- assert(type(namespace) == "string" or not namespace) --! optional parameters? - -- assert(type(version) == "string" or not version) - -- assert(type(substring) == "boolean" or not substring) - -- assert(type(arch) == "string" or not arch) - -- assert(type(operator) == "string" or not operator) operator = operator or "==" @@ -83,7 +78,6 @@ end -- Query for all packages -- @param arch string (optional) function queries.all(arch?: string): Query - -- assert(type(arch) == "string" or not arch) --! optional return queries.new("", nil, nil, true, arch) end diff --git a/src/luarocks/results.tl b/src/luarocks/results.tl index e6c849a6..cf7e109c 100644 --- a/src/luarocks/results.tl +++ b/src/luarocks/results.tl @@ -20,8 +20,6 @@ end function results.new(name: string, version: string, repo: string, arch?: string, namespace?: string): Result, boolean assert(not name:match("/")) - -- assert(type(arch) == "string" or not arch) --! arch?: string - -- assert(type(namespace) == "string" or not namespace) --! namespace?: string if not namespace then diff --git a/src/luarocks/search.tl b/src/luarocks/search.tl index fdeebcd8..5681fa54 100644 --- a/src/luarocks/search.tl +++ b/src/luarocks/search.tl @@ -27,7 +27,6 @@ local type Tree = t.Tree -- tables with fields "arch" and "repo". -- @param result table: A result. function search.store_result(result_tree: {string: {string: {Result}}}, result: Result) - assert(type(result_tree) == "table") local name = result.name local version = result.version diff --git a/src/luarocks/test.tl b/src/luarocks/test.tl index 3345a7eb..b60e3458 100644 --- a/src/luarocks/test.tl +++ b/src/luarocks/test.tl @@ -104,7 +104,7 @@ function test.run_test_suite(rockspec_arg: string | Rockspec, test_type: string, end else local flags = rockspec.test and rockspec.test.flags - if type(flags) == "table" then + if flags is {string} then util.variable_substitutions(flags, rockspec.variables) -- insert any flags given in test.flags at the front of args diff --git a/src/luarocks/test/command.tl b/src/luarocks/test/command.tl index 843367b2..2a1e3ce9 100644 --- a/src/luarocks/test/command.tl +++ b/src/luarocks/test/command.tl @@ -29,7 +29,8 @@ function command.run_tests(test: Test, args: {string}): boolean, string local ok: boolean if test.script then - if type(test.script) ~= "string" then + local test_script = test.script + if not test_script is string then return nil, "Malformed rockspec: 'script' expects a string" end if not fs.exists(test.script) then @@ -38,7 +39,8 @@ function command.run_tests(test: Test, args: {string}): boolean, string local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured ok = fs.execute(lua, test.script, table.unpack(args)) elseif test.command then - if type(test.command) ~= "string" then + local test_command = test.command + if not test_command is string then return nil, "Malformed rockspec: 'command' expects a string" end ok = fs.execute(test.command, table.unpack(args)) diff --git a/src/luarocks/tools/zip.tl b/src/luarocks/tools/zip.tl index bbe2ecbd..82a19011 100644 --- a/src/luarocks/tools/zip.tl +++ b/src/luarocks/tools/zip.tl @@ -562,9 +562,7 @@ function zip.gzip(input_filename: string, output_filename?: string): boolean, st return fs.filter_file(fn, input_filename, output_filename) end -function zip.gunzip(input_filename: string, output_filename: string): boolean, string - assert(type(input_filename) == "string") - assert(output_filename == nil or type(output_filename) == "string") +function zip.gunzip(input_filename: string, output_filename?: string): boolean, string if not output_filename then output_filename = input_filename:gsub("%.gz$", "") -- cgit v1.2.3-55-g6feb