diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-07-05 13:32:16 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:49:17 +0300 |
commit | c28adae4adcd527ef66b74ba8f44faada734f2de (patch) | |
tree | 2fd68210f464f758ee351f52c65b2a2e3b16b9c9 | |
parent | 28063726da89cc684a3d7d05d96542e3d9f5018d (diff) | |
download | luarocks-c28adae4adcd527ef66b74ba8f44faada734f2de.tar.gz luarocks-c28adae4adcd527ef66b74ba8f44faada734f2de.tar.bz2 luarocks-c28adae4adcd527ef66b74ba8f44faada734f2de.zip |
take path out
-rw-r--r-- | src/luarocks/core/path-incomplete.lua (renamed from src/luarocks/core/path-original.lua) | 82 | ||||
-rw-r--r-- | src/luarocks/core/path.lua | 82 |
2 files changed, 82 insertions, 82 deletions
diff --git a/src/luarocks/core/path-original.lua b/src/luarocks/core/path-incomplete.lua index 2f037b41..59ab9c7f 100644 --- a/src/luarocks/core/path-original.lua +++ b/src/luarocks/core/path-incomplete.lua | |||
@@ -1,13 +1,15 @@ | |||
1 | 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 | ||
1 | 2 | ||
2 | --- Core LuaRocks-specific path handling functions. | ||
3 | local path = {} | 3 | local path = {} |
4 | 4 | ||
5 | |||
5 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
6 | local dir = require("luarocks.core.dir") | 7 | local dir = require("luarocks.core.dir") |
7 | local require = nil | 8 | |
9 | |||
8 | 10 | ||
9 | local dir_sep = package.config:sub(1, 1) | 11 | local dir_sep = package.config:sub(1, 1) |
10 | -------------------------------------------------------------------------------- | 12 | |
11 | 13 | ||
12 | function path.rocks_dir(tree) | 14 | function path.rocks_dir(tree) |
13 | if tree == nil then | 15 | if tree == nil then |
@@ -16,33 +18,30 @@ function path.rocks_dir(tree) | |||
16 | if type(tree) == "string" then | 18 | if type(tree) == "string" then |
17 | return dir.path(tree, cfg.rocks_subdir) | 19 | return dir.path(tree, cfg.rocks_subdir) |
18 | end | 20 | end |
19 | assert(type(tree) == "table") | ||
20 | return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) | 21 | return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) |
21 | end | 22 | end |
22 | 23 | ||
23 | --- Produce a versioned version of a filename. | 24 | |
24 | -- @param file string: filename (must start with prefix) | 25 | |
25 | -- @param prefix string: Path prefix for file | 26 | |
26 | -- @param name string: Rock name | 27 | |
27 | -- @param version string: Rock version | 28 | |
28 | -- @return string: a pathname with the same directory parts and a versioned basename. | 29 | |
29 | function path.versioned_name(file, prefix, name, version) | 30 | function path.versioned_name(file, prefix, name, version) |
30 | assert(type(file) == "string") | 31 | assert(not name:match(dir_sep)) |
31 | assert(type(name) == "string" and not name:match(dir_sep)) | ||
32 | assert(type(version) == "string") | ||
33 | 32 | ||
34 | local rest = file:sub(#prefix+1):gsub("^" .. dir_sep .. "*", "") | 33 | local rest = file:sub(#prefix + 1):gsub("^" .. dir_sep .. "*", "") |
35 | local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") | 34 | local name_version = (name .. "_" .. version):gsub("%-", "_"):gsub("%.", "_") |
36 | return dir.path(prefix, name_version.."-"..rest) | 35 | return dir.path(prefix, name_version .. "-" .. rest) |
37 | end | 36 | end |
38 | 37 | ||
39 | --- Convert a pathname to a module identifier. | 38 | |
40 | -- In Unix, for example, a path "foo/bar/baz.lua" is converted to | 39 | |
41 | -- "foo.bar.baz"; "bla/init.lua" returns "bla.init"; "foo.so" returns "foo". | 40 | |
42 | -- @param file string: Pathname of module | 41 | |
43 | -- @return string: The module identifier, or nil if given path is | 42 | |
44 | -- not a conformant module path (the function does not check if the | 43 | |
45 | -- path actually exists). | 44 | |
46 | function path.path_to_module(file) | 45 | function path.path_to_module(file) |
47 | assert(type(file) == "string") | 46 | assert(type(file) == "string") |
48 | 47 | ||
@@ -66,7 +65,7 @@ function path.path_to_module(file) | |||
66 | 65 | ||
67 | if not name then name = file end | 66 | if not name then name = file end |
68 | 67 | ||
69 | -- remove any beginning and trailing slashes-converted-to-dots | 68 | |
70 | name = name:gsub("^%.+", ""):gsub("%.+$", "") | 69 | name = name:gsub("^%.+", ""):gsub("%.+$", "") |
71 | 70 | ||
72 | return name | 71 | return name |
@@ -86,20 +85,20 @@ function path.deploy_lib_dir(tree) | |||
86 | return dir.path(tree, cfg.lib_modules_path) | 85 | return dir.path(tree, cfg.lib_modules_path) |
87 | else | 86 | else |
88 | assert(type(tree) == "table") | 87 | assert(type(tree) == "table") |
89 | return tree.lib_dir or dir.path(tree.root, cfg.lib_modules_path) | 88 | return tostring(tree.lib_dir) or dir.path(tree.root, cfg.lib_modules_path) |
90 | end | 89 | end |
91 | end | 90 | end |
92 | 91 | ||
93 | local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } | 92 | local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } |
94 | 93 | ||
95 | --- Return the pathname of the file that would be loaded for a module, indexed. | 94 | |
96 | -- @param file_name string: module file name as in manifest (eg. "socket/core.so") | 95 | |
97 | -- @param name string: name of the package (eg. "luasocket") | 96 | |
98 | -- @param version string: version number (eg. "2.0.2-1") | 97 | |
99 | -- @param tree string: repository path (eg. "/usr/local") | 98 | |
100 | -- @param i number: the index, 1 if version is the current default, > 1 otherwise. | 99 | |
101 | -- This is done this way for use by select_module in luarocks.loader. | 100 | |
102 | -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") | 101 | |
103 | function path.which_i(file_name, name, version, tree, i) | 102 | function path.which_i(file_name, name, version, tree, i) |
104 | local deploy_dir | 103 | local deploy_dir |
105 | local extension = file_name:match("%.[a-z]+$") | 104 | local extension = file_name:match("%.[a-z]+$") |
@@ -120,18 +119,17 @@ function path.rocks_tree_to_string(tree) | |||
120 | if type(tree) == "string" then | 119 | if type(tree) == "string" then |
121 | return tree | 120 | return tree |
122 | else | 121 | else |
123 | assert(type(tree) == "table") | 122 | return tostring(tree.root) |
124 | return tree.root | ||
125 | end | 123 | end |
126 | end | 124 | end |
127 | 125 | ||
128 | --- Apply a given function to the active rocks trees based on chosen dependency mode. | 126 | |
129 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 127 | |
130 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 128 | |
131 | -- "none" for no trees (this function becomes a nop). | 129 | |
132 | -- @param fn function: function to be applied, with the tree dir (string) as the first | 130 | |
133 | -- argument and the remaining varargs of map_trees as the following arguments. | 131 | |
134 | -- @return a table with all results of invocations of fn collected. | 132 | |
135 | function path.map_trees(deps_mode, fn, ...) | 133 | function path.map_trees(deps_mode, fn, ...) |
136 | local result = {} | 134 | local result = {} |
137 | local current = cfg.root_dir or cfg.rocks_trees[1] | 135 | local current = cfg.root_dir or cfg.rocks_trees[1] |
diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index 59ab9c7f..2f037b41 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua | |||
@@ -1,15 +1,13 @@ | |||
1 | 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 | ||
2 | 1 | ||
2 | --- Core LuaRocks-specific path handling functions. | ||
3 | local path = {} | 3 | local path = {} |
4 | 4 | ||
5 | |||
6 | local cfg = require("luarocks.core.cfg") | 5 | local cfg = require("luarocks.core.cfg") |
7 | local dir = require("luarocks.core.dir") | 6 | local dir = require("luarocks.core.dir") |
8 | 7 | local require = nil | |
9 | |||
10 | 8 | ||
11 | local dir_sep = package.config:sub(1, 1) | 9 | local dir_sep = package.config:sub(1, 1) |
12 | 10 | -------------------------------------------------------------------------------- | |
13 | 11 | ||
14 | function path.rocks_dir(tree) | 12 | function path.rocks_dir(tree) |
15 | if tree == nil then | 13 | if tree == nil then |
@@ -18,30 +16,33 @@ function path.rocks_dir(tree) | |||
18 | if type(tree) == "string" then | 16 | if type(tree) == "string" then |
19 | return dir.path(tree, cfg.rocks_subdir) | 17 | return dir.path(tree, cfg.rocks_subdir) |
20 | end | 18 | end |
19 | assert(type(tree) == "table") | ||
21 | return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) | 20 | return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) |
22 | end | 21 | end |
23 | 22 | ||
24 | 23 | --- Produce a versioned version of a filename. | |
25 | 24 | -- @param file string: filename (must start with prefix) | |
26 | 25 | -- @param prefix string: Path prefix for file | |
27 | 26 | -- @param name string: Rock name | |
28 | 27 | -- @param version string: Rock version | |
29 | 28 | -- @return string: a pathname with the same directory parts and a versioned basename. | |
30 | function path.versioned_name(file, prefix, name, version) | 29 | function path.versioned_name(file, prefix, name, version) |
31 | assert(not name:match(dir_sep)) | 30 | assert(type(file) == "string") |
31 | assert(type(name) == "string" and not name:match(dir_sep)) | ||
32 | assert(type(version) == "string") | ||
32 | 33 | ||
33 | local rest = file:sub(#prefix + 1):gsub("^" .. dir_sep .. "*", "") | 34 | local rest = file:sub(#prefix+1):gsub("^" .. dir_sep .. "*", "") |
34 | local name_version = (name .. "_" .. version):gsub("%-", "_"):gsub("%.", "_") | 35 | local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") |
35 | return dir.path(prefix, name_version .. "-" .. rest) | 36 | return dir.path(prefix, name_version.."-"..rest) |
36 | end | 37 | end |
37 | 38 | ||
38 | 39 | --- Convert a pathname to a module identifier. | |
39 | 40 | -- In Unix, for example, a path "foo/bar/baz.lua" is converted to | |
40 | 41 | -- "foo.bar.baz"; "bla/init.lua" returns "bla.init"; "foo.so" returns "foo". | |
41 | 42 | -- @param file string: Pathname of module | |
42 | 43 | -- @return string: The module identifier, or nil if given path is | |
43 | 44 | -- not a conformant module path (the function does not check if the | |
44 | 45 | -- path actually exists). | |
45 | function path.path_to_module(file) | 46 | function path.path_to_module(file) |
46 | assert(type(file) == "string") | 47 | assert(type(file) == "string") |
47 | 48 | ||
@@ -65,7 +66,7 @@ function path.path_to_module(file) | |||
65 | 66 | ||
66 | if not name then name = file end | 67 | if not name then name = file end |
67 | 68 | ||
68 | 69 | -- remove any beginning and trailing slashes-converted-to-dots | |
69 | name = name:gsub("^%.+", ""):gsub("%.+$", "") | 70 | name = name:gsub("^%.+", ""):gsub("%.+$", "") |
70 | 71 | ||
71 | return name | 72 | return name |
@@ -85,20 +86,20 @@ function path.deploy_lib_dir(tree) | |||
85 | return dir.path(tree, cfg.lib_modules_path) | 86 | return dir.path(tree, cfg.lib_modules_path) |
86 | else | 87 | else |
87 | assert(type(tree) == "table") | 88 | assert(type(tree) == "table") |
88 | return tostring(tree.lib_dir) or dir.path(tree.root, cfg.lib_modules_path) | 89 | return tree.lib_dir or dir.path(tree.root, cfg.lib_modules_path) |
89 | end | 90 | end |
90 | end | 91 | end |
91 | 92 | ||
92 | local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } | 93 | local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } |
93 | 94 | ||
94 | 95 | --- Return the pathname of the file that would be loaded for a module, indexed. | |
95 | 96 | -- @param file_name string: module file name as in manifest (eg. "socket/core.so") | |
96 | 97 | -- @param name string: name of the package (eg. "luasocket") | |
97 | 98 | -- @param version string: version number (eg. "2.0.2-1") | |
98 | 99 | -- @param tree string: repository path (eg. "/usr/local") | |
99 | 100 | -- @param i number: the index, 1 if version is the current default, > 1 otherwise. | |
100 | 101 | -- This is done this way for use by select_module in luarocks.loader. | |
101 | 102 | -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") | |
102 | function path.which_i(file_name, name, version, tree, i) | 103 | function path.which_i(file_name, name, version, tree, i) |
103 | local deploy_dir | 104 | local deploy_dir |
104 | local extension = file_name:match("%.[a-z]+$") | 105 | local extension = file_name:match("%.[a-z]+$") |
@@ -119,17 +120,18 @@ function path.rocks_tree_to_string(tree) | |||
119 | if type(tree) == "string" then | 120 | if type(tree) == "string" then |
120 | return tree | 121 | return tree |
121 | else | 122 | else |
122 | return tostring(tree.root) | 123 | assert(type(tree) == "table") |
124 | return tree.root | ||
123 | end | 125 | end |
124 | end | 126 | end |
125 | 127 | ||
126 | 128 | --- Apply a given function to the active rocks trees based on chosen dependency mode. | |
127 | 129 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | |
128 | 130 | -- "all" for all trees, "order" for all trees with priority >= the current default, | |
129 | 131 | -- "none" for no trees (this function becomes a nop). | |
130 | 132 | -- @param fn function: function to be applied, with the tree dir (string) as the first | |
131 | 133 | -- argument and the remaining varargs of map_trees as the following arguments. | |
132 | 134 | -- @return a table with all results of invocations of fn collected. | |
133 | function path.map_trees(deps_mode, fn, ...) | 135 | function path.map_trees(deps_mode, fn, ...) |
134 | local result = {} | 136 | local result = {} |
135 | local current = cfg.root_dir or cfg.rocks_trees[1] | 137 | local current = cfg.root_dir or cfg.rocks_trees[1] |