aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-04 14:28:12 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:51:31 +0300
commit151d06b9e19f2664e23787bf60ea46bf62cc87f2 (patch)
treedaa6f596e170bd40be66e4abbb91419d41333241
parent509d553d5d6003a92add3b7b30af02171280c052 (diff)
downloadluarocks-151d06b9e19f2664e23787bf60ea46bf62cc87f2.tar.gz
luarocks-151d06b9e19f2664e23787bf60ea46bf62cc87f2.tar.bz2
luarocks-151d06b9e19f2664e23787bf60ea46bf62cc87f2.zip
type_check and rockspec
-rw-r--r--src/luarocks/type/rockspec.tl352
-rw-r--r--src/luarocks/type_check.tl2
2 files changed, 253 insertions, 101 deletions
diff --git a/src/luarocks/type/rockspec.tl b/src/luarocks/type/rockspec.tl
index 4b9aecf9..365f5d3d 100644
--- a/src/luarocks/type/rockspec.tl
+++ b/src/luarocks/type/rockspec.tl
@@ -1,8 +1,11 @@
1local record type_rockspec 1local record type_rockspec
2 2 order: util.Ordering<string>
3end 3end
4 4
5local type_check = require("luarocks.type_check") 5local type_check = require("luarocks.type_check")
6local util = require("luarocks.core.util") --!
7
8local type TableSchema = type_check.TableSchema
6 9
7type_rockspec.rockspec_format = "3.0" 10type_rockspec.rockspec_format = "3.0"
8 11
@@ -19,121 +22,271 @@ type_rockspec.rockspec_format = "3.0"
19-- _more (boolean) indicates that the table accepts unspecified keys and does not type-check them. 22-- _more (boolean) indicates that the table accepts unspecified keys and does not type-check them.
20-- Any other string keys that don't start with an underscore represent known keys and are type-checking tables, recursively checked. 23-- Any other string keys that don't start with an underscore represent known keys and are type-checking tables, recursively checked.
21 24
25-- local rockspec_formats, versions = type_check.declare_schemas({
26-- ["1.0"] = {
27-- rockspec_format = { _type = "string" },
28-- package = { _type = "string", _mandatory = true },
29-- version = { _type = "string", _pattern = "[%w.]+-[%d]+", _mandatory = true },
30-- description = {
31-- summary = { _type = "string" },
32-- detailed = { _type = "string" },
33-- homepage = { _type = "string" },
34-- license = { _type = "string" },
35-- maintainer = { _type = "string" },
36-- },
37-- dependencies = {
38-- platforms = type_check.MAGIC_PLATFORMS,
39-- _any = {
40-- _type = "string",
41-- _name = "a valid dependency string",
42-- _pattern = "%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
43-- },
44-- },
45-- supported_platforms = {
46-- _any = { _type = "string" },
47-- },
48-- external_dependencies = {
49-- platforms = type_check.MAGIC_PLATFORMS,
50-- _any = {
51-- program = { _type = "string" },
52-- header = { _type = "string" },
53-- library = { _type = "string" },
54-- }
55-- },
56-- source = {
57-- _mandatory = true,
58-- platforms = type_check.MAGIC_PLATFORMS,
59-- url = { _type = "string", _mandatory = true },
60-- md5 = { _type = "string" },
61-- file = { _type = "string" },
62-- dir = { _type = "string" },
63-- tag = { _type = "string" },
64-- branch = { _type = "string" },
65-- module = { _type = "string" },
66-- cvs_tag = { _type = "string" },
67-- cvs_module = { _type = "string" },
68-- },
69-- build = {
70-- platforms = type_check.MAGIC_PLATFORMS,
71-- type = { _type = "string" },
72-- install = {
73-- lua = {
74-- _more = true
75-- },
76-- lib = {
77-- _more = true
78-- },
79-- conf = {
80-- _more = true
81-- },
82-- bin = {
83-- _more = true
84-- }
85-- },
86-- copy_directories = {
87-- _any = { _type = "string" },
88-- },
89-- _more = true,
90-- _mandatory = true
91-- },
92-- hooks = {
93-- platforms = type_check.MAGIC_PLATFORMS,
94-- post_install = { _type = "string" },
95-- },
96-- },
97
98-- ["1.1"] = {
99-- deploy = {
100-- wrap_bin_scripts = { _type = "boolean" },
101-- }
102-- },
103
104-- ["3.0"] = {
105-- description = {
106-- labels = {
107-- _any = { _type = "string" }
108-- },
109-- issues_url = { _type = "string" },
110-- },
111-- dependencies = {
112-- _any = {
113-- _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
114-- },
115-- },
116-- build_dependencies = {
117-- platforms = type_check.MAGIC_PLATFORMS,
118-- _any = {
119-- _type = "string",
120-- _name = "a valid dependency string",
121-- _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
122-- },
123-- },
124-- test_dependencies = {
125-- platforms = type_check.MAGIC_PLATFORMS,
126-- _any = {
127-- _type = "string",
128-- _name = "a valid dependency string",
129-- _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
130-- },
131-- },
132-- build = {
133-- _mandatory = false,
134-- },
135-- test = {
136-- platforms = type_check.MAGIC_PLATFORMS,
137-- type = { _type = "string" },
138-- _more = true,
139-- },
140-- }
141-- })
142
22local rockspec_formats, versions = type_check.declare_schemas({ 143local rockspec_formats, versions = type_check.declare_schemas({
23 ["1.0"] = { 144 ["1.0"] = {
24 rockspec_format = { _type = "string" }, 145 fields = {
25 package = { _type = "string", _mandatory = true }, 146 rockspec_format = { _type = "string" },
26 version = { _type = "string", _pattern = "[%w.]+-[%d]+", _mandatory = true }, 147 package = { _type = "string", _mandatory = true },
27 description = { 148 version = { _type = "string", _pattern = "[%w.]+-[%d]+", _mandatory = true },
28 summary = { _type = "string" }, 149 description = {
29 detailed = { _type = "string" }, 150 fields = {
30 homepage = { _type = "string" }, 151 summary = { _type = "string" },
31 license = { _type = "string" }, 152 detailed = { _type = "string" },
32 maintainer = { _type = "string" }, 153 homepage = { _type = "string" },
33 }, 154 license = { _type = "string" },
34 dependencies = { 155 maintainer = { _type = "string" },
35 platforms = type_check.MAGIC_PLATFORMS,
36 _any = {
37 _type = "string",
38 _name = "a valid dependency string",
39 _pattern = "%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
40 },
41 },
42 supported_platforms = {
43 _any = { _type = "string" },
44 },
45 external_dependencies = {
46 platforms = type_check.MAGIC_PLATFORMS,
47 _any = {
48 program = { _type = "string" },
49 header = { _type = "string" },
50 library = { _type = "string" },
51 }
52 },
53 source = {
54 _mandatory = true,
55 platforms = type_check.MAGIC_PLATFORMS,
56 url = { _type = "string", _mandatory = true },
57 md5 = { _type = "string" },
58 file = { _type = "string" },
59 dir = { _type = "string" },
60 tag = { _type = "string" },
61 branch = { _type = "string" },
62 module = { _type = "string" },
63 cvs_tag = { _type = "string" },
64 cvs_module = { _type = "string" },
65 },
66 build = {
67 platforms = type_check.MAGIC_PLATFORMS,
68 type = { _type = "string" },
69 install = {
70 lua = {
71 _more = true
72 }, 156 },
73 lib = { 157 },
74 _more = true 158 dependencies = {
159 fields = {
160 platforms = type_check.MAGIC_PLATFORMS,
75 }, 161 },
76 conf = { 162 _any = {
77 _more = true 163 _type = "string",
164 _name = "a valid dependency string",
165 _pattern = "%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
78 }, 166 },
79 bin = {
80 _more = true
81 }
82 }, 167 },
83 copy_directories = { 168 supported_platforms = {
84 _any = { _type = "string" }, 169 _any = { _type = "string" },
85 }, 170 },
86 _more = true, 171 external_dependencies = {
87 _mandatory = true 172 fields = {
88 }, 173 platforms = type_check.MAGIC_PLATFORMS,
89 hooks = { 174 },
90 platforms = type_check.MAGIC_PLATFORMS, 175 _any = {
91 post_install = { _type = "string" }, 176 fields = {
177 program = { _type = "string" },
178 header = { _type = "string" },
179 library = { _type = "string" },
180 }
181 },
182 },
183 source = {
184 _mandatory = true,
185 fields = {
186 platforms = type_check.MAGIC_PLATFORMS,
187 url = { _type = "string", _mandatory = true },
188 md5 = { _type = "string" },
189 file = { _type = "string" },
190 dir = { _type = "string" },
191 tag = { _type = "string" },
192 branch = { _type = "string" },
193 module = { _type = "string" },
194 cvs_tag = { _type = "string" },
195 cvs_module = { _type = "string" },
196 },
197 },
198 build = {
199 fields = {
200 platforms = type_check.MAGIC_PLATFORMS,
201 type = { _type = "string" },
202 install = {
203 fields = {
204 lua = {
205 _more = true
206 },
207 lib = {
208 _more = true
209 },
210 conf = {
211 _more = true
212 },
213 bin = {
214 _more = true
215 }
216 }
217 },
218 copy_directories = {
219 _any = { _type = "string" },
220 },
221 },
222 _more = true,
223 _mandatory = true
224 },
225 hooks = {
226 fields = {
227 platforms = type_check.MAGIC_PLATFORMS,
228 post_install = { _type = "string" },
229 }
230 },
92 }, 231 },
93 }, 232 },
94 233
95 ["1.1"] = { 234 ["1.1"] = {
96 deploy = { 235 fields = {
97 wrap_bin_scripts = { _type = "boolean" }, 236 deploy = {
98 } 237 fields = {
238 wrap_bin_scripts = { _type = "boolean" },
239 },
240 }
241 },
99 }, 242 },
100 243
101 ["3.0"] = { 244 ["3.0"] = {
102 description = { 245 fields = {
103 labels = { 246 description = {
104 _any = { _type = "string" } 247 fields = {
248 labels = {
249 _any = { _type = "string" }
250 },
251 issues_url = { _type = "string" },
252 },
105 }, 253 },
106 issues_url = { _type = "string" }, 254 dependencies = {
107 }, 255 _any = {
108 dependencies = { 256 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
109 _any = { 257 },
110 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
111 }, 258 },
112 }, 259 build_dependencies = {
113 build_dependencies = { 260 fields = {
114 platforms = type_check.MAGIC_PLATFORMS, 261 platforms = type_check.MAGIC_PLATFORMS,
115 _any = { 262 },
116 _type = "string", 263 _any = {
117 _name = "a valid dependency string", 264 _type = "string",
118 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", 265 _name = "a valid dependency string",
266 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
267 },
119 }, 268 },
120 }, 269 test_dependencies = {
121 test_dependencies = { 270 fields = {
122 platforms = type_check.MAGIC_PLATFORMS, 271 platforms = type_check.MAGIC_PLATFORMS,
123 _any = { 272 },
124 _type = "string", 273 _any = {
125 _name = "a valid dependency string", 274 _type = "string",
126 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", 275 _name = "a valid dependency string",
276 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
277 },
127 }, 278 },
128 }, 279 build = {
129 build = { 280 _mandatory = false,
130 _mandatory = false, 281 },
131 }, 282 test = {
132 test = { 283 fields = {
133 platforms = type_check.MAGIC_PLATFORMS, 284 platforms = type_check.MAGIC_PLATFORMS,
134 type = { _type = "string" }, 285 type = { _type = "string" },
135 _more = true, 286 },
136 }, 287 _more = true,
288 },
289 }
137 } 290 }
138}) 291})
139 292
@@ -167,7 +320,7 @@ type_rockspec.order = {
167 } 320 }
168} 321}
169 322
170local function check_rockspec_using_version(rockspec, globals, version) 323local function check_rockspec_using_version(rockspec: {any: any}, globals: {string: any}, version: string): boolean, string
171 local schema = rockspec_formats[version] 324 local schema = rockspec_formats[version]
172 if not schema then 325 if not schema then
173 return nil, "unknown rockspec format " .. version 326 return nil, "unknown rockspec format " .. version
@@ -189,8 +342,7 @@ end
189-- mismatches. 342-- mismatches.
190-- @return boolean or (nil, string): true if type checking 343-- @return boolean or (nil, string): true if type checking
191-- succeeded, or nil and an error message if it failed. 344-- succeeded, or nil and an error message if it failed.
192function type_rockspec.check(rockspec, globals) 345function type_rockspec.check(rockspec: {any: any}, globals: {string: any}): boolean, string
193 assert(type(rockspec) == "table")
194 346
195 local version = rockspec.rockspec_format or "1.0" 347 local version = rockspec.rockspec_format or "1.0"
196 local ok, err = check_rockspec_using_version(rockspec, globals, version) 348 local ok, err = check_rockspec_using_version(rockspec, globals, version)
diff --git a/src/luarocks/type_check.tl b/src/luarocks/type_check.tl
index d36debc4..1ff490b8 100644
--- a/src/luarocks/type_check.tl
+++ b/src/luarocks/type_check.tl
@@ -207,7 +207,7 @@ function type_check.type_check_table(version: string, tbl: {any: any}, typetbl:
207 return true 207 return true
208end 208end
209 209
210function type_check.check_undeclared_globals(globals: {string: any}, typetbl: {string: string}): boolean, string --! tbl and typetbl types 210function type_check.check_undeclared_globals(globals: {string: any}, typetbl: TableSchema): boolean, string --! tbl and typetbl types
211 local undeclared = {} 211 local undeclared = {}
212 for glob, _ in pairs(globals) do 212 for glob, _ in pairs(globals) do
213 if not (typetbl[glob] or typetbl["MUST_"..glob]) then 213 if not (typetbl[glob] or typetbl["MUST_"..glob]) then