aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:48:58 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commitb8fa101569c3f5a0cf68291954a38cf128ff8442 (patch)
tree0b68c6956236c75ff645f7966d7c3af187c8b24d
parent1624da99574c48dfd92b1dd42b982118c11270f7 (diff)
downloadluarocks-b8fa101569c3f5a0cf68291954a38cf128ff8442.tar.gz
luarocks-b8fa101569c3f5a0cf68291954a38cf128ff8442.tar.bz2
luarocks-b8fa101569c3f5a0cf68291954a38cf128ff8442.zip
Teal: convert luarocks.type.rockspec
-rw-r--r--src/luarocks/type/rockspec.tl282
1 files changed, 172 insertions, 110 deletions
diff --git a/src/luarocks/type/rockspec.tl b/src/luarocks/type/rockspec.tl
index 0b4b5dcf..5db0c4c4 100644
--- a/src/luarocks/type/rockspec.tl
+++ b/src/luarocks/type/rockspec.tl
@@ -1,7 +1,16 @@
1local type_rockspec = {} 1local record type_rockspec
2 order: Ordering<string>
3 rockspec_format: string
4end
5
6local type Ordering = require("luarocks.core.types.ordering").Ordering
7
8local type Rockspec = require("luarocks.core.types.rockspec").Rockspec
2 9
3local type_check = require("luarocks.type_check") 10local type_check = require("luarocks.type_check")
4 11
12-- local type TableSchema = type_check.TableSchema
13
5type_rockspec.rockspec_format = "3.0" 14type_rockspec.rockspec_format = "3.0"
6 15
7-- Syntax for type-checking tables: 16-- Syntax for type-checking tables:
@@ -19,138 +28,192 @@ type_rockspec.rockspec_format = "3.0"
19 28
20local rockspec_formats, versions = type_check.declare_schemas({ 29local rockspec_formats, versions = type_check.declare_schemas({
21 ["1.0"] = { 30 ["1.0"] = {
22 rockspec_format = { _type = "string" }, 31 fields = {
23 package = { _type = "string", _mandatory = true }, 32 rockspec_format = { _type = "string" },
24 version = { _type = "string", _pattern = "[%w.]+-[%d]+", _mandatory = true }, 33 package = { _type = "string", _mandatory = true },
25 description = { 34 version = { _type = "string", _pattern = "[%w.]+-[%d]+", _mandatory = true },
26 summary = { _type = "string" }, 35 description = {
27 detailed = { _type = "string" }, 36 fields = {
28 homepage = { _type = "string" }, 37 summary = { _type = "string" },
29 license = { _type = "string" }, 38 detailed = { _type = "string" },
30 maintainer = { _type = "string" }, 39 homepage = { _type = "string" },
31 }, 40 license = { _type = "string" },
32 dependencies = { 41 maintainer = { _type = "string" },
33 platforms = type_check.MAGIC_PLATFORMS,
34 _any = {
35 _type = "string",
36 _name = "a valid dependency string",
37 _pattern = "%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
38 },
39 },
40 supported_platforms = {
41 _any = { _type = "string" },
42 },
43 external_dependencies = {
44 platforms = type_check.MAGIC_PLATFORMS,
45 _any = {
46 program = { _type = "string" },
47 header = { _type = "string" },
48 library = { _type = "string" },
49 }
50 },
51 source = {
52 _mandatory = true,
53 platforms = type_check.MAGIC_PLATFORMS,
54 url = { _type = "string", _mandatory = true },
55 md5 = { _type = "string" },
56 file = { _type = "string" },
57 dir = { _type = "string" },
58 tag = { _type = "string" },
59 branch = { _type = "string" },
60 module = { _type = "string" },
61 cvs_tag = { _type = "string" },
62 cvs_module = { _type = "string" },
63 },
64 build = {
65 platforms = type_check.MAGIC_PLATFORMS,
66 type = { _type = "string" },
67 install = {
68 lua = {
69 _more = true
70 }, 42 },
71 lib = { 43 },
72 _more = true 44 dependencies = {
45 fields = {
46 platforms = type_check.MAGIC_PLATFORMS,
73 }, 47 },
74 conf = { 48 _any = {
75 _more = true 49 _type = "string",
50 _name = "a valid dependency string",
51 _pattern = "%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
76 }, 52 },
77 bin = {
78 _more = true
79 }
80 }, 53 },
81 copy_directories = { 54 supported_platforms = {
82 _any = { _type = "string" }, 55 _any = { _type = "string" },
83 }, 56 },
84 _more = true, 57 external_dependencies = {
85 _mandatory = true 58 fields = {
86 }, 59 platforms = type_check.MAGIC_PLATFORMS,
87 hooks = { 60 },
88 platforms = type_check.MAGIC_PLATFORMS, 61 _any = {
89 post_install = { _type = "string" }, 62 fields = {
63 program = { _type = "string" },
64 header = { _type = "string" },
65 library = { _type = "string" },
66 }
67 },
68 },
69 source = {
70 _mandatory = true,
71 fields = {
72 platforms = type_check.MAGIC_PLATFORMS,
73 url = { _type = "string", _mandatory = true },
74 md5 = { _type = "string" },
75 file = { _type = "string" },
76 dir = { _type = "string" },
77 tag = { _type = "string" },
78 branch = { _type = "string" },
79 module = { _type = "string" },
80 cvs_tag = { _type = "string" },
81 cvs_module = { _type = "string" },
82 },
83 },
84 build = {
85 fields = {
86 platforms = type_check.MAGIC_PLATFORMS,
87 type = { _type = "string" },
88 install = {
89 fields = {
90 lua = {
91 _more = true
92 },
93 lib = {
94 _more = true
95 },
96 conf = {
97 _more = true
98 },
99 bin = {
100 _more = true
101 }
102 }
103 },
104 copy_directories = {
105 _any = { _type = "string" },
106 },
107 },
108 _more = true,
109 _mandatory = true
110 },
111 hooks = {
112 fields = {
113 platforms = type_check.MAGIC_PLATFORMS,
114 post_install = { _type = "string" },
115 }
116 },
90 }, 117 },
91 }, 118 },
92 119
93 ["1.1"] = { 120 ["1.1"] = {
94 deploy = { 121 fields = {
95 wrap_bin_scripts = { _type = "boolean" }, 122 deploy = {
96 } 123 fields = {
124 wrap_bin_scripts = { _type = "boolean" },
125 },
126 }
127 },
97 }, 128 },
98 129
99 ["3.0"] = { 130 ["3.0"] = {
100 description = { 131 fields = {
101 labels = { 132 description = {
102 _any = { _type = "string" } 133 fields = {
134 labels = {
135 _any = { _type = "string" }
136 },
137 issues_url = { _type = "string" },
138 },
103 }, 139 },
104 issues_url = { _type = "string" }, 140 dependencies = {
105 }, 141 _any = {
106 dependencies = { 142 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
107 _any = { 143 },
108 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
109 }, 144 },
110 }, 145 build_dependencies = {
111 build_dependencies = { 146 fields = {
112 platforms = type_check.MAGIC_PLATFORMS, 147 platforms = type_check.MAGIC_PLATFORMS,
113 _any = { 148 },
114 _type = "string", 149 _any = {
115 _name = "a valid dependency string", 150 _type = "string",
116 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", 151 _name = "a valid dependency string",
152 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
153 },
117 }, 154 },
118 }, 155 test_dependencies = {
119 test_dependencies = { 156 fields = {
120 platforms = type_check.MAGIC_PLATFORMS, 157 platforms = type_check.MAGIC_PLATFORMS,
121 _any = { 158 },
122 _type = "string", 159 _any = {
123 _name = "a valid dependency string", 160 _type = "string",
124 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", 161 _name = "a valid dependency string",
162 _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)",
163 },
125 }, 164 },
126 }, 165 build = {
127 build = { 166 _mandatory = false,
128 _mandatory = false, 167 },
129 }, 168 test = {
130 test = { 169 fields = {
131 platforms = type_check.MAGIC_PLATFORMS, 170 platforms = type_check.MAGIC_PLATFORMS,
132 type = { _type = "string" }, 171 type = { _type = "string" },
133 _more = true, 172 },
134 }, 173 _more = true,
174 },
175 }
135 } 176 }
136}) 177})
137 178
138type_rockspec.order = {"rockspec_format", "package", "version", 179-- type_rockspec.order = {"rockspec_format", "package", "version",
139 { "source", { "url", "tag", "branch", "md5" } }, 180-- { "source", { "url", "tag", "branch", "md5" } },
140 { "description", {"summary", "detailed", "homepage", "license" } }, 181-- { "description", {"summary", "detailed", "homepage", "license" } },
141 "supported_platforms", "dependencies", "build_dependencies", "external_dependencies", 182-- "supported_platforms", "dependencies", "build_dependencies", "external_dependencies",
142 { "build", {"type", "modules", "copy_directories", "platforms"} }, 183-- { "build", {"type", "modules", "copy_directories", "platforms"} },
143 "test_dependencies", { "test", {"type"} }, 184-- "test_dependencies", { "test", {"type"} },
144 "hooks"} 185-- "hooks"}
186
187type_rockspec.order = {
188 "rockspec_format",
189 "package",
190 "version",
191 "source",
192 "description",
193 "supported_platforms",
194 "dependencies",
195 "build_dependencies",
196 "external_dependencies",
197 "build",
198 "test_dependencies",
199 "test",
200 "hooks",
201 sub_orders = {
202 ["source"] = { "url", "tag", "branch", "md5" },
203 ["description"] = {"summary", "detailed", "homepage", "license" },
204 ["build"] = { "type", "modules", "copy_directories", "platforms" },
205 ["test"] = { "type" }
206 }
207}
145 208
146local function check_rockspec_using_version(rockspec, globals, version) 209local function check_rockspec_using_version(rockspec: Rockspec, globals: {string: any}, version: string): boolean, string
147 local schema = rockspec_formats[version] 210 local schema = rockspec_formats[version]
148 if not schema then 211 if not schema then
149 return nil, "unknown rockspec format " .. version 212 return nil, "unknown rockspec format " .. version
150 end 213 end
151 local ok, err = type_check.check_undeclared_globals(globals, schema) 214 local ok, err = type_check.check_undeclared_globals(globals, schema)
152 if ok then 215 if ok then
153 ok, err = type_check.type_check_table(version, rockspec, schema, "") 216 ok, err = type_check.type_check_table(version, rockspec as {any: any}, schema, "")
154 end 217 end
155 if ok then 218 if ok then
156 return true 219 return true
@@ -165,10 +228,9 @@ end
165-- mismatches. 228-- mismatches.
166-- @return boolean or (nil, string): true if type checking 229-- @return boolean or (nil, string): true if type checking
167-- succeeded, or nil and an error message if it failed. 230-- succeeded, or nil and an error message if it failed.
168function type_rockspec.check(rockspec, globals) 231function type_rockspec.check(rockspec: Rockspec, globals: {string: any}): boolean, string
169 assert(type(rockspec) == "table")
170 232
171 local version = rockspec.rockspec_format or "1.0" 233 local version: string = rockspec.rockspec_format as string or "1.0"
172 local ok, err = check_rockspec_using_version(rockspec, globals, version) 234 local ok, err = check_rockspec_using_version(rockspec, globals, version)
173 if ok then 235 if ok then
174 return true 236 return true
@@ -184,7 +246,7 @@ function type_rockspec.check(rockspec, globals)
184 found = true 246 found = true
185 end 247 end
186 else 248 else
187 local v_ok, v_err = check_rockspec_using_version(rockspec, globals, v) 249 local v_ok = check_rockspec_using_version(rockspec, globals, v)
188 if v_ok then 250 if v_ok then
189 return nil, err .. " (using rockspec format " .. version .. " -- " .. 251 return nil, err .. " (using rockspec format " .. version .. " -- " ..
190 [[adding 'rockspec_format = "]] .. v .. [["' to the rockspec ]] .. 252 [[adding 'rockspec_format = "]] .. v .. [["' to the rockspec ]] ..