diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-07-15 00:23:01 +0300 |
|---|---|---|
| committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:49:17 +0300 |
| commit | 949c0e66a12d4f9d6ad9df560647b41329d9a5f7 (patch) | |
| tree | 83c6f1cf1fb3376791adf7a17f6247c90eefa521 /src | |
| parent | 568a5ea1ad0ed1612a92203cb3dd10ff0265c04c (diff) | |
| download | luarocks-949c0e66a12d4f9d6ad9df560647b41329d9a5f7.tar.gz luarocks-949c0e66a12d4f9d6ad9df560647b41329d9a5f7.tar.bz2 luarocks-949c0e66a12d4f9d6ad9df560647b41329d9a5f7.zip | |
converted path and added to fs and cfg
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/core/cfg.d.tl | 5 | ||||
| -rw-r--r-- | src/luarocks/core/path.tl | 1 | ||||
| -rw-r--r-- | src/luarocks/fs.d.tl | 6 | ||||
| -rw-r--r-- | src/luarocks/path-original.lua (renamed from src/luarocks/path.lua) | 0 | ||||
| -rw-r--r-- | src/luarocks/path.tl | 255 | ||||
| -rw-r--r-- | src/luarocks/util.tl | 53 |
6 files changed, 312 insertions, 8 deletions
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index a741baaa..68d110c3 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl | |||
| @@ -4,12 +4,17 @@ local record cfg | |||
| 4 | make_defaults: function(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any} | 4 | make_defaults: function(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any} |
| 5 | use_defaults: function(cfg, defaults: {any: any}) | 5 | use_defaults: function(cfg, defaults: {any: any}) |
| 6 | root_dir: string | Tree | 6 | root_dir: string | Tree |
| 7 | rocks_dir: string | ||
| 7 | rocks_subdir: string | 8 | rocks_subdir: string |
| 8 | lua_modules_path: string | 9 | lua_modules_path: string |
| 9 | lib_modules_path: string | 10 | lib_modules_path: string |
| 10 | rocks_trees: {string| Tree} | 11 | rocks_trees: {string| Tree} |
| 11 | lua_version: string | 12 | lua_version: string |
| 12 | deps_mode: string | 13 | deps_mode: string |
| 14 | deploy_bin_dir: string | ||
| 15 | deploy_lua_dir: string | ||
| 16 | deploy_lib_dir: string | ||
| 17 | lib_extension: string | ||
| 13 | record Tree | 18 | record Tree |
| 14 | root: string | 19 | root: string |
| 15 | rocks_dir: string | 20 | rocks_dir: string |
diff --git a/src/luarocks/core/path.tl b/src/luarocks/core/path.tl index e1bdc8de..213c0d69 100644 --- a/src/luarocks/core/path.tl +++ b/src/luarocks/core/path.tl | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | |||
| 2 | --- Core LuaRocks-specific path handling functions. | 1 | --- Core LuaRocks-specific path handling functions. |
| 3 | local record path | 2 | local record path |
| 4 | end | 3 | end |
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index b0ca56c7..6a8d7520 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl | |||
| @@ -6,8 +6,10 @@ local record fs | |||
| 6 | change_dir_to_root: function | 6 | change_dir_to_root: function |
| 7 | record FsTable | 7 | record FsTable |
| 8 | end | 8 | end |
| 9 | 9 | -- util | |
| 10 | --... | 10 | is_dir: function(dir: string): boolean |
| 11 | dir: function(dir: string): function(): string --? right iterator | ||
| 12 | is_file: function(file: string): boolean | ||
| 11 | end | 13 | end |
| 12 | 14 | ||
| 13 | return fs | 15 | return fs |
diff --git a/src/luarocks/path.lua b/src/luarocks/path-original.lua index 19657c83..19657c83 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path-original.lua | |||
diff --git a/src/luarocks/path.tl b/src/luarocks/path.tl new file mode 100644 index 00000000..93fb6aae --- /dev/null +++ b/src/luarocks/path.tl | |||
| @@ -0,0 +1,255 @@ | |||
| 1 | |||
| 2 | --- LuaRocks-specific path handling functions. | ||
| 3 | -- All paths are configured in this module, making it a single | ||
| 4 | -- point where the layout of the local installation is defined in LuaRocks. | ||
| 5 | |||
| 6 | local cfg = require("luarocks.core.cfg") | ||
| 7 | local core = require("luarocks.core.path") | ||
| 8 | local dir = require("luarocks.dir") | ||
| 9 | -- local util = require("luarocks.util") --! crashes teal | ||
| 10 | |||
| 11 | local type Tree = cfg.Tree | ||
| 12 | |||
| 13 | local record path | ||
| 14 | rocks_dir: function(string | Tree): string | ||
| 15 | versioned_name: function(string, string, string, string): string | ||
| 16 | path_to_module: function(string): string | ||
| 17 | deploy_lua_dir: function(string | Tree): string | ||
| 18 | deploy_lib_dir: function(string | Tree): string | ||
| 19 | map_trees: function(string, function(...: any): any..., ...: string): {any} | ||
| 20 | rocks_tree_to_string: function(string | Tree): string | ||
| 21 | end | ||
| 22 | |||
| 23 | path.rocks_dir = core.rocks_dir | ||
| 24 | path.versioned_name = core.versioned_name | ||
| 25 | path.path_to_module = core.path_to_module | ||
| 26 | path.deploy_lua_dir = core.deploy_lua_dir | ||
| 27 | path.deploy_lib_dir = core.deploy_lib_dir | ||
| 28 | path.map_trees = core.map_trees | ||
| 29 | path.rocks_tree_to_string = core.rocks_tree_to_string | ||
| 30 | |||
| 31 | --- Infer rockspec filename from a rock filename. | ||
| 32 | -- @param rock_name string: Pathname of a rock file. | ||
| 33 | -- @return string: Filename of the rockspec, without path. | ||
| 34 | function path.rockspec_name_from_rock(rock_name: string): string | ||
| 35 | local base_name = dir.base_name(rock_name) | ||
| 36 | return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" | ||
| 37 | end | ||
| 38 | |||
| 39 | function path.root_from_rocks_dir(rocks_dir: string): string | ||
| 40 | return "" --! temp | ||
| 41 | -- return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") --! only depends here on util | ||
| 42 | end | ||
| 43 | |||
| 44 | function path.root_dir(tree: string | Tree): string | ||
| 45 | if tree is string then | ||
| 46 | return tree | ||
| 47 | else | ||
| 48 | return tree.root | ||
| 49 | end | ||
| 50 | end | ||
| 51 | |||
| 52 | function path.deploy_bin_dir(tree: string | Tree): string | ||
| 53 | return dir.path(path.root_dir(tree), "bin") | ||
| 54 | end | ||
| 55 | |||
| 56 | function path.manifest_file(tree: string | Tree): string | ||
| 57 | return dir.path(path.rocks_dir(tree), "manifest") | ||
| 58 | end | ||
| 59 | |||
| 60 | --- Get the directory for all versions of a package in a tree. | ||
| 61 | -- @param name string: The package name. | ||
| 62 | -- @return string: The resulting path -- does not guarantee that | ||
| 63 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 64 | -- the package (and by extension, the path) exists. | ||
| 65 | function path.versions_dir(name: string, tree: string | Tree): string | ||
| 66 | assert(not name:match("/")) | ||
| 67 | return dir.path(path.rocks_dir(tree), name) | ||
| 68 | end | ||
| 69 | |||
| 70 | --- Get the local installation directory (prefix) for a package. | ||
| 71 | -- @param name string: The package name. | ||
| 72 | -- @param version string: The package version. | ||
| 73 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 74 | -- @return string: The resulting path -- does not guarantee that | ||
| 75 | -- the package (and by extension, the path) exists. | ||
| 76 | function path.install_dir(name: string, version: string, tree: string | Tree): string | ||
| 77 | assert(not name:match("/")) | ||
| 78 | return dir.path(path.rocks_dir(tree), name, version) | ||
| 79 | end | ||
| 80 | |||
| 81 | --- Get the local filename of the rockspec of an installed rock. | ||
| 82 | -- @param name string: The package name. | ||
| 83 | -- @param version string: The package version. | ||
| 84 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 85 | -- @return string: The resulting path -- does not guarantee that | ||
| 86 | -- the package (and by extension, the file) exists. | ||
| 87 | function path.rockspec_file(name: string, version: string, tree: string | Tree): string | ||
| 88 | assert(not name:match("/")) | ||
| 89 | return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec") | ||
| 90 | end | ||
| 91 | |||
| 92 | --- Get the local filename of the rock_manifest file of an installed rock. | ||
| 93 | -- @param name string: The package name. | ||
| 94 | -- @param version string: The package version. | ||
| 95 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 96 | -- @return string: The resulting path -- does not guarantee that | ||
| 97 | -- the package (and by extension, the file) exists. | ||
| 98 | function path.rock_manifest_file(name: string, version: string, tree: string | Tree): string | ||
| 99 | assert(not name:match("/")) | ||
| 100 | return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") | ||
| 101 | end | ||
| 102 | |||
| 103 | --- Get the local filename of the rock_namespace file of an installed rock. | ||
| 104 | -- @param name string: The package name (without a namespace). | ||
| 105 | -- @param version string: The package version. | ||
| 106 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 107 | -- @return string: The resulting path -- does not guarantee that | ||
| 108 | -- the package (and by extension, the file) exists. | ||
| 109 | function path.rock_namespace_file(name: string, version: string, tree: string | Tree): string | ||
| 110 | assert(not name:match("/")) | ||
| 111 | return dir.path(path.rocks_dir(tree), name, version, "rock_namespace") | ||
| 112 | end | ||
| 113 | |||
| 114 | --- Get the local installation directory for C libraries of a package. | ||
| 115 | -- @param name string: The package name. | ||
| 116 | -- @param version string: The package version. | ||
| 117 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 118 | -- @return string: The resulting path -- does not guarantee that | ||
| 119 | -- the package (and by extension, the path) exists. | ||
| 120 | function path.lib_dir(name: string, version: string, tree: string | Tree): string | ||
| 121 | assert(not name:match("/")) | ||
| 122 | return dir.path(path.rocks_dir(tree), name, version, "lib") | ||
| 123 | end | ||
| 124 | |||
| 125 | --- Get the local installation directory for Lua modules of a package. | ||
| 126 | -- @param name string: The package name. | ||
| 127 | -- @param version string: The package version. | ||
| 128 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 129 | -- @return string: The resulting path -- does not guarantee that | ||
| 130 | -- the package (and by extension, the path) exists. | ||
| 131 | function path.lua_dir(name: string, version: string, tree: string | Tree): string | ||
| 132 | assert(not name:match("/")) | ||
| 133 | return dir.path(path.rocks_dir(tree), name, version, "lua") | ||
| 134 | end | ||
| 135 | |||
| 136 | --- Get the local installation directory for documentation of a package. | ||
| 137 | -- @param name string: The package name. | ||
| 138 | -- @param version string: The package version. | ||
| 139 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 140 | -- @return string: The resulting path -- does not guarantee that | ||
| 141 | -- the package (and by extension, the path) exists. | ||
| 142 | function path.doc_dir(name: string, version: string, tree: string | Tree): string | ||
| 143 | assert(not name:match("/")) | ||
| 144 | return dir.path(path.rocks_dir(tree), name, version, "doc") | ||
| 145 | end | ||
| 146 | |||
| 147 | --- Get the local installation directory for configuration files of a package. | ||
| 148 | -- @param name string: The package name. | ||
| 149 | -- @param version string: The package version. | ||
| 150 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 151 | -- @return string: The resulting path -- does not guarantee that | ||
| 152 | -- the package (and by extension, the path) exists. | ||
| 153 | function path.conf_dir(name: string, version: string, tree: string | Tree): string | ||
| 154 | assert(not name:match("/")) | ||
| 155 | return dir.path(path.rocks_dir(tree), name, version, "conf") | ||
| 156 | end | ||
| 157 | |||
| 158 | --- Get the local installation directory for command-line scripts | ||
| 159 | -- of a package. | ||
| 160 | -- @param name string: The package name. | ||
| 161 | -- @param version string: The package version. | ||
| 162 | -- @param tree string or nil: If given, specifies the local tree to use. | ||
| 163 | -- @return string: The resulting path -- does not guarantee that | ||
| 164 | -- the package (and by extension, the path) exists. | ||
| 165 | function path.bin_dir(name: string, version: string, tree: string | Tree): string | ||
| 166 | assert(not name:match("/")) | ||
| 167 | return dir.path(path.rocks_dir(tree), name, version, "bin") | ||
| 168 | end | ||
| 169 | |||
| 170 | --- Extract name, version and arch of a rock filename, | ||
| 171 | -- or name, version and "rockspec" from a rockspec name. | ||
| 172 | -- @param file_name string: pathname of a rock or rockspec | ||
| 173 | -- @return (string, string, string) or nil: name, version and arch | ||
| 174 | -- or nil if name could not be parsed | ||
| 175 | function path.parse_name(file_name: string): string | ||
| 176 | if file_name:match("%.rock$") then | ||
| 177 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") | ||
| 178 | else | ||
| 179 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.(rockspec)") | ||
| 180 | end | ||
| 181 | end | ||
| 182 | |||
| 183 | --- Make a rockspec or rock URL. | ||
| 184 | -- @param pathname string: Base URL or pathname. | ||
| 185 | -- @param name string: Package name. | ||
| 186 | -- @param version string: Package version. | ||
| 187 | -- @param arch string: Architecture identifier, or "rockspec" or "installed". | ||
| 188 | -- @return string: A URL or pathname following LuaRocks naming conventions. | ||
| 189 | function path.make_url(pathname: string, name: string, version: string, arch: string): string | ||
| 190 | assert(not name:match("/")) | ||
| 191 | local filename = name.."-"..version | ||
| 192 | if arch == "installed" then | ||
| 193 | filename = dir.path(name, version, filename..".rockspec") | ||
| 194 | elseif arch == "rockspec" then | ||
| 195 | filename = filename..".rockspec" | ||
| 196 | else | ||
| 197 | filename = filename.."."..arch..".rock" | ||
| 198 | end | ||
| 199 | return dir.path(pathname, filename) | ||
| 200 | end | ||
| 201 | |||
| 202 | --- Obtain the directory name where a module should be stored. | ||
| 203 | -- For example, on Unix, "foo.bar.baz" will return "foo/bar". | ||
| 204 | -- @param mod string: A module name in Lua dot-separated format. | ||
| 205 | -- @return string: A directory name using the platform's separator. | ||
| 206 | function path.module_to_path(mod: string): string | ||
| 207 | return (mod:gsub("[^.]*$", ""):gsub("%.", "/")) | ||
| 208 | end | ||
| 209 | |||
| 210 | function path.use_tree(tree: Tree) | ||
| 211 | cfg.root_dir = tree | ||
| 212 | cfg.rocks_dir = path.rocks_dir(tree) | ||
| 213 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | ||
| 214 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | ||
| 215 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | ||
| 216 | end | ||
| 217 | |||
| 218 | function path.add_to_package_paths(tree: string | Tree) | ||
| 219 | package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";" | ||
| 220 | .. dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";" | ||
| 221 | .. package.path | ||
| 222 | package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";" | ||
| 223 | .. package.cpath | ||
| 224 | end | ||
| 225 | |||
| 226 | --- Get the namespace of a locally-installed rock, if any. | ||
| 227 | -- @param name string: The rock name, without a namespace. | ||
| 228 | -- @param version string: The rock version. | ||
| 229 | -- @param tree string: The local tree to use. | ||
| 230 | -- @return string?: The namespace if it exists, or nil. | ||
| 231 | function path.read_namespace(name: string, version: string, tree: string | Tree): string | ||
| 232 | assert(not name:match("/")) | ||
| 233 | |||
| 234 | local namespace: string | ||
| 235 | local fd = io.open(path.rock_namespace_file(name, version, tree), "r") | ||
| 236 | if fd then | ||
| 237 | namespace = fd:read("*a") | ||
| 238 | fd:close() | ||
| 239 | end | ||
| 240 | return namespace | ||
| 241 | end | ||
| 242 | |||
| 243 | function path.package_paths(deps_mode: string): string, string | ||
| 244 | local lpaths = {} | ||
| 245 | local lcpaths = {} | ||
| 246 | path.map_trees(deps_mode, function(tree: string | Tree) | ||
| 247 | local root = path.root_dir(tree) | ||
| 248 | table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?.lua")) | ||
| 249 | table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?/init.lua")) | ||
| 250 | table.insert(lcpaths, dir.path(root, cfg.lib_modules_path, "?." .. cfg.lib_extension)) | ||
| 251 | end) | ||
| 252 | return table.concat(lpaths, ";"), table.concat(lcpaths, ";") | ||
| 253 | end | ||
| 254 | |||
| 255 | return path | ||
diff --git a/src/luarocks/util.tl b/src/luarocks/util.tl index a8233f31..a9fc8394 100644 --- a/src/luarocks/util.tl +++ b/src/luarocks/util.tl | |||
| @@ -25,14 +25,57 @@ local record util | |||
| 25 | args: {any: any} | 25 | args: {any: any} |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | record Rockspec | 28 | record Source |
| 29 | name: string | 29 | url: string |
| 30 | version: string --? | 30 | end |
| 31 | |||
| 32 | record Description | ||
| 33 | summary: string | ||
| 34 | detailed: string | ||
| 35 | homepage: string | ||
| 36 | issues_url: string | ||
| 37 | maintainer: string | ||
| 38 | license: string | ||
| 39 | end | ||
| 40 | |||
| 41 | record Test | ||
| 42 | type: string | ||
| 43 | platforms: {{string: any}} | ||
| 44 | end | ||
| 45 | |||
| 46 | record Rockspec -- luarocks-dev-1.rockspec | ||
| 47 | rockspec_format: string | ||
| 48 | name: string --? package | ||
| 49 | version: string | ||
| 50 | source: {Source} | ||
| 51 | description: Description | ||
| 52 | test_dependencies: {string} | ||
| 53 | test: Test | ||
| 54 | end | ||
| 55 | |||
| 56 | record Parser --? | ||
| 57 | option: function(Parser, ...: string): Parser | ||
| 58 | argname: function(Parser, string): Parser | ||
| 59 | choices: function(Parser, {string}): Parser | ||
| 60 | flag: function(Parser, string): Parser | ||
| 61 | hidden: function(Parser, boolean): Parser | ||
| 31 | end | 62 | end |
| 32 | end | 63 | end |
| 33 | 64 | ||
| 65 | util.cleanup_path = core.cleanup_path | ||
| 66 | util.split_string = core.split_string | ||
| 67 | util.sortedpairs = core.sortedpairs | ||
| 68 | util.deep_merge = core.deep_merge | ||
| 69 | util.deep_merge_under = core.deep_merge_under | ||
| 70 | util.popen_read = core.popen_read | ||
| 71 | util.show_table = core.show_table | ||
| 72 | util.printerr = core.printerr | ||
| 73 | util.warning = core.warning | ||
| 74 | util.keys = core.keys | ||
| 75 | |||
| 34 | local type Fn = util.Fn | 76 | local type Fn = util.Fn |
| 35 | local type Rockspec = util.Rockspec | 77 | local type Rockspec = util.Rockspec |
| 78 | local type Parser = util.Parser | ||
| 36 | 79 | ||
| 37 | local scheduled_functions: {Fn} = {} --? infered from line 48-51 | 80 | local scheduled_functions: {Fn} = {} --? infered from line 48-51 |
| 38 | 81 | ||
| @@ -229,7 +272,7 @@ function util.format_rock_name(name: string, namespace: string, version: string) | |||
| 229 | return (namespace and namespace.."/" or "")..name..(version and " "..version or "") | 272 | return (namespace and namespace.."/" or "")..name..(version and " "..version or "") |
| 230 | end | 273 | end |
| 231 | 274 | ||
| 232 | function util.deps_mode_option(parser: {string: any}, program: string) --? type of parser | 275 | function util.deps_mode_option(parser: Parser, program: string) |
| 233 | local cfg = require("luarocks.core.cfg") | 276 | local cfg = require("luarocks.core.cfg") |
| 234 | 277 | ||
| 235 | parser:option("--deps-mode", "How to handle dependencies. Four modes are supported:\n".. | 278 | parser:option("--deps-mode", "How to handle dependencies. Four modes are supported:\n".. |
| @@ -286,7 +329,7 @@ local function collect_rockspecs(versions: {string: vers.Version}, paths: {strin | |||
| 286 | 329 | ||
| 287 | if fs.is_dir(subdir) then | 330 | if fs.is_dir(subdir) then |
| 288 | for file in fs.dir(subdir) do | 331 | for file in fs.dir(subdir) do |
| 289 | file = dir.path(subdir, file) -- path: function(...: string): string | 332 | file = dir.path(subdir, file) |
| 290 | 333 | ||
| 291 | if file:match("rockspec$") and fs.is_file(file) then | 334 | if file:match("rockspec$") and fs.is_file(file) then |
| 292 | local rock, version = path.parse_name(file) | 335 | local rock, version = path.parse_name(file) |
