diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-13 20:19:43 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-13 20:19:43 +0300 |
commit | c7b03dea26827e1d526d06e7f5c3b8b86ce1fe05 (patch) | |
tree | 46b5e4f5e6cd81eb49220a77c8c1722831137e10 | |
parent | 2ab89328bd35d20e4ef990934abf8382adc95b82 (diff) | |
download | luarocks-c7b03dea26827e1d526d06e7f5c3b8b86ce1fe05.tar.gz luarocks-c7b03dea26827e1d526d06e7f5c3b8b86ce1fe05.tar.bz2 luarocks-c7b03dea26827e1d526d06e7f5c3b8b86ce1fe05.zip |
writer
-rw-r--r-- | src/luarocks/manif/writer.tl | 54 | ||||
-rw-r--r-- | src/luarocks/repo_writer.tl | 52 |
2 files changed, 76 insertions, 30 deletions
diff --git a/src/luarocks/manif/writer.tl b/src/luarocks/manif/writer.tl index ee4144e0..0461b230 100644 --- a/src/luarocks/manif/writer.tl +++ b/src/luarocks/manif/writer.tl | |||
@@ -16,6 +16,12 @@ local persist = require("luarocks.persist") | |||
16 | local manif = require("luarocks.manif") | 16 | local manif = require("luarocks.manif") |
17 | local queries = require("luarocks.queries") | 17 | local queries = require("luarocks.queries") |
18 | 18 | ||
19 | local type m = require("luarocks.core.types.manifest") | ||
20 | local type Manifest = m.Manifest | ||
21 | |||
22 | local type r = require("luarocks.core.types.rockspec") | ||
23 | local type Rockspec = r.Rockspec | ||
24 | |||
19 | --- Update storage table to account for items provided by a package. | 25 | --- Update storage table to account for items provided by a package. |
20 | -- @param storage table: a table storing items in the following format: | 26 | -- @param storage table: a table storing items in the following format: |
21 | -- keys are item names and values are arrays of packages providing each item, | 27 | -- keys are item names and values are arrays of packages providing each item, |
@@ -23,15 +29,12 @@ local queries = require("luarocks.queries") | |||
23 | -- @param items table: a table mapping item names to paths. | 29 | -- @param items table: a table mapping item names to paths. |
24 | -- @param name string: package name. | 30 | -- @param name string: package name. |
25 | -- @param version string: package version. | 31 | -- @param version string: package version. |
26 | local function store_package_items(storage, name, version, items) | 32 | local function store_package_items(storage: {string: {string}}, name: string, version: string, items: {string: string}) |
27 | assert(type(storage) == "table") | 33 | assert(not name:match("/")) |
28 | assert(type(items) == "table") | ||
29 | assert(type(name) == "string" and not name:match("/")) | ||
30 | assert(type(version) == "string") | ||
31 | 34 | ||
32 | local package_identifier = name.."/"..version | 35 | local package_identifier = name.."/"..version |
33 | 36 | ||
34 | for item_name, path in pairs(items) do -- luacheck: ignore 431 | 37 | for item_name, _ in pairs(items) do -- luacheck: ignore 431 |
35 | if not storage[item_name] then | 38 | if not storage[item_name] then |
36 | storage[item_name] = {} | 39 | storage[item_name] = {} |
37 | end | 40 | end |
@@ -47,15 +50,12 @@ end | |||
47 | -- @param items table: a table mapping item names to paths. | 50 | -- @param items table: a table mapping item names to paths. |
48 | -- @param name string: package name. | 51 | -- @param name string: package name. |
49 | -- @param version string: package version. | 52 | -- @param version string: package version. |
50 | local function remove_package_items(storage, name, version, items) | 53 | local function remove_package_items(storage: {string: {string}}, name: string, version: string, items: {string: string}) |
51 | assert(type(storage) == "table") | 54 | assert(not name:match("/")) |
52 | assert(type(items) == "table") | ||
53 | assert(type(name) == "string" and not name:match("/")) | ||
54 | assert(type(version) == "string") | ||
55 | 55 | ||
56 | local package_identifier = name.."/"..version | 56 | local package_identifier = name.."/"..version |
57 | 57 | ||
58 | for item_name, path in pairs(items) do -- luacheck: ignore 431 | 58 | for item_name, _ in pairs(items) do -- luacheck: ignore 431 |
59 | local key = item_name | 59 | local key = item_name |
60 | local all_identifiers = storage[key] | 60 | local all_identifiers = storage[key] |
61 | if not all_identifiers then | 61 | if not all_identifiers then |
@@ -88,7 +88,7 @@ end | |||
88 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 88 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
89 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 89 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
90 | -- "none" for no trees. | 90 | -- "none" for no trees. |
91 | local function update_dependencies(manifest, deps_mode) | 91 | local function update_dependencies(manifest: Manifest, deps_mode: string) |
92 | assert(type(manifest) == "table") | 92 | assert(type(manifest) == "table") |
93 | assert(type(deps_mode) == "string") | 93 | assert(type(deps_mode) == "string") |
94 | 94 | ||
@@ -118,10 +118,7 @@ end | |||
118 | -- @param b string: Version to compare. | 118 | -- @param b string: Version to compare. |
119 | -- @return boolean: The comparison result, according to the | 119 | -- @return boolean: The comparison result, according to the |
120 | -- rule outlined above. | 120 | -- rule outlined above. |
121 | local function sort_pkgs(a, b) | 121 | local function sort_pkgs(a: string, b: string): boolean |
122 | assert(type(a) == "string") | ||
123 | assert(type(b) == "string") | ||
124 | |||
125 | local na, va = a:match("(.*)/(.*)$") | 122 | local na, va = a:match("(.*)/(.*)$") |
126 | local nb, vb = b:match("(.*)/(.*)$") | 123 | local nb, vb = b:match("(.*)/(.*)$") |
127 | 124 | ||
@@ -131,15 +128,14 @@ end | |||
131 | --- Sort items of a package matching table by version number (higher versions first). | 128 | --- Sort items of a package matching table by version number (higher versions first). |
132 | -- @param tbl table: the package matching table: keys should be strings | 129 | -- @param tbl table: the package matching table: keys should be strings |
133 | -- and values arrays of strings with packages names in "name/version" format. | 130 | -- and values arrays of strings with packages names in "name/version" format. |
134 | local function sort_package_matching_table(tbl) | 131 | local function sort_package_matching_table(tbl: {string: {string}}) |
135 | assert(type(tbl) == "table") | ||
136 | 132 | ||
137 | if next(tbl) then | 133 | if next(tbl) ~= nil then |
138 | for item, pkgs in pairs(tbl) do | 134 | for item, pkgs in pairs(tbl) do |
139 | if #pkgs > 1 then | 135 | if #pkgs > 1 then |
140 | table.sort(pkgs, sort_pkgs) | 136 | table.sort(pkgs, sort_pkgs) |
141 | -- Remove duplicates from the sorted array. | 137 | -- Remove duplicates from the sorted array. |
142 | local prev = nil | 138 | local prev: string = nil |
143 | local i = 1 | 139 | local i = 1 |
144 | while pkgs[i] do | 140 | while pkgs[i] do |
145 | local curr = pkgs[i] | 141 | local curr = pkgs[i] |
@@ -161,26 +157,24 @@ end | |||
161 | -- @param lua_version string or nil: filter by Lua version | 157 | -- @param lua_version string or nil: filter by Lua version |
162 | -- @param repodir string: directory of repository being scanned | 158 | -- @param repodir string: directory of repository being scanned |
163 | -- @param cache table: temporary rockspec cache table | 159 | -- @param cache table: temporary rockspec cache table |
164 | local function filter_by_lua_version(manifest, lua_version, repodir, cache) | 160 | local function filter_by_lua_version(manifest: Manifest, lua_version_str: string, repodir: string, cache: {string: Rockspec}) |
165 | assert(type(manifest) == "table") | ||
166 | assert(type(repodir) == "string") | ||
167 | assert((not cache) or type(cache) == "table") | ||
168 | 161 | ||
169 | cache = cache or {} | 162 | cache = cache or {} |
170 | lua_version = vers.parse_version(lua_version) | 163 | local lua_version = vers.parse_version(lua_version_str) |
171 | for pkg, versions in pairs(manifest.repository) do | 164 | for pkg, versions in pairs(manifest.repository) do |
172 | local to_remove = {} | 165 | local to_remove: {string} = {} |
173 | for version, repositories in pairs(versions) do | 166 | for version, repositories in pairs(versions) do |
174 | for _, repo in ipairs(repositories) do | 167 | for _, repo in ipairs(repositories) do |
175 | if repo.arch == "rockspec" then | 168 | if repo.arch == "rockspec" then |
176 | local pathname = dir.path(repodir, pkg.."-"..version..".rockspec") | 169 | local pathname = dir.path(repodir, pkg.."-"..version..".rockspec") |
177 | local rockspec, err = cache[pathname] | 170 | local rockspec = cache[pathname] |
171 | local err: string | ||
178 | if not rockspec then | 172 | if not rockspec then |
179 | rockspec, err = fetch.load_local_rockspec(pathname, true) | 173 | rockspec, err = fetch.load_local_rockspec(pathname, true) |
180 | end | 174 | end |
181 | if rockspec then | 175 | if rockspec then |
182 | cache[pathname] = rockspec | 176 | cache[pathname] = rockspec |
183 | for _, dep in ipairs(rockspec.dependencies) do | 177 | for _, dep in ipairs(rockspec.dependencies.queries) do |
184 | if dep.name == "lua" then | 178 | if dep.name == "lua" then |
185 | if not vers.match_constraints(lua_version, dep.constraints) then | 179 | if not vers.match_constraints(lua_version, dep.constraints) then |
186 | table.insert(to_remove, version) | 180 | table.insert(to_remove, version) |
@@ -194,7 +188,7 @@ local function filter_by_lua_version(manifest, lua_version, repodir, cache) | |||
194 | end | 188 | end |
195 | end | 189 | end |
196 | end | 190 | end |
197 | if next(to_remove) then | 191 | if next(to_remove) ~= nil then |
198 | for _, incompat in ipairs(to_remove) do | 192 | for _, incompat in ipairs(to_remove) do |
199 | versions[incompat] = nil | 193 | versions[incompat] = nil |
200 | end | 194 | end |
diff --git a/src/luarocks/repo_writer.tl b/src/luarocks/repo_writer.tl new file mode 100644 index 00000000..698af976 --- /dev/null +++ b/src/luarocks/repo_writer.tl | |||
@@ -0,0 +1,52 @@ | |||
1 | local repo_writer = {} | ||
2 | |||
3 | local fs = require("luarocks.fs") | ||
4 | local path = require("luarocks.path") | ||
5 | local repos = require("luarocks.repos") | ||
6 | local writer = require("luarocks.manif.writer") | ||
7 | |||
8 | function repo_writer.deploy_files(name, version, wrap_bin_scripts, deps_mode, namespace) | ||
9 | local ok, err | ||
10 | |||
11 | if not fs.exists(path.rock_manifest_file(name, version)) then | ||
12 | ok, err = writer.make_rock_manifest(name, version) | ||
13 | if err then | ||
14 | return nil, err | ||
15 | end | ||
16 | end | ||
17 | |||
18 | if namespace then | ||
19 | ok, err = writer.make_namespace_file(name, version, namespace) | ||
20 | if not ok then | ||
21 | return nil, err | ||
22 | end | ||
23 | end | ||
24 | |||
25 | ok, err = repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | ||
26 | if not ok then | ||
27 | return nil, err | ||
28 | end | ||
29 | |||
30 | ok, err = writer.add_to_manifest(name, version, nil, deps_mode) | ||
31 | return ok, err | ||
32 | end | ||
33 | |||
34 | function repo_writer.delete_version(name, version, deps_mode, quick) | ||
35 | local ok, err, op = repos.delete_local_version(name, version, deps_mode, quick) | ||
36 | |||
37 | if op == "remove" then | ||
38 | local rok, rerr = writer.remove_from_manifest(name, version, nil, deps_mode) | ||
39 | if ok and not rok then | ||
40 | ok, err = rok, rerr | ||
41 | end | ||
42 | end | ||
43 | |||
44 | return ok, err | ||
45 | end | ||
46 | |||
47 | function repo_writer.refresh_manifest(rocks_dir) | ||
48 | return writer.make_manifest(rocks_dir, "one") | ||
49 | end | ||
50 | |||
51 | return repo_writer | ||
52 | |||