diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-07-30 20:53:21 +0300 |
|---|---|---|
| committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:51:31 +0300 |
| commit | e8fffcffbb06ad2a77771af5e452645937675066 (patch) | |
| tree | eedb3d02a02cb9d3e709cb23a90be3b052eb64a3 /src | |
| parent | 9d69cffa1446e03b6c425f974b14c33551a5e07a (diff) | |
| download | luarocks-e8fffcffbb06ad2a77771af5e452645937675066.tar.gz luarocks-e8fffcffbb06ad2a77771af5e452645937675066.tar.bz2 luarocks-e8fffcffbb06ad2a77771af5e452645937675066.zip | |
added manifest and rockspec tl files
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/type/manifest.tl | 80 | ||||
| -rw-r--r-- | src/luarocks/type/rockspec.tl | 221 |
2 files changed, 301 insertions, 0 deletions
diff --git a/src/luarocks/type/manifest.tl b/src/luarocks/type/manifest.tl new file mode 100644 index 00000000..043366ea --- /dev/null +++ b/src/luarocks/type/manifest.tl | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | local type_manifest = {} | ||
| 2 | |||
| 3 | local type_check = require("luarocks.type_check") | ||
| 4 | |||
| 5 | local manifest_formats = type_check.declare_schemas({ | ||
| 6 | ["3.0"] = { | ||
| 7 | repository = { | ||
| 8 | _mandatory = true, | ||
| 9 | -- packages | ||
| 10 | _any = { | ||
| 11 | -- versions | ||
| 12 | _any = { | ||
| 13 | -- items | ||
| 14 | _any = { | ||
| 15 | arch = { _type = "string", _mandatory = true }, | ||
| 16 | modules = { _any = { _type = "string" } }, | ||
| 17 | commands = { _any = { _type = "string" } }, | ||
| 18 | dependencies = { _any = { _type = "string" } }, | ||
| 19 | -- TODO: to be extended with more metadata. | ||
| 20 | } | ||
| 21 | } | ||
| 22 | } | ||
| 23 | }, | ||
| 24 | modules = { | ||
| 25 | _mandatory = true, | ||
| 26 | -- modules | ||
| 27 | _any = { | ||
| 28 | -- providers | ||
| 29 | _any = { _type = "string" } | ||
| 30 | } | ||
| 31 | }, | ||
| 32 | commands = { | ||
| 33 | _mandatory = true, | ||
| 34 | -- modules | ||
| 35 | _any = { | ||
| 36 | -- commands | ||
| 37 | _any = { _type = "string" } | ||
| 38 | } | ||
| 39 | }, | ||
| 40 | dependencies = { | ||
| 41 | -- each module | ||
| 42 | _any = { | ||
| 43 | -- each version | ||
| 44 | _any = { | ||
| 45 | -- each dependency | ||
| 46 | _any = { | ||
| 47 | name = { _type = "string" }, | ||
| 48 | namespace = { _type = "string" }, | ||
| 49 | constraints = { | ||
| 50 | _any = { | ||
| 51 | no_upgrade = { _type = "boolean" }, | ||
| 52 | op = { _type = "string" }, | ||
| 53 | version = { | ||
| 54 | string = { _type = "string" }, | ||
| 55 | _any = { _type = "number" }, | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | }) | ||
| 65 | |||
| 66 | --- Type check a manifest table. | ||
| 67 | -- Verify the correctness of elements from a | ||
| 68 | -- manifest table, reporting on unknown fields and type | ||
| 69 | -- mismatches. | ||
| 70 | -- @return boolean or (nil, string): true if type checking | ||
| 71 | -- succeeded, or nil and an error message if it failed. | ||
| 72 | function type_manifest.check(manifest, globals) | ||
| 73 | assert(type(manifest) == "table") | ||
| 74 | local format = manifest_formats["3.0"] | ||
| 75 | local ok, err = type_check.check_undeclared_globals(globals, format) | ||
| 76 | if not ok then return nil, err end | ||
| 77 | return type_check.type_check_table("3.0", manifest, format, "") | ||
| 78 | end | ||
| 79 | |||
| 80 | return type_manifest | ||
diff --git a/src/luarocks/type/rockspec.tl b/src/luarocks/type/rockspec.tl new file mode 100644 index 00000000..0b3cf31f --- /dev/null +++ b/src/luarocks/type/rockspec.tl | |||
| @@ -0,0 +1,221 @@ | |||
| 1 | local type_rockspec = {} | ||
| 2 | |||
| 3 | local type_check = require("luarocks.type_check") | ||
| 4 | |||
| 5 | type_rockspec.rockspec_format = "3.0" | ||
| 6 | |||
| 7 | -- Syntax for type-checking tables: | ||
| 8 | -- | ||
| 9 | -- A type-checking table describes typing data for a value. | ||
| 10 | -- Any key starting with an underscore has a special meaning: | ||
| 11 | -- _type (string) is the Lua type of the value. Default is "table". | ||
| 12 | -- _mandatory (boolean) indicates if the value is a mandatory key in its container table. Default is false. | ||
| 13 | -- For "string" types only: | ||
| 14 | -- _pattern (string) is the string-matching pattern, valid for string types only. Default is ".*". | ||
| 15 | -- For "table" types only: | ||
| 16 | -- _any (table) is the type-checking table for unspecified keys, recursively checked. | ||
| 17 | -- _more (boolean) indicates that the table accepts unspecified keys and does not type-check them. | ||
| 18 | -- Any other string keys that don't start with an underscore represent known keys and are type-checking tables, recursively checked. | ||
| 19 | |||
| 20 | local rockspec_formats, versions = type_check.declare_schemas({ | ||
| 21 | ["1.0"] = { | ||
| 22 | rockspec_format = { _type = "string" }, | ||
| 23 | package = { _type = "string", _mandatory = true }, | ||
| 24 | version = { _type = "string", _pattern = "[%w.]+-[%d]+", _mandatory = true }, | ||
| 25 | description = { | ||
| 26 | summary = { _type = "string" }, | ||
| 27 | detailed = { _type = "string" }, | ||
| 28 | homepage = { _type = "string" }, | ||
| 29 | license = { _type = "string" }, | ||
| 30 | maintainer = { _type = "string" }, | ||
| 31 | }, | ||
| 32 | dependencies = { | ||
| 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 | }, | ||
| 71 | lib = { | ||
| 72 | _more = true | ||
| 73 | }, | ||
| 74 | conf = { | ||
| 75 | _more = true | ||
| 76 | }, | ||
| 77 | bin = { | ||
| 78 | _more = true | ||
| 79 | } | ||
| 80 | }, | ||
| 81 | copy_directories = { | ||
| 82 | _any = { _type = "string" }, | ||
| 83 | }, | ||
| 84 | _more = true, | ||
| 85 | _mandatory = true | ||
| 86 | }, | ||
| 87 | hooks = { | ||
| 88 | platforms = type_check.MAGIC_PLATFORMS, | ||
| 89 | post_install = { _type = "string" }, | ||
| 90 | }, | ||
| 91 | }, | ||
| 92 | |||
| 93 | ["1.1"] = { | ||
| 94 | deploy = { | ||
| 95 | wrap_bin_scripts = { _type = "boolean" }, | ||
| 96 | } | ||
| 97 | }, | ||
| 98 | |||
| 99 | ["3.0"] = { | ||
| 100 | description = { | ||
| 101 | labels = { | ||
| 102 | _any = { _type = "string" } | ||
| 103 | }, | ||
| 104 | issues_url = { _type = "string" }, | ||
| 105 | }, | ||
| 106 | dependencies = { | ||
| 107 | _any = { | ||
| 108 | _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", | ||
| 109 | }, | ||
| 110 | }, | ||
| 111 | build_dependencies = { | ||
| 112 | platforms = type_check.MAGIC_PLATFORMS, | ||
| 113 | _any = { | ||
| 114 | _type = "string", | ||
| 115 | _name = "a valid dependency string", | ||
| 116 | _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", | ||
| 117 | }, | ||
| 118 | }, | ||
| 119 | test_dependencies = { | ||
| 120 | platforms = type_check.MAGIC_PLATFORMS, | ||
| 121 | _any = { | ||
| 122 | _type = "string", | ||
| 123 | _name = "a valid dependency string", | ||
| 124 | _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", | ||
| 125 | }, | ||
| 126 | }, | ||
| 127 | build = { | ||
| 128 | _mandatory = false, | ||
| 129 | }, | ||
| 130 | test = { | ||
| 131 | platforms = type_check.MAGIC_PLATFORMS, | ||
| 132 | type = { _type = "string" }, | ||
| 133 | _more = true, | ||
| 134 | }, | ||
| 135 | } | ||
| 136 | }) | ||
| 137 | |||
| 138 | -- type_rockspec.order = {"rockspec_format", "package", "version", | ||
| 139 | -- { "source", { "url", "tag", "branch", "md5" } }, | ||
| 140 | -- { "description", {"summary", "detailed", "homepage", "license" } }, | ||
| 141 | -- "supported_platforms", "dependencies", "build_dependencies", "external_dependencies", | ||
| 142 | -- { "build", {"type", "modules", "copy_directories", "platforms"} }, | ||
| 143 | -- "test_dependencies", { "test", {"type"} }, | ||
| 144 | -- "hooks"} | ||
| 145 | |||
| 146 | type_rockspec.order = { | ||
| 147 | "rockspec_format", | ||
| 148 | "package", | ||
| 149 | "version", | ||
| 150 | "source", | ||
| 151 | "description", | ||
| 152 | "supported_platforms", | ||
| 153 | "dependencies", | ||
| 154 | "build_dependencies", | ||
| 155 | "external_dependencies", | ||
| 156 | "build", | ||
| 157 | "test_dependencies", | ||
| 158 | "test", | ||
| 159 | "hooks", | ||
| 160 | sub_orders = { | ||
| 161 | ["source"] = { "url", "tag", "branch", "md5" }, | ||
| 162 | ["description"] = {"summary", "detailed", "homepage", "license" }, | ||
| 163 | ["build"] = { "type", "modules", "copy_directories", "platforms" }, | ||
| 164 | ["test"] = { "type" } | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | local function check_rockspec_using_version(rockspec, globals, version) | ||
| 169 | local schema = rockspec_formats[version] | ||
| 170 | if not schema then | ||
| 171 | return nil, "unknown rockspec format " .. version | ||
| 172 | end | ||
| 173 | local ok, err = type_check.check_undeclared_globals(globals, schema) | ||
| 174 | if ok then | ||
| 175 | ok, err = type_check.type_check_table(version, rockspec, schema, "") | ||
| 176 | end | ||
| 177 | if ok then | ||
| 178 | return true | ||
| 179 | else | ||
| 180 | return nil, err | ||
| 181 | end | ||
| 182 | end | ||
| 183 | |||
| 184 | --- Type check a rockspec table. | ||
| 185 | -- Verify the correctness of elements from a | ||
| 186 | -- rockspec table, reporting on unknown fields and type | ||
| 187 | -- mismatches. | ||
| 188 | -- @return boolean or (nil, string): true if type checking | ||
| 189 | -- succeeded, or nil and an error message if it failed. | ||
| 190 | function type_rockspec.check(rockspec, globals) | ||
| 191 | assert(type(rockspec) == "table") | ||
| 192 | |||
| 193 | local version = rockspec.rockspec_format or "1.0" | ||
| 194 | local ok, err = check_rockspec_using_version(rockspec, globals, version) | ||
| 195 | if ok then | ||
| 196 | return true | ||
| 197 | end | ||
| 198 | |||
| 199 | -- Rockspec parsing failed. | ||
| 200 | -- Let's see if it would pass using a later version. | ||
| 201 | |||
| 202 | local found = false | ||
| 203 | for _, v in ipairs(versions) do | ||
| 204 | if not found then | ||
| 205 | if v == version then | ||
| 206 | found = true | ||
| 207 | end | ||
| 208 | else | ||
| 209 | local v_ok, v_err = check_rockspec_using_version(rockspec, globals, v) | ||
| 210 | if v_ok then | ||
| 211 | return nil, err .. " (using rockspec format " .. version .. " -- " .. | ||
| 212 | [[adding 'rockspec_format = "]] .. v .. [["' to the rockspec ]] .. | ||
| 213 | [[will fix this)]] | ||
| 214 | end | ||
| 215 | end | ||
| 216 | end | ||
| 217 | |||
| 218 | return nil, err .. " (using rockspec format " .. version .. ")" | ||
| 219 | end | ||
| 220 | |||
| 221 | return type_rockspec | ||
