aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:48:56 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commitd7b06bdc297d758e5dbf56086bda57358a1b40f2 (patch)
treeae85265103d8fd3ced7666c6d35eeff423a1254c /src
parentc083f3418dbaa8b354febf936fe08037a9514d40 (diff)
downloadluarocks-d7b06bdc297d758e5dbf56086bda57358a1b40f2.tar.gz
luarocks-d7b06bdc297d758e5dbf56086bda57358a1b40f2.tar.bz2
luarocks-d7b06bdc297d758e5dbf56086bda57358a1b40f2.zip
Teal: convert luarocks.rockspecs
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/rockspecs.tl (renamed from src/luarocks/rockspecs.lua)95
1 files changed, 48 insertions, 47 deletions
diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.tl
index 454bab77..15a28de0 100644
--- a/src/luarocks/rockspecs.lua
+++ b/src/luarocks/rockspecs.tl
@@ -1,4 +1,6 @@
1local rockspecs = {} 1
2local record rockspecs
3end
2 4
3local cfg = require("luarocks.core.cfg") 5local cfg = require("luarocks.core.cfg")
4local dir = require("luarocks.dir") 6local dir = require("luarocks.dir")
@@ -8,7 +10,12 @@ local type_rockspec = require("luarocks.type.rockspec")
8local util = require("luarocks.util") 10local util = require("luarocks.util")
9local vers = require("luarocks.core.vers") 11local vers = require("luarocks.core.vers")
10 12
11local vendored_build_type_set = { 13local type Rockspec = require("luarocks.core.types.rockspec").Rockspec
14local type Dependencies = require("luarocks.core.types.rockspec").Dependencies
15
16local type Query = require("luarocks.core.types.query").Query
17
18local vendored_build_type_set: {string: boolean} = {
12 ["builtin"] = true, 19 ["builtin"] = true,
13 ["cmake"] = true, 20 ["cmake"] = true,
14 ["command"] = true, 21 ["command"] = true,
@@ -17,14 +24,6 @@ local vendored_build_type_set = {
17 ["none"] = true, 24 ["none"] = true,
18} 25}
19 26
20local rockspec_mt = {}
21
22rockspec_mt.__index = rockspec_mt
23
24function rockspec_mt.type()
25 return "rockspec"
26end
27
28--- Perform platform-specific overrides on a table. 27--- Perform platform-specific overrides on a table.
29-- Overrides values of table with the contents of the appropriate 28-- Overrides values of table with the contents of the appropriate
30-- subset of its "platforms" field. The "platforms" field should 29-- subset of its "platforms" field. The "platforms" field should
@@ -38,15 +37,16 @@ end
38-- tbl.x are preserved). 37-- tbl.x are preserved).
39-- @param tbl table or nil: Table which may contain a "platforms" field; 38-- @param tbl table or nil: Table which may contain a "platforms" field;
40-- if it doesn't (or if nil is passed), this function does nothing. 39-- if it doesn't (or if nil is passed), this function does nothing.
41local function platform_overrides(tbl) 40local function platform_overrides(tbl?: {any: any})
42 assert(type(tbl) == "table" or not tbl)
43 41
44 if not tbl then return end 42 if not tbl then return end
45 43
46 if tbl.platforms then 44 local tblp = tbl.platforms
45
46 if tblp is {any: any} then
47 for platform in cfg.each_platform() do 47 for platform in cfg.each_platform() do
48 local platform_tbl = tbl.platforms[platform] 48 local platform_tbl = tblp[platform]
49 if platform_tbl then 49 if platform_tbl is {any: any} then
50 util.deep_merge(tbl, platform_tbl) 50 util.deep_merge(tbl, platform_tbl)
51 end 51 end
52 end 52 end
@@ -54,18 +54,16 @@ local function platform_overrides(tbl)
54 tbl.platforms = nil 54 tbl.platforms = nil
55end 55end
56 56
57local function convert_dependencies(rockspec, key) 57local function convert_dependencies(dependencies: Dependencies): boolean, string
58 if rockspec[key] then 58 local qs: {Query} = {}
59 for i = 1, #rockspec[key] do 59 for i = 1, #dependencies do
60 local parsed, err = queries.from_dep_string(rockspec[key][i]) 60 local parsed, err = queries.from_dep_string(dependencies[i])
61 if not parsed then 61 if not parsed then
62 return nil, "Parse error processing dependency '"..rockspec[key][i].."': "..tostring(err) 62 return nil, "Parse error processing dependency '"..dependencies[i].."': "..tostring(err)
63 end
64 rockspec[key][i] = parsed
65 end 63 end
66 else 64 qs[i] = parsed
67 rockspec[key] = {}
68 end 65 end
66 dependencies.queries = qs
69 return true 67 return true
70end 68end
71 69
@@ -73,8 +71,8 @@ end
73-- Create a "variables" table in the rockspec table, containing 71-- Create a "variables" table in the rockspec table, containing
74-- adjusted variables according to the configuration file. 72-- adjusted variables according to the configuration file.
75-- @param rockspec table: The rockspec table. 73-- @param rockspec table: The rockspec table.
76local function configure_paths(rockspec) 74local function configure_paths(rockspec: Rockspec)
77 local vars = {} 75 local vars: {string: string} = {}
78 for k,v in pairs(cfg.variables) do 76 for k,v in pairs(cfg.variables) do
79 vars[k] = v 77 vars[k] = v
80 end 78 end
@@ -88,11 +86,7 @@ local function configure_paths(rockspec)
88 rockspec.variables = vars 86 rockspec.variables = vars
89end 87end
90 88
91function rockspecs.from_persisted_table(filename, rockspec, globals, quick) 89function rockspecs.from_persisted_table(filename: string, rockspec: Rockspec, globals?: {string: any}, quick?: boolean): Rockspec, string
92 assert(type(rockspec) == "table")
93 assert(type(globals) == "table" or globals == nil)
94 assert(type(filename) == "string")
95 assert(type(quick) == "boolean" or quick == nil)
96 90
97 if rockspec.rockspec_format then 91 if rockspec.rockspec_format then
98 if vers.compare_versions(rockspec.rockspec_format, type_rockspec.rockspec_format) then 92 if vers.compare_versions(rockspec.rockspec_format, type_rockspec.rockspec_format) then
@@ -113,19 +107,19 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick)
113 -- @return boolean: true if rockspec format matches version or is newer, false otherwise. 107 -- @return boolean: true if rockspec format matches version or is newer, false otherwise.
114 do 108 do
115 local parsed_format = vers.parse_version(rockspec.rockspec_format or "1.0") 109 local parsed_format = vers.parse_version(rockspec.rockspec_format or "1.0")
116 rockspec.format_is_at_least = function(self, version) 110 rockspec.format_is_at_least = function(self: Rockspec, version: string): boolean
117 return parsed_format >= vers.parse_version(version) 111 return parsed_format >= vers.parse_version(version)
118 end 112 end
119 end 113 end
120 114
121 platform_overrides(rockspec.build) 115 platform_overrides(rockspec.build as {any : any}) --!
122 platform_overrides(rockspec.dependencies) 116 platform_overrides(rockspec.dependencies as {any : any})
123 platform_overrides(rockspec.build_dependencies) 117 platform_overrides(rockspec.build_dependencies as {any : any})
124 platform_overrides(rockspec.test_dependencies) 118 platform_overrides(rockspec.test_dependencies as {any : any})
125 platform_overrides(rockspec.external_dependencies) 119 platform_overrides(rockspec.external_dependencies as {any : any})
126 platform_overrides(rockspec.source) 120 platform_overrides(rockspec.source as {any : any})
127 platform_overrides(rockspec.hooks) 121 platform_overrides(rockspec.hooks as {any : any})
128 platform_overrides(rockspec.test) 122 platform_overrides(rockspec.test as {any : any})
129 123
130 rockspec.name = rockspec.package:lower() 124 rockspec.name = rockspec.package:lower()
131 125
@@ -145,9 +139,12 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick)
145 139
146 rockspec.rocks_provided = util.get_rocks_provided(rockspec) 140 rockspec.rocks_provided = util.get_rocks_provided(rockspec)
147 141
148 for _, key in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do 142 rockspec.dependencies = rockspec.dependencies or {}
149 local ok, err = convert_dependencies(rockspec, key) 143 rockspec.build_dependencies = rockspec.build_dependencies or {}
150 if not ok then 144 rockspec.test_dependencies = rockspec.test_dependencies or {}
145 for _, d in ipairs({rockspec.dependencies, rockspec.build_dependencies, rockspec.test_dependencies}) do
146 local _, err = convert_dependencies(d)
147 if err then
151 return nil, err 148 return nil, err
152 end 149 end
153 end 150 end
@@ -161,7 +158,7 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick)
161 end 158 end
162 159
163 local found = false 160 local found = false
164 for _, dep in ipairs(rockspec.build_dependencies) do 161 for _, dep in ipairs(rockspec.build_dependencies.queries) do
165 if dep.name == build_pkg_name then 162 if dep.name == build_pkg_name then
166 found = true 163 found = true
167 break 164 break
@@ -169,7 +166,11 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick)
169 end 166 end
170 167
171 if not found then 168 if not found then
172 table.insert(rockspec.build_dependencies, queries.from_dep_string(build_pkg_name)) 169 local query, errfromdep = queries.from_dep_string(build_pkg_name)
170 if errfromdep then
171 return nil, "Invalid dependency in rockspec: " .. errfromdep
172 end
173 table.insert(rockspec.build_dependencies.queries, query)
173 end 174 end
174 end 175 end
175 176
@@ -177,7 +178,7 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick)
177 configure_paths(rockspec) 178 configure_paths(rockspec)
178 end 179 end
179 180
180 return setmetatable(rockspec, rockspec_mt) 181 return rockspec
181end 182end
182 183
183return rockspecs 184return rockspecs