diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-20 00:54:55 +0300 |
|---|---|---|
| committer | V1K1NGbg <victor@ilchev.com> | 2024-08-20 00:54:55 +0300 |
| commit | ec0de3d09266f28cb9c45b635da50db113abeba2 (patch) | |
| tree | 53b1c6300d8179c98fb20c2c5bbb19b41ff17e10 /src | |
| parent | f17c209b891e53cf510e13e31a40dbc4fa918049 (diff) | |
| download | luarocks-ec0de3d09266f28cb9c45b635da50db113abeba2.tar.gz luarocks-ec0de3d09266f28cb9c45b635da50db113abeba2.tar.bz2 luarocks-ec0de3d09266f28cb9c45b635da50db113abeba2.zip | |
config, install, lint, make, new_version
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/config-original.lua | 392 | ||||
| -rw-r--r-- | src/luarocks/cmd/config.lua | 114 | ||||
| -rw-r--r-- | src/luarocks/cmd/config.tl | 51 | ||||
| -rw-r--r-- | src/luarocks/cmd/install-original.lua | 250 | ||||
| -rw-r--r-- | src/luarocks/cmd/install.lua | 162 | ||||
| -rw-r--r-- | src/luarocks/cmd/install.tl | 8 | ||||
| -rw-r--r-- | src/luarocks/cmd/lint-original.lua | 50 | ||||
| -rw-r--r-- | src/luarocks/cmd/lint.lua | 37 | ||||
| -rw-r--r-- | src/luarocks/cmd/lint.tl | 6 | ||||
| -rw-r--r-- | src/luarocks/cmd/make-original.lua | 165 | ||||
| -rw-r--r-- | src/luarocks/cmd/make.lua | 105 | ||||
| -rw-r--r-- | src/luarocks/cmd/make.tl | 18 | ||||
| -rw-r--r-- | src/luarocks/cmd/new_version-original.lua | 228 | ||||
| -rw-r--r-- | src/luarocks/cmd/new_version.lua | 61 | ||||
| -rw-r--r-- | src/luarocks/cmd/new_version.tl | 6 |
15 files changed, 1408 insertions, 245 deletions
diff --git a/src/luarocks/cmd/config-original.lua b/src/luarocks/cmd/config-original.lua new file mode 100644 index 00000000..d67711a0 --- /dev/null +++ b/src/luarocks/cmd/config-original.lua | |||
| @@ -0,0 +1,392 @@ | |||
| 1 | --- Module implementing the LuaRocks "config" command. | ||
| 2 | -- Queries information about the LuaRocks configuration. | ||
| 3 | local config_cmd = {} | ||
| 4 | |||
| 5 | local persist = require("luarocks.persist") | ||
| 6 | local config = require("luarocks.config") | ||
| 7 | local cfg = require("luarocks.core.cfg") | ||
| 8 | local util = require("luarocks.util") | ||
| 9 | local deps = require("luarocks.deps") | ||
| 10 | local dir = require("luarocks.dir") | ||
| 11 | local fs = require("luarocks.fs") | ||
| 12 | local json = require("luarocks.vendor.dkjson") | ||
| 13 | |||
| 14 | function config_cmd.add_to_parser(parser) | ||
| 15 | local cmd = parser:command("config", [[ | ||
| 16 | Query information about the LuaRocks configuration. | ||
| 17 | |||
| 18 | * When given a configuration key, it prints the value of that key according to | ||
| 19 | the currently active configuration (taking into account all config files and | ||
| 20 | any command-line flags passed) | ||
| 21 | |||
| 22 | Examples: | ||
| 23 | luarocks config variables.LUA_INCDIR | ||
| 24 | luarocks config lua_version | ||
| 25 | |||
| 26 | * When given a configuration key and a value, it overwrites the config file (see | ||
| 27 | the --scope option below to determine which) and replaces the value of the | ||
| 28 | given key with the given value. | ||
| 29 | |||
| 30 | * `lua_dir` is a special key as it checks for a valid Lua installation | ||
| 31 | (equivalent to --lua-dir) and sets several keys at once. | ||
| 32 | * `lua_version` is a special key as it changes the default Lua version | ||
| 33 | used by LuaRocks commands (equivalent to passing --lua-version). | ||
| 34 | |||
| 35 | Examples: | ||
| 36 | luarocks config variables.OPENSSL_DIR /usr/local/openssl | ||
| 37 | luarocks config lua_dir /usr/local | ||
| 38 | luarocks config lua_version 5.3 | ||
| 39 | |||
| 40 | * When given a configuration key and --unset, it overwrites the config file (see | ||
| 41 | the --scope option below to determine which) and deletes that key from the | ||
| 42 | file. | ||
| 43 | |||
| 44 | Example: luarocks config variables.OPENSSL_DIR --unset | ||
| 45 | |||
| 46 | * When given no arguments, it prints the entire currently active configuration, | ||
| 47 | resulting from reading the config files from all scopes. | ||
| 48 | |||
| 49 | Example: luarocks config]], util.see_also([[ | ||
| 50 | https://github.com/luarocks/luarocks/wiki/Config-file-format | ||
| 51 | for detailed information on the LuaRocks config file format. | ||
| 52 | ]])) | ||
| 53 | :summary("Query information about the LuaRocks configuration.") | ||
| 54 | |||
| 55 | cmd:argument("key", "The configuration key.") | ||
| 56 | :args("?") | ||
| 57 | cmd:argument("value", "The configuration value.") | ||
| 58 | :args("?") | ||
| 59 | |||
| 60 | cmd:option("--scope", "The scope indicates which config file should be rewritten.\n".. | ||
| 61 | '* Using a wrapper created with `luarocks init`, the default is "project".\n'.. | ||
| 62 | '* Using --local (or when `local_by_default` is `true`), the default is "user".\n'.. | ||
| 63 | '* Otherwise, the default is "system".') | ||
| 64 | :choices({"system", "user", "project"}) | ||
| 65 | cmd:flag("--unset", "Delete the key from the configuration file.") | ||
| 66 | cmd:flag("--json", "Output as JSON.") | ||
| 67 | |||
| 68 | -- Deprecated flags | ||
| 69 | cmd:flag("--lua-incdir"):hidden(true) | ||
| 70 | cmd:flag("--lua-libdir"):hidden(true) | ||
| 71 | cmd:flag("--lua-ver"):hidden(true) | ||
| 72 | cmd:flag("--system-config"):hidden(true) | ||
| 73 | cmd:flag("--user-config"):hidden(true) | ||
| 74 | cmd:flag("--rock-trees"):hidden(true) | ||
| 75 | end | ||
| 76 | |||
| 77 | local function config_file(conf) | ||
| 78 | print(dir.normalize(conf.file)) | ||
| 79 | if conf.found then | ||
| 80 | return true | ||
| 81 | else | ||
| 82 | return nil, "file not found" | ||
| 83 | end | ||
| 84 | end | ||
| 85 | |||
| 86 | local function traverse_varstring(var, tbl, fn, missing_parent) | ||
| 87 | local k, r = var:match("^%[([0-9]+)%]%.(.*)$") | ||
| 88 | if k then | ||
| 89 | k = tonumber(k) | ||
| 90 | else | ||
| 91 | k, r = var:match("^([^.[]+)%.(.*)$") | ||
| 92 | if not k then | ||
| 93 | k, r = var:match("^([^[]+)(%[.*)$") | ||
| 94 | end | ||
| 95 | end | ||
| 96 | |||
| 97 | if k then | ||
| 98 | if not tbl[k] and missing_parent then | ||
| 99 | missing_parent(tbl, k) | ||
| 100 | end | ||
| 101 | |||
| 102 | if tbl[k] then | ||
| 103 | return traverse_varstring(r, tbl[k], fn, missing_parent) | ||
| 104 | else | ||
| 105 | return nil, "Unknown entry " .. k | ||
| 106 | end | ||
| 107 | end | ||
| 108 | |||
| 109 | local i = var:match("^%[([0-9]+)%]$") | ||
| 110 | if i then | ||
| 111 | var = tonumber(i) | ||
| 112 | end | ||
| 113 | |||
| 114 | return fn(tbl, var) | ||
| 115 | end | ||
| 116 | |||
| 117 | local function print_json(value) | ||
| 118 | print(json.encode(value)) | ||
| 119 | return true | ||
| 120 | end | ||
| 121 | |||
| 122 | local function print_entry(var, tbl, is_json) | ||
| 123 | return traverse_varstring(var, tbl, function(t, k) | ||
| 124 | if not t[k] then | ||
| 125 | return nil, "Unknown entry " .. k | ||
| 126 | end | ||
| 127 | local val = t[k] | ||
| 128 | |||
| 129 | if not config.should_skip(var, val) then | ||
| 130 | if is_json then | ||
| 131 | return print_json(val) | ||
| 132 | elseif type(val) == "string" then | ||
| 133 | print(val) | ||
| 134 | else | ||
| 135 | persist.write_value(io.stdout, val) | ||
| 136 | end | ||
| 137 | end | ||
| 138 | return true | ||
| 139 | end) | ||
| 140 | end | ||
| 141 | |||
| 142 | local function infer_type(var) | ||
| 143 | local typ | ||
| 144 | traverse_varstring(var, cfg, function(t, k) | ||
| 145 | if t[k] ~= nil then | ||
| 146 | typ = type(t[k]) | ||
| 147 | end | ||
| 148 | end) | ||
| 149 | return typ | ||
| 150 | end | ||
| 151 | |||
| 152 | local function write_entries(keys, scope, do_unset) | ||
| 153 | if scope == "project" and not cfg.config_files.project then | ||
| 154 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." | ||
| 155 | end | ||
| 156 | |||
| 157 | local file_name = cfg.config_files[scope].file | ||
| 158 | |||
| 159 | local tbl, err = persist.load_config_file_if_basic(file_name, cfg) | ||
| 160 | if not tbl then | ||
| 161 | return nil, err | ||
| 162 | end | ||
| 163 | |||
| 164 | for var, val in util.sortedpairs(keys) do | ||
| 165 | traverse_varstring(var, tbl, function(t, k) | ||
| 166 | if do_unset then | ||
| 167 | t[k] = nil | ||
| 168 | else | ||
| 169 | local typ = infer_type(var) | ||
| 170 | local v | ||
| 171 | if typ == "number" and tonumber(val) then | ||
| 172 | v = tonumber(val) | ||
| 173 | elseif typ == "boolean" and val == "true" then | ||
| 174 | v = true | ||
| 175 | elseif typ == "boolean" and val == "false" then | ||
| 176 | v = false | ||
| 177 | else | ||
| 178 | v = val | ||
| 179 | end | ||
| 180 | t[k] = v | ||
| 181 | keys[var] = v | ||
| 182 | end | ||
| 183 | return true | ||
| 184 | end, function(p, k) | ||
| 185 | p[k] = {} | ||
| 186 | end) | ||
| 187 | end | ||
| 188 | |||
| 189 | local ok, err = fs.make_dir(dir.dir_name(file_name)) | ||
| 190 | if not ok then | ||
| 191 | return nil, err | ||
| 192 | end | ||
| 193 | |||
| 194 | ok, err = persist.save_from_table(file_name, tbl) | ||
| 195 | if ok then | ||
| 196 | print(do_unset and "Removed" or "Wrote") | ||
| 197 | for var, val in util.sortedpairs(keys) do | ||
| 198 | if do_unset then | ||
| 199 | print(("\t%s"):format(var)) | ||
| 200 | else | ||
| 201 | if type(val) == "string" then | ||
| 202 | print(("\t%s = %q"):format(var, val)) | ||
| 203 | else | ||
| 204 | print(("\t%s = %s"):format(var, tostring(val))) | ||
| 205 | end | ||
| 206 | end | ||
| 207 | end | ||
| 208 | print(do_unset and "from" or "to") | ||
| 209 | print("\t" .. file_name) | ||
| 210 | return true | ||
| 211 | else | ||
| 212 | return nil, err | ||
| 213 | end | ||
| 214 | end | ||
| 215 | |||
| 216 | local function get_scope(args) | ||
| 217 | return args.scope | ||
| 218 | or (args["local"] and "user") | ||
| 219 | or (args.project_tree and "project") | ||
| 220 | or (cfg.local_by_default and "user") | ||
| 221 | or (fs.is_writable(cfg.config_files["system"].file) and "system") | ||
| 222 | or "user" | ||
| 223 | end | ||
| 224 | |||
| 225 | local function report_on_lua_incdir_config(value, lua_version) | ||
| 226 | local variables = { | ||
| 227 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | ||
| 228 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | ||
| 229 | ["LUA_INCDIR"] = value, | ||
| 230 | ["LUA_LIBDIR"] = cfg.variables.LUA_LIBDIR, | ||
| 231 | ["LUA"] = cfg.variables.LUA, | ||
| 232 | } | ||
| 233 | |||
| 234 | local ok, err = deps.check_lua_incdir(variables, lua_version) | ||
| 235 | if not ok then | ||
| 236 | util.printerr() | ||
| 237 | util.warning((err:gsub(" You can use.*", ""))) | ||
| 238 | end | ||
| 239 | return ok | ||
| 240 | end | ||
| 241 | |||
| 242 | local function report_on_lua_libdir_config(value, lua_version) | ||
| 243 | local variables = { | ||
| 244 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | ||
| 245 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | ||
| 246 | ["LUA_INCDIR"] = cfg.variables.LUA_INCDIR, | ||
| 247 | ["LUA_LIBDIR"] = value, | ||
| 248 | ["LUA"] = cfg.variables.LUA, | ||
| 249 | } | ||
| 250 | |||
| 251 | local ok, err, _, err_files = deps.check_lua_libdir(variables, lua_version) | ||
| 252 | if not ok then | ||
| 253 | util.printerr() | ||
| 254 | util.warning((err:gsub(" You can use.*", ""))) | ||
| 255 | util.printerr("Tried:") | ||
| 256 | for _, l in pairs(err_files or {}) do | ||
| 257 | for _, d in ipairs(l) do | ||
| 258 | util.printerr("\t" .. d) | ||
| 259 | end | ||
| 260 | end | ||
| 261 | end | ||
| 262 | return ok | ||
| 263 | end | ||
| 264 | |||
| 265 | local function warn_bad_c_config() | ||
| 266 | util.printerr() | ||
| 267 | util.printerr("LuaRocks may not work correctly when building C modules using this configuration.") | ||
| 268 | util.printerr() | ||
| 269 | end | ||
| 270 | |||
| 271 | --- Driver function for "config" command. | ||
| 272 | -- @return boolean: True if succeeded, nil on errors. | ||
| 273 | function config_cmd.command(args) | ||
| 274 | local lua_version = args.lua_version or cfg.lua_version | ||
| 275 | |||
| 276 | deps.check_lua_incdir(cfg.variables, lua_version) | ||
| 277 | deps.check_lua_libdir(cfg.variables, lua_version) | ||
| 278 | |||
| 279 | -- deprecated flags | ||
| 280 | if args.lua_incdir then | ||
| 281 | print(cfg.variables.LUA_INCDIR) | ||
| 282 | return true | ||
| 283 | end | ||
| 284 | if args.lua_libdir then | ||
| 285 | print(cfg.variables.LUA_LIBDIR) | ||
| 286 | return true | ||
| 287 | end | ||
| 288 | if args.lua_ver then | ||
| 289 | print(cfg.lua_version) | ||
| 290 | return true | ||
| 291 | end | ||
| 292 | if args.system_config then | ||
| 293 | return config_file(cfg.config_files.system) | ||
| 294 | end | ||
| 295 | if args.user_config then | ||
| 296 | return config_file(cfg.config_files.user) | ||
| 297 | end | ||
| 298 | if args.rock_trees then | ||
| 299 | for _, tree in ipairs(cfg.rocks_trees) do | ||
| 300 | if type(tree) == "string" then | ||
| 301 | util.printout(dir.normalize(tree)) | ||
| 302 | else | ||
| 303 | local name = tree.name and "\t"..tree.name or "" | ||
| 304 | util.printout(dir.normalize(tree.root)..name) | ||
| 305 | end | ||
| 306 | end | ||
| 307 | return true | ||
| 308 | end | ||
| 309 | |||
| 310 | if args.key == "lua_version" and args.value then | ||
| 311 | local scope = get_scope(args) | ||
| 312 | if scope == "project" and not cfg.config_files.project then | ||
| 313 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." | ||
| 314 | end | ||
| 315 | |||
| 316 | local location = cfg.config_files[scope] | ||
| 317 | if (not location) or (not location.file) then | ||
| 318 | return nil, "could not get config file location for " .. tostring(scope) .. " scope" | ||
| 319 | end | ||
| 320 | |||
| 321 | local prefix = dir.dir_name(location.file) | ||
| 322 | local ok, err = persist.save_default_lua_version(prefix, args.value) | ||
| 323 | if not ok then | ||
| 324 | return nil, "could not set default Lua version: " .. err | ||
| 325 | end | ||
| 326 | print("Lua version will default to " .. args.value .. " in " .. prefix) | ||
| 327 | end | ||
| 328 | |||
| 329 | if args.key == "lua_dir" and args.value then | ||
| 330 | local scope = get_scope(args) | ||
| 331 | local keys = { | ||
| 332 | ["variables.LUA_DIR"] = cfg.variables.LUA_DIR, | ||
| 333 | ["variables.LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | ||
| 334 | ["variables.LUA_INCDIR"] = cfg.variables.LUA_INCDIR, | ||
| 335 | ["variables.LUA_LIBDIR"] = cfg.variables.LUA_LIBDIR, | ||
| 336 | ["variables.LUA"] = cfg.variables.LUA, | ||
| 337 | } | ||
| 338 | if args.lua_version then | ||
| 339 | local prefix = dir.dir_name(cfg.config_files[scope].file) | ||
| 340 | persist.save_default_lua_version(prefix, args.lua_version) | ||
| 341 | end | ||
| 342 | local ok, err = write_entries(keys, scope, args.unset) | ||
| 343 | if ok then | ||
| 344 | local inc_ok = report_on_lua_incdir_config(cfg.variables.LUA_INCDIR, lua_version) | ||
| 345 | local lib_ok = ok and report_on_lua_libdir_config(cfg.variables.LUA_LIBDIR, lua_version) | ||
| 346 | if not (inc_ok and lib_ok) then | ||
| 347 | warn_bad_c_config() | ||
| 348 | end | ||
| 349 | end | ||
| 350 | |||
| 351 | return ok, err | ||
| 352 | end | ||
| 353 | |||
| 354 | if args.key then | ||
| 355 | if args.key:match("^[A-Z]") then | ||
| 356 | args.key = "variables." .. args.key | ||
| 357 | end | ||
| 358 | |||
| 359 | if args.value or args.unset then | ||
| 360 | local scope = get_scope(args) | ||
| 361 | |||
| 362 | local ok, err = write_entries({ [args.key] = args.value or args.unset }, scope, args.unset) | ||
| 363 | |||
| 364 | if ok then | ||
| 365 | if args.key == "variables.LUA_INCDIR" then | ||
| 366 | local ok = report_on_lua_incdir_config(args.value, lua_version) | ||
| 367 | if not ok then | ||
| 368 | warn_bad_c_config() | ||
| 369 | end | ||
| 370 | elseif args.key == "variables.LUA_LIBDIR" then | ||
| 371 | local ok = report_on_lua_libdir_config(args.value, lua_version) | ||
| 372 | if not ok then | ||
| 373 | warn_bad_c_config() | ||
| 374 | end | ||
| 375 | end | ||
| 376 | end | ||
| 377 | |||
| 378 | return ok, err | ||
| 379 | else | ||
| 380 | return print_entry(args.key, cfg, args.json) | ||
| 381 | end | ||
| 382 | end | ||
| 383 | |||
| 384 | if args.json then | ||
| 385 | return print_json(config.get_config_for_display(cfg)) | ||
| 386 | else | ||
| 387 | print(config.to_string(cfg)) | ||
| 388 | return true | ||
| 389 | end | ||
| 390 | end | ||
| 391 | |||
| 392 | return config_cmd | ||
diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index d67711a0..c2dd7d82 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | --- Module implementing the LuaRocks "config" command. | 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string |
| 2 | -- Queries information about the LuaRocks configuration. | 2 | |
| 3 | local config_cmd = {} | 3 | local config_cmd = {} |
| 4 | 4 | ||
| 5 | |||
| 5 | local persist = require("luarocks.persist") | 6 | local persist = require("luarocks.persist") |
| 6 | local config = require("luarocks.config") | 7 | local config = require("luarocks.config") |
| 7 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
| @@ -11,6 +12,14 @@ local dir = require("luarocks.dir") | |||
| 11 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
| 12 | local json = require("luarocks.vendor.dkjson") | 13 | local json = require("luarocks.vendor.dkjson") |
| 13 | 14 | ||
| 15 | local argparse = require("luarocks.vendor.argparse") | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 14 | function config_cmd.add_to_parser(parser) | 23 | function config_cmd.add_to_parser(parser) |
| 15 | local cmd = parser:command("config", [[ | 24 | local cmd = parser:command("config", [[ |
| 16 | Query information about the LuaRocks configuration. | 25 | Query information about the LuaRocks configuration. |
| @@ -49,23 +58,23 @@ Query information about the LuaRocks configuration. | |||
| 49 | Example: luarocks config]], util.see_also([[ | 58 | Example: luarocks config]], util.see_also([[ |
| 50 | https://github.com/luarocks/luarocks/wiki/Config-file-format | 59 | https://github.com/luarocks/luarocks/wiki/Config-file-format |
| 51 | for detailed information on the LuaRocks config file format. | 60 | for detailed information on the LuaRocks config file format. |
| 52 | ]])) | 61 | ]])): |
| 53 | :summary("Query information about the LuaRocks configuration.") | 62 | summary("Query information about the LuaRocks configuration.") |
| 54 | 63 | ||
| 55 | cmd:argument("key", "The configuration key.") | 64 | cmd:argument("key", "The configuration key."): |
| 56 | :args("?") | 65 | args("?") |
| 57 | cmd:argument("value", "The configuration value.") | 66 | cmd:argument("value", "The configuration value."): |
| 58 | :args("?") | 67 | args("?") |
| 59 | 68 | ||
| 60 | cmd:option("--scope", "The scope indicates which config file should be rewritten.\n".. | 69 | cmd:option("--scope", "The scope indicates which config file should be rewritten.\n" .. |
| 61 | '* Using a wrapper created with `luarocks init`, the default is "project".\n'.. | 70 | '* Using a wrapper created with `luarocks init`, the default is "project".\n' .. |
| 62 | '* Using --local (or when `local_by_default` is `true`), the default is "user".\n'.. | 71 | '* Using --local (or when `local_by_default` is `true`), the default is "user".\n' .. |
| 63 | '* Otherwise, the default is "system".') | 72 | '* Otherwise, the default is "system".'): |
| 64 | :choices({"system", "user", "project"}) | 73 | choices({ "system", "user", "project" }) |
| 65 | cmd:flag("--unset", "Delete the key from the configuration file.") | 74 | cmd:flag("--unset", "Delete the key from the configuration file.") |
| 66 | cmd:flag("--json", "Output as JSON.") | 75 | cmd:flag("--json", "Output as JSON.") |
| 67 | 76 | ||
| 68 | -- Deprecated flags | 77 | |
| 69 | cmd:flag("--lua-incdir"):hidden(true) | 78 | cmd:flag("--lua-incdir"):hidden(true) |
| 70 | cmd:flag("--lua-libdir"):hidden(true) | 79 | cmd:flag("--lua-libdir"):hidden(true) |
| 71 | cmd:flag("--lua-ver"):hidden(true) | 80 | cmd:flag("--lua-ver"):hidden(true) |
| @@ -84,7 +93,9 @@ local function config_file(conf) | |||
| 84 | end | 93 | end |
| 85 | 94 | ||
| 86 | local function traverse_varstring(var, tbl, fn, missing_parent) | 95 | local function traverse_varstring(var, tbl, fn, missing_parent) |
| 87 | local k, r = var:match("^%[([0-9]+)%]%.(.*)$") | 96 | local k |
| 97 | local r | ||
| 98 | k, r = var:match("^%[([0-9]+)%]%.(.*)$") | ||
| 88 | if k then | 99 | if k then |
| 89 | k = tonumber(k) | 100 | k = tonumber(k) |
| 90 | else | 101 | else |
| @@ -102,13 +113,13 @@ local function traverse_varstring(var, tbl, fn, missing_parent) | |||
| 102 | if tbl[k] then | 113 | if tbl[k] then |
| 103 | return traverse_varstring(r, tbl[k], fn, missing_parent) | 114 | return traverse_varstring(r, tbl[k], fn, missing_parent) |
| 104 | else | 115 | else |
| 105 | return nil, "Unknown entry " .. k | 116 | return nil, "Unknown entry " .. tostring(k) |
| 106 | end | 117 | end |
| 107 | end | 118 | end |
| 108 | 119 | ||
| 109 | local i = var:match("^%[([0-9]+)%]$") | 120 | local i = var:match("^%[([0-9]+)%]$") |
| 110 | if i then | 121 | if i then |
| 111 | var = tonumber(i) | 122 | return fn(tbl, tonumber(i)) |
| 112 | end | 123 | end |
| 113 | 124 | ||
| 114 | return fn(tbl, var) | 125 | return fn(tbl, var) |
| @@ -150,11 +161,12 @@ local function infer_type(var) | |||
| 150 | end | 161 | end |
| 151 | 162 | ||
| 152 | local function write_entries(keys, scope, do_unset) | 163 | local function write_entries(keys, scope, do_unset) |
| 164 | local wrote = {} | ||
| 153 | if scope == "project" and not cfg.config_files.project then | 165 | if scope == "project" and not cfg.config_files.project then |
| 154 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." | 166 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." |
| 155 | end | 167 | end |
| 156 | 168 | ||
| 157 | local file_name = cfg.config_files[scope].file | 169 | local file_name = (cfg.config_files)[scope].file |
| 158 | 170 | ||
| 159 | local tbl, err = persist.load_config_file_if_basic(file_name, cfg) | 171 | local tbl, err = persist.load_config_file_if_basic(file_name, cfg) |
| 160 | if not tbl then | 172 | if not tbl then |
| @@ -165,6 +177,7 @@ local function write_entries(keys, scope, do_unset) | |||
| 165 | traverse_varstring(var, tbl, function(t, k) | 177 | traverse_varstring(var, tbl, function(t, k) |
| 166 | if do_unset then | 178 | if do_unset then |
| 167 | t[k] = nil | 179 | t[k] = nil |
| 180 | wrote[var] = "" | ||
| 168 | else | 181 | else |
| 169 | local typ = infer_type(var) | 182 | local typ = infer_type(var) |
| 170 | local v | 183 | local v |
| @@ -178,7 +191,7 @@ local function write_entries(keys, scope, do_unset) | |||
| 178 | v = val | 191 | v = val |
| 179 | end | 192 | end |
| 180 | t[k] = v | 193 | t[k] = v |
| 181 | keys[var] = v | 194 | wrote[var] = v |
| 182 | end | 195 | end |
| 183 | return true | 196 | return true |
| 184 | end, function(p, k) | 197 | end, function(p, k) |
| @@ -194,7 +207,7 @@ local function write_entries(keys, scope, do_unset) | |||
| 194 | ok, err = persist.save_from_table(file_name, tbl) | 207 | ok, err = persist.save_from_table(file_name, tbl) |
| 195 | if ok then | 208 | if ok then |
| 196 | print(do_unset and "Removed" or "Wrote") | 209 | print(do_unset and "Removed" or "Wrote") |
| 197 | for var, val in util.sortedpairs(keys) do | 210 | for var, val in util.sortedpairs(wrote) do |
| 198 | if do_unset then | 211 | if do_unset then |
| 199 | print(("\t%s"):format(var)) | 212 | print(("\t%s"):format(var)) |
| 200 | else | 213 | else |
| @@ -214,15 +227,15 @@ local function write_entries(keys, scope, do_unset) | |||
| 214 | end | 227 | end |
| 215 | 228 | ||
| 216 | local function get_scope(args) | 229 | local function get_scope(args) |
| 217 | return args.scope | 230 | return args.scope or |
| 218 | or (args["local"] and "user") | 231 | (args["local"] and "user") or |
| 219 | or (args.project_tree and "project") | 232 | (args.project_tree and "project") or |
| 220 | or (cfg.local_by_default and "user") | 233 | (cfg.local_by_default and "user") or |
| 221 | or (fs.is_writable(cfg.config_files["system"].file) and "system") | 234 | (fs.is_writable(cfg.config_files["system"].file) and "system") or |
| 222 | or "user" | 235 | "user" |
| 223 | end | 236 | end |
| 224 | 237 | ||
| 225 | local function report_on_lua_incdir_config(value, lua_version) | 238 | local function report_on_lua_incdir_config(value) |
| 226 | local variables = { | 239 | local variables = { |
| 227 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | 240 | ["LUA_DIR"] = cfg.variables.LUA_DIR, |
| 228 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | 241 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, |
| @@ -231,7 +244,7 @@ local function report_on_lua_incdir_config(value, lua_version) | |||
| 231 | ["LUA"] = cfg.variables.LUA, | 244 | ["LUA"] = cfg.variables.LUA, |
| 232 | } | 245 | } |
| 233 | 246 | ||
| 234 | local ok, err = deps.check_lua_incdir(variables, lua_version) | 247 | local ok, err = deps.check_lua_incdir(variables) |
| 235 | if not ok then | 248 | if not ok then |
| 236 | util.printerr() | 249 | util.printerr() |
| 237 | util.warning((err:gsub(" You can use.*", ""))) | 250 | util.warning((err:gsub(" You can use.*", ""))) |
| @@ -239,7 +252,7 @@ local function report_on_lua_incdir_config(value, lua_version) | |||
| 239 | return ok | 252 | return ok |
| 240 | end | 253 | end |
| 241 | 254 | ||
| 242 | local function report_on_lua_libdir_config(value, lua_version) | 255 | local function report_on_lua_libdir_config(value) |
| 243 | local variables = { | 256 | local variables = { |
| 244 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | 257 | ["LUA_DIR"] = cfg.variables.LUA_DIR, |
| 245 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | 258 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, |
| @@ -248,7 +261,7 @@ local function report_on_lua_libdir_config(value, lua_version) | |||
| 248 | ["LUA"] = cfg.variables.LUA, | 261 | ["LUA"] = cfg.variables.LUA, |
| 249 | } | 262 | } |
| 250 | 263 | ||
| 251 | local ok, err, _, err_files = deps.check_lua_libdir(variables, lua_version) | 264 | local ok, err, _, err_files = deps.check_lua_libdir(variables) |
| 252 | if not ok then | 265 | if not ok then |
| 253 | util.printerr() | 266 | util.printerr() |
| 254 | util.warning((err:gsub(" You can use.*", ""))) | 267 | util.warning((err:gsub(" You can use.*", ""))) |
| @@ -268,15 +281,14 @@ local function warn_bad_c_config() | |||
| 268 | util.printerr() | 281 | util.printerr() |
| 269 | end | 282 | end |
| 270 | 283 | ||
| 271 | --- Driver function for "config" command. | 284 | |
| 272 | -- @return boolean: True if succeeded, nil on errors. | 285 | |
| 273 | function config_cmd.command(args) | 286 | function config_cmd.command(args) |
| 274 | local lua_version = args.lua_version or cfg.lua_version | ||
| 275 | 287 | ||
| 276 | deps.check_lua_incdir(cfg.variables, lua_version) | 288 | deps.check_lua_incdir(cfg.variables) |
| 277 | deps.check_lua_libdir(cfg.variables, lua_version) | 289 | deps.check_lua_libdir(cfg.variables) |
| 290 | |||
| 278 | 291 | ||
| 279 | -- deprecated flags | ||
| 280 | if args.lua_incdir then | 292 | if args.lua_incdir then |
| 281 | print(cfg.variables.LUA_INCDIR) | 293 | print(cfg.variables.LUA_INCDIR) |
| 282 | return true | 294 | return true |
| @@ -297,12 +309,12 @@ function config_cmd.command(args) | |||
| 297 | end | 309 | end |
| 298 | if args.rock_trees then | 310 | if args.rock_trees then |
| 299 | for _, tree in ipairs(cfg.rocks_trees) do | 311 | for _, tree in ipairs(cfg.rocks_trees) do |
| 300 | if type(tree) == "string" then | 312 | if type(tree) == "string" then |
| 301 | util.printout(dir.normalize(tree)) | 313 | util.printout(dir.normalize(tree)) |
| 302 | else | 314 | else |
| 303 | local name = tree.name and "\t"..tree.name or "" | 315 | local name = tree.name and "\t" .. tree.name or "" |
| 304 | util.printout(dir.normalize(tree.root)..name) | 316 | util.printout(dir.normalize(tree.root) .. name) |
| 305 | end | 317 | end |
| 306 | end | 318 | end |
| 307 | return true | 319 | return true |
| 308 | end | 320 | end |
| @@ -313,7 +325,7 @@ function config_cmd.command(args) | |||
| 313 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." | 325 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." |
| 314 | end | 326 | end |
| 315 | 327 | ||
| 316 | local location = cfg.config_files[scope] | 328 | local location = (cfg.config_files)[scope] |
| 317 | if (not location) or (not location.file) then | 329 | if (not location) or (not location.file) then |
| 318 | return nil, "could not get config file location for " .. tostring(scope) .. " scope" | 330 | return nil, "could not get config file location for " .. tostring(scope) .. " scope" |
| 319 | end | 331 | end |
| @@ -336,13 +348,13 @@ function config_cmd.command(args) | |||
| 336 | ["variables.LUA"] = cfg.variables.LUA, | 348 | ["variables.LUA"] = cfg.variables.LUA, |
| 337 | } | 349 | } |
| 338 | if args.lua_version then | 350 | if args.lua_version then |
| 339 | local prefix = dir.dir_name(cfg.config_files[scope].file) | 351 | local prefix = dir.dir_name((cfg.config_files)[scope].file) |
| 340 | persist.save_default_lua_version(prefix, args.lua_version) | 352 | persist.save_default_lua_version(prefix, args.lua_version) |
| 341 | end | 353 | end |
| 342 | local ok, err = write_entries(keys, scope, args.unset) | 354 | local ok, err = write_entries(keys, scope, args.unset) |
| 343 | if ok then | 355 | if ok then |
| 344 | local inc_ok = report_on_lua_incdir_config(cfg.variables.LUA_INCDIR, lua_version) | 356 | local inc_ok = report_on_lua_incdir_config(cfg.variables.LUA_INCDIR) |
| 345 | local lib_ok = ok and report_on_lua_libdir_config(cfg.variables.LUA_LIBDIR, lua_version) | 357 | local lib_ok = ok and report_on_lua_libdir_config(cfg.variables.LUA_LIBDIR) |
| 346 | if not (inc_ok and lib_ok) then | 358 | if not (inc_ok and lib_ok) then |
| 347 | warn_bad_c_config() | 359 | warn_bad_c_config() |
| 348 | end | 360 | end |
| @@ -359,16 +371,16 @@ function config_cmd.command(args) | |||
| 359 | if args.value or args.unset then | 371 | if args.value or args.unset then |
| 360 | local scope = get_scope(args) | 372 | local scope = get_scope(args) |
| 361 | 373 | ||
| 362 | local ok, err = write_entries({ [args.key] = args.value or args.unset }, scope, args.unset) | 374 | local ok, err = write_entries({ [args.key] = args.value or "" }, scope, args.unset) |
| 363 | 375 | ||
| 364 | if ok then | 376 | if ok then |
| 365 | if args.key == "variables.LUA_INCDIR" then | 377 | if args.key == "variables.LUA_INCDIR" then |
| 366 | local ok = report_on_lua_incdir_config(args.value, lua_version) | 378 | local ok = report_on_lua_incdir_config(args.value) |
| 367 | if not ok then | 379 | if not ok then |
| 368 | warn_bad_c_config() | 380 | warn_bad_c_config() |
| 369 | end | 381 | end |
| 370 | elseif args.key == "variables.LUA_LIBDIR" then | 382 | elseif args.key == "variables.LUA_LIBDIR" then |
| 371 | local ok = report_on_lua_libdir_config(args.value, lua_version) | 383 | local ok = report_on_lua_libdir_config(args.value) |
| 372 | if not ok then | 384 | if not ok then |
| 373 | warn_bad_c_config() | 385 | warn_bad_c_config() |
| 374 | end | 386 | end |
diff --git a/src/luarocks/cmd/config.tl b/src/luarocks/cmd/config.tl index 75e99198..6fe63471 100644 --- a/src/luarocks/cmd/config.tl +++ b/src/luarocks/cmd/config.tl | |||
| @@ -18,8 +18,7 @@ local type Parser = argparse.Parser | |||
| 18 | local type a = require("luarocks.core.types.args") | 18 | local type a = require("luarocks.core.types.args") |
| 19 | local type Args = a.Args | 19 | local type Args = a.Args |
| 20 | 20 | ||
| 21 | local type p = require("luarocks.core.types.persist") | 21 | local type PersistableTable = require("luarocks.core.types.persist").PersistableTable |
| 22 | local type PersistableTable = p.PersistableTable | ||
| 23 | 22 | ||
| 24 | function config_cmd.add_to_parser(parser: Parser) | 23 | function config_cmd.add_to_parser(parser: Parser) |
| 25 | local cmd = parser:command("config", [[ | 24 | local cmd = parser:command("config", [[ |
| @@ -93,9 +92,10 @@ local function config_file(conf: cfg.conf): boolean, string | |||
| 93 | end | 92 | end |
| 94 | end | 93 | end |
| 95 | 94 | ||
| 96 | local function traverse_varstring(var: string, tbl: PersistableTable, fn: function(PersistableTable, string): (boolean, string), missing_parent?: function): boolean, string | 95 | local function traverse_varstring(var: string, tbl: PersistableTable, fn: function(PersistableTable, string | number): (boolean, string), missing_parent?: function(PersistableTable, string | number)): boolean, string |
| 97 | local k, rs = var:match("^%[([0-9]+)%]%.(.*)$") | 96 | local k: string | number |
| 98 | local r: string | 97 | local r: string |
| 98 | k, r = var:match("^%[([0-9]+)%]%.(.*)$") | ||
| 99 | if k then | 99 | if k then |
| 100 | k = tonumber(k) | 100 | k = tonumber(k) |
| 101 | else | 101 | else |
| @@ -113,13 +113,13 @@ local function traverse_varstring(var: string, tbl: PersistableTable, fn: functi | |||
| 113 | if tbl[k] then | 113 | if tbl[k] then |
| 114 | return traverse_varstring(r, tbl[k] as PersistableTable, fn, missing_parent) | 114 | return traverse_varstring(r, tbl[k] as PersistableTable, fn, missing_parent) |
| 115 | else | 115 | else |
| 116 | return nil, "Unknown entry " .. k | 116 | return nil, "Unknown entry " .. tostring(k) |
| 117 | end | 117 | end |
| 118 | end | 118 | end |
| 119 | 119 | ||
| 120 | local i = var:match("^%[([0-9]+)%]$") | 120 | local i = var:match("^%[([0-9]+)%]$") |
| 121 | if i then | 121 | if i then |
| 122 | local var = tonumber(i) | 122 | return fn(tbl, tonumber(i)) |
| 123 | end | 123 | end |
| 124 | 124 | ||
| 125 | return fn(tbl, var) | 125 | return fn(tbl, var) |
| @@ -160,7 +160,8 @@ local function infer_type(var: string): string | |||
| 160 | return typ | 160 | return typ |
| 161 | end | 161 | end |
| 162 | 162 | ||
| 163 | local function write_entries(keys: {string: any}, scope: string, do_unset: boolean): boolean, string | 163 | local function write_entries(keys: {string: string}, scope: string, do_unset: boolean): boolean, string |
| 164 | local wrote: PersistableTable = {} | ||
| 164 | if scope == "project" and not cfg.config_files.project then | 165 | if scope == "project" and not cfg.config_files.project then |
| 165 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." | 166 | return nil, "Current directory is not part of a project. You may want to run `luarocks init`." |
| 166 | end | 167 | end |
| @@ -173,12 +174,13 @@ local function write_entries(keys: {string: any}, scope: string, do_unset: boole | |||
| 173 | end | 174 | end |
| 174 | 175 | ||
| 175 | for var, val in util.sortedpairs(keys) do | 176 | for var, val in util.sortedpairs(keys) do |
| 176 | traverse_varstring(var, tbl, function(t: PersistableTable, k: string): boolean, string | 177 | traverse_varstring(var, tbl, function(t: PersistableTable, k: string | number): boolean, string |
| 177 | if do_unset then | 178 | if do_unset then |
| 178 | t[k] = nil | 179 | t[k] = nil |
| 180 | wrote[var] = "" | ||
| 179 | else | 181 | else |
| 180 | local typ = infer_type(var) | 182 | local typ = infer_type(var) |
| 181 | local v | 183 | local v: string | number | boolean |
| 182 | if typ == "number" and tonumber(val) then | 184 | if typ == "number" and tonumber(val) then |
| 183 | v = tonumber(val) | 185 | v = tonumber(val) |
| 184 | elseif typ == "boolean" and val == "true" then | 186 | elseif typ == "boolean" and val == "true" then |
| @@ -189,10 +191,10 @@ local function write_entries(keys: {string: any}, scope: string, do_unset: boole | |||
| 189 | v = val | 191 | v = val |
| 190 | end | 192 | end |
| 191 | t[k] = v | 193 | t[k] = v |
| 192 | keys[var] = v | 194 | wrote[var] = v |
| 193 | end | 195 | end |
| 194 | return true | 196 | return true |
| 195 | end, function(p, k) | 197 | end, function(p: PersistableTable, k: string | number) |
| 196 | p[k] = {} | 198 | p[k] = {} |
| 197 | end) | 199 | end) |
| 198 | end | 200 | end |
| @@ -205,11 +207,11 @@ local function write_entries(keys: {string: any}, scope: string, do_unset: boole | |||
| 205 | ok, err = persist.save_from_table(file_name, tbl) | 207 | ok, err = persist.save_from_table(file_name, tbl) |
| 206 | if ok then | 208 | if ok then |
| 207 | print(do_unset and "Removed" or "Wrote") | 209 | print(do_unset and "Removed" or "Wrote") |
| 208 | for var, val in util.sortedpairs(keys) do | 210 | for var, val in util.sortedpairs(wrote) do |
| 209 | if do_unset then | 211 | if do_unset then |
| 210 | print(("\t%s"):format(var)) | 212 | print(("\t%s"):format(var)) |
| 211 | else | 213 | else |
| 212 | if type(val) == "string" then | 214 | if val is string then |
| 213 | print(("\t%s = %q"):format(var, val)) | 215 | print(("\t%s = %q"):format(var, val)) |
| 214 | else | 216 | else |
| 215 | print(("\t%s = %s"):format(var, tostring(val))) | 217 | print(("\t%s = %s"):format(var, tostring(val))) |
| @@ -233,7 +235,7 @@ local function get_scope(args: Args): string | |||
| 233 | or "user" | 235 | or "user" |
| 234 | end | 236 | end |
| 235 | 237 | ||
| 236 | local function report_on_lua_incdir_config(value: string, lua_version: string): boolean | 238 | local function report_on_lua_incdir_config(value: string): boolean |
| 237 | local variables = { | 239 | local variables = { |
| 238 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | 240 | ["LUA_DIR"] = cfg.variables.LUA_DIR, |
| 239 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | 241 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, |
| @@ -242,7 +244,7 @@ local function report_on_lua_incdir_config(value: string, lua_version: string): | |||
| 242 | ["LUA"] = cfg.variables.LUA, | 244 | ["LUA"] = cfg.variables.LUA, |
| 243 | } | 245 | } |
| 244 | 246 | ||
| 245 | local ok, err = deps.check_lua_incdir(variables, lua_version) --! | 247 | local ok, err = deps.check_lua_incdir(variables) |
| 246 | if not ok then | 248 | if not ok then |
| 247 | util.printerr() | 249 | util.printerr() |
| 248 | util.warning((err:gsub(" You can use.*", ""))) | 250 | util.warning((err:gsub(" You can use.*", ""))) |
| @@ -250,7 +252,7 @@ local function report_on_lua_incdir_config(value: string, lua_version: string): | |||
| 250 | return ok | 252 | return ok |
| 251 | end | 253 | end |
| 252 | 254 | ||
| 253 | local function report_on_lua_libdir_config(value: string, lua_version: string): boolean | 255 | local function report_on_lua_libdir_config(value: string): boolean |
| 254 | local variables = { | 256 | local variables = { |
| 255 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | 257 | ["LUA_DIR"] = cfg.variables.LUA_DIR, |
| 256 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | 258 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, |
| @@ -259,7 +261,7 @@ local function report_on_lua_libdir_config(value: string, lua_version: string): | |||
| 259 | ["LUA"] = cfg.variables.LUA, | 261 | ["LUA"] = cfg.variables.LUA, |
| 260 | } | 262 | } |
| 261 | 263 | ||
| 262 | local ok, err, _, err_files = deps.check_lua_libdir(variables, lua_version) --! | 264 | local ok, err, _, err_files = deps.check_lua_libdir(variables) |
| 263 | if not ok then | 265 | if not ok then |
| 264 | util.printerr() | 266 | util.printerr() |
| 265 | util.warning((err:gsub(" You can use.*", ""))) | 267 | util.warning((err:gsub(" You can use.*", ""))) |
| @@ -282,10 +284,9 @@ end | |||
| 282 | --- Driver function for "config" command. | 284 | --- Driver function for "config" command. |
| 283 | -- @return boolean: True if succeeded, nil on errors. | 285 | -- @return boolean: True if succeeded, nil on errors. |
| 284 | function config_cmd.command(args: Args): boolean, string | 286 | function config_cmd.command(args: Args): boolean, string |
| 285 | local lua_version = args.lua_version or cfg.lua_version | ||
| 286 | 287 | ||
| 287 | deps.check_lua_incdir(cfg.variables, lua_version) | 288 | deps.check_lua_incdir(cfg.variables) |
| 288 | deps.check_lua_libdir(cfg.variables, lua_version) | 289 | deps.check_lua_libdir(cfg.variables) |
| 289 | 290 | ||
| 290 | -- deprecated flags | 291 | -- deprecated flags |
| 291 | if args.lua_incdir then | 292 | if args.lua_incdir then |
| @@ -352,8 +353,8 @@ function config_cmd.command(args: Args): boolean, string | |||
| 352 | end | 353 | end |
| 353 | local ok, err = write_entries(keys, scope, args.unset) | 354 | local ok, err = write_entries(keys, scope, args.unset) |
| 354 | if ok then | 355 | if ok then |
| 355 | local inc_ok = report_on_lua_incdir_config(cfg.variables.LUA_INCDIR, lua_version) | 356 | local inc_ok = report_on_lua_incdir_config(cfg.variables.LUA_INCDIR) |
| 356 | local lib_ok = ok and report_on_lua_libdir_config(cfg.variables.LUA_LIBDIR, lua_version) | 357 | local lib_ok = ok and report_on_lua_libdir_config(cfg.variables.LUA_LIBDIR) |
| 357 | if not (inc_ok and lib_ok) then | 358 | if not (inc_ok and lib_ok) then |
| 358 | warn_bad_c_config() | 359 | warn_bad_c_config() |
| 359 | end | 360 | end |
| @@ -370,16 +371,16 @@ function config_cmd.command(args: Args): boolean, string | |||
| 370 | if args.value or args.unset then | 371 | if args.value or args.unset then |
| 371 | local scope = get_scope(args) | 372 | local scope = get_scope(args) |
| 372 | 373 | ||
| 373 | local ok, err = write_entries({ [args.key] = args.value or args.unset }, scope, args.unset) | 374 | local ok, err = write_entries({ [args.key] = args.value or "" }, scope, args.unset) |
| 374 | 375 | ||
| 375 | if ok then | 376 | if ok then |
| 376 | if args.key == "variables.LUA_INCDIR" then | 377 | if args.key == "variables.LUA_INCDIR" then |
| 377 | local ok = report_on_lua_incdir_config(args.value, lua_version) | 378 | local ok = report_on_lua_incdir_config(args.value) |
| 378 | if not ok then | 379 | if not ok then |
| 379 | warn_bad_c_config() | 380 | warn_bad_c_config() |
| 380 | end | 381 | end |
| 381 | elseif args.key == "variables.LUA_LIBDIR" then | 382 | elseif args.key == "variables.LUA_LIBDIR" then |
| 382 | local ok = report_on_lua_libdir_config(args.value, lua_version) | 383 | local ok = report_on_lua_libdir_config(args.value) |
| 383 | if not ok then | 384 | if not ok then |
| 384 | warn_bad_c_config() | 385 | warn_bad_c_config() |
| 385 | end | 386 | end |
diff --git a/src/luarocks/cmd/install-original.lua b/src/luarocks/cmd/install-original.lua new file mode 100644 index 00000000..e00b964d --- /dev/null +++ b/src/luarocks/cmd/install-original.lua | |||
| @@ -0,0 +1,250 @@ | |||
| 1 | --- Module implementing the LuaRocks "install" command. | ||
| 2 | -- Installs binary rocks. | ||
| 3 | local install = {} | ||
| 4 | |||
| 5 | local dir = require("luarocks.dir") | ||
| 6 | local path = require("luarocks.path") | ||
| 7 | local repos = require("luarocks.repos") | ||
| 8 | local fetch = require("luarocks.fetch") | ||
| 9 | local util = require("luarocks.util") | ||
| 10 | local fs = require("luarocks.fs") | ||
| 11 | local deps = require("luarocks.deps") | ||
| 12 | local repo_writer = require("luarocks.repo_writer") | ||
| 13 | local remove = require("luarocks.remove") | ||
| 14 | local search = require("luarocks.search") | ||
| 15 | local queries = require("luarocks.queries") | ||
| 16 | local cfg = require("luarocks.core.cfg") | ||
| 17 | |||
| 18 | function install.add_to_parser(parser) | ||
| 19 | local cmd = parser:command("install", "Install a rock.", util.see_also()) -- luacheck: ignore 431 | ||
| 20 | |||
| 21 | cmd:argument("rock", "The name of a rock to be fetched from a repository ".. | ||
| 22 | "or a filename of a locally available rock.") | ||
| 23 | :action(util.namespaced_name_action) | ||
| 24 | cmd:argument("version", "Version of the rock.") | ||
| 25 | :args("?") | ||
| 26 | |||
| 27 | cmd:flag("--keep", "Do not remove previously installed versions of the ".. | ||
| 28 | "rock after building a new one. This behavior can be made permanent by ".. | ||
| 29 | "setting keep_other_versions=true in the configuration file.") | ||
| 30 | cmd:flag("--force", "If --keep is not specified, force removal of ".. | ||
| 31 | "previously installed versions if it would break dependencies. ".. | ||
| 32 | "If rock is already installed, reinstall it anyway.") | ||
| 33 | cmd:flag("--force-fast", "Like --force, but performs a forced removal ".. | ||
| 34 | "without reporting dependency issues.") | ||
| 35 | cmd:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") | ||
| 36 | cmd:flag("--no-doc", "Install the rock without its documentation.") | ||
| 37 | cmd:flag("--verify", "Verify signature of the rockspec or src.rock being ".. | ||
| 38 | "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. | ||
| 39 | "attempt to download the signature as well. Otherwise, the signature ".. | ||
| 40 | "file should be already available locally in the same directory.\n".. | ||
| 41 | "You need the signer’s public key in your local keyring for this ".. | ||
| 42 | "option to work properly.") | ||
| 43 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | ||
| 44 | "and report if it is available for another Lua version.") | ||
| 45 | util.deps_mode_option(cmd) | ||
| 46 | cmd:flag("--no-manifest", "Skip creating/updating the manifest") | ||
| 47 | cmd:flag("--pin", "If the installed rock is a Lua module, create a ".. | ||
| 48 | "luarocks.lock file listing the exact versions of each dependency found for ".. | ||
| 49 | "this rock (recursively), and store it in the rock's directory. ".. | ||
| 50 | "Ignores any existing luarocks.lock file in the rock's sources.") | ||
| 51 | -- luarocks build options | ||
| 52 | parser:flag("--pack-binary-rock"):hidden(true) | ||
| 53 | parser:option("--branch"):hidden(true) | ||
| 54 | parser:flag("--sign"):hidden(true) | ||
| 55 | end | ||
| 56 | |||
| 57 | |||
| 58 | --- Install a binary rock. | ||
| 59 | -- @param rock_file string: local or remote filename of a rock. | ||
| 60 | -- @param opts table: installation options | ||
| 61 | -- @return (string, string) or (nil, string, [string]): Name and version of | ||
| 62 | -- installed rock if succeeded or nil and an error message followed by an error code. | ||
| 63 | function install.install_binary_rock(rock_file, opts) | ||
| 64 | assert(type(rock_file) == "string") | ||
| 65 | |||
| 66 | local namespace = opts.namespace | ||
| 67 | local deps_mode = opts.deps_mode | ||
| 68 | |||
| 69 | local name, version, arch = path.parse_name(rock_file) | ||
| 70 | if not name then | ||
| 71 | return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." | ||
| 72 | end | ||
| 73 | |||
| 74 | if arch ~= "all" and arch ~= cfg.arch then | ||
| 75 | return nil, "Incompatible architecture "..arch, "arch" | ||
| 76 | end | ||
| 77 | if repos.is_installed(name, version) then | ||
| 78 | if not (opts.force or opts.force_fast) then | ||
| 79 | util.printout(name .. " " .. version .. " is already installed in " .. path.root_dir(cfg.root_dir)) | ||
| 80 | util.printout("Use --force to reinstall.") | ||
| 81 | return name, version | ||
| 82 | end | ||
| 83 | repo_writer.delete_version(name, version, opts.deps_mode) | ||
| 84 | end | ||
| 85 | |||
| 86 | local install_dir = path.install_dir(name, version) | ||
| 87 | |||
| 88 | local rollback = util.schedule_function(function() | ||
| 89 | fs.delete(install_dir) | ||
| 90 | fs.remove_dir_if_empty(path.versions_dir(name)) | ||
| 91 | end) | ||
| 92 | |||
| 93 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) | ||
| 94 | if not ok then return nil, err, errcode end | ||
| 95 | |||
| 96 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) | ||
| 97 | if err then | ||
| 98 | return nil, "Failed loading rockspec for installed package: "..err, errcode | ||
| 99 | end | ||
| 100 | |||
| 101 | if opts.deps_mode ~= "none" then | ||
| 102 | ok, err, errcode = deps.check_external_deps(rockspec, "install") | ||
| 103 | if err then return nil, err, errcode end | ||
| 104 | end | ||
| 105 | |||
| 106 | if deps_mode ~= "none" then | ||
| 107 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) | ||
| 108 | and "." | ||
| 109 | or install_dir | ||
| 110 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", deps_mode, opts.verify, deplock_dir) | ||
| 111 | if err then return nil, err, errcode end | ||
| 112 | end | ||
| 113 | |||
| 114 | ok, err = repo_writer.deploy_files(name, version, repos.should_wrap_bin_scripts(rockspec), deps_mode, namespace) | ||
| 115 | if err then return nil, err end | ||
| 116 | |||
| 117 | util.remove_scheduled_function(rollback) | ||
| 118 | rollback = util.schedule_function(function() | ||
| 119 | repo_writer.delete_version(name, version, deps_mode) | ||
| 120 | end) | ||
| 121 | |||
| 122 | ok, err = repos.run_hook(rockspec, "post_install") | ||
| 123 | if err then return nil, err end | ||
| 124 | |||
| 125 | util.announce_install(rockspec) | ||
| 126 | util.remove_scheduled_function(rollback) | ||
| 127 | return name, version | ||
| 128 | end | ||
| 129 | |||
| 130 | --- Installs the dependencies of a binary rock. | ||
| 131 | -- @param rock_file string: local or remote filename of a rock. | ||
| 132 | -- @param opts table: installation options | ||
| 133 | -- @return (string, string) or (nil, string, [string]): Name and version of | ||
| 134 | -- the rock whose dependencies were installed if succeeded or nil and an error message | ||
| 135 | -- followed by an error code. | ||
| 136 | function install.install_binary_rock_deps(rock_file, opts) | ||
| 137 | assert(type(rock_file) == "string") | ||
| 138 | |||
| 139 | local name, version, arch = path.parse_name(rock_file) | ||
| 140 | if not name then | ||
| 141 | return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." | ||
| 142 | end | ||
| 143 | |||
| 144 | if arch ~= "all" and arch ~= cfg.arch then | ||
| 145 | return nil, "Incompatible architecture "..arch, "arch" | ||
| 146 | end | ||
| 147 | |||
| 148 | local install_dir = path.install_dir(name, version) | ||
| 149 | |||
| 150 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) | ||
| 151 | if not ok then return nil, err, errcode end | ||
| 152 | |||
| 153 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) | ||
| 154 | if err then | ||
| 155 | return nil, "Failed loading rockspec for installed package: "..err, errcode | ||
| 156 | end | ||
| 157 | |||
| 158 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) | ||
| 159 | and "." | ||
| 160 | or install_dir | ||
| 161 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode, opts.verify, deplock_dir) | ||
| 162 | if err then return nil, err, errcode end | ||
| 163 | |||
| 164 | util.printout() | ||
| 165 | util.printout("Successfully installed dependencies for " ..name.." "..version) | ||
| 166 | |||
| 167 | return name, version | ||
| 168 | end | ||
| 169 | |||
| 170 | local function install_rock_file_deps(filename, opts) | ||
| 171 | |||
| 172 | local name, version = install.install_binary_rock_deps(filename, opts) | ||
| 173 | if not name then return nil, version end | ||
| 174 | |||
| 175 | deps.check_dependencies(nil, opts.deps_mode) | ||
| 176 | return name, version | ||
| 177 | end | ||
| 178 | |||
| 179 | local function install_rock_file(filename, opts) | ||
| 180 | assert(type(filename) == "string") | ||
| 181 | |||
| 182 | local name, version = install.install_binary_rock(filename, opts) | ||
| 183 | if not name then return nil, version end | ||
| 184 | |||
| 185 | if opts.no_doc then | ||
| 186 | util.remove_doc_dir(name, version) | ||
| 187 | end | ||
| 188 | |||
| 189 | if (not opts.keep) and not cfg.keep_other_versions then | ||
| 190 | local ok, err, warn = remove.remove_other_versions(name, version, opts.force, opts.force_fast) | ||
| 191 | if not ok then | ||
| 192 | return nil, err | ||
| 193 | elseif warn then | ||
| 194 | util.printerr(err) | ||
| 195 | end | ||
| 196 | end | ||
| 197 | |||
| 198 | deps.check_dependencies(nil, opts.deps_mode) | ||
| 199 | return name, version | ||
| 200 | end | ||
| 201 | |||
| 202 | --- Driver function for the "install" command. | ||
| 203 | -- If an URL or pathname to a binary rock is given, fetches and installs it. | ||
| 204 | -- If a rockspec or a source rock is given, forwards the request to the "build" | ||
| 205 | -- command. | ||
| 206 | -- If a package name is given, forwards the request to "search" and, | ||
| 207 | -- if returned a result, installs the matching rock. | ||
| 208 | -- @return boolean or (nil, string, exitcode): True if installation was | ||
| 209 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | ||
| 210 | function install.command(args) | ||
| 211 | if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then | ||
| 212 | local build = require("luarocks.cmd.build") | ||
| 213 | return build.command(args) | ||
| 214 | elseif args.rock:match("%.rock$") then | ||
| 215 | local deps_mode = deps.get_deps_mode(args) | ||
| 216 | local opts = { | ||
| 217 | namespace = args.namespace, | ||
| 218 | keep = not not args.keep, | ||
| 219 | force = not not args.force, | ||
| 220 | force_fast = not not args.force_fast, | ||
| 221 | no_doc = not not args.no_doc, | ||
| 222 | deps_mode = deps_mode, | ||
| 223 | verify = not not args.verify, | ||
| 224 | } | ||
| 225 | if args.only_deps then | ||
| 226 | return install_rock_file_deps(args.rock, opts) | ||
| 227 | else | ||
| 228 | return install_rock_file(args.rock, opts) | ||
| 229 | end | ||
| 230 | else | ||
| 231 | local url, err = search.find_rock_checking_lua_versions( | ||
| 232 | queries.new(args.rock, args.namespace, args.version), | ||
| 233 | args.check_lua_versions) | ||
| 234 | if not url then | ||
| 235 | return nil, err | ||
| 236 | end | ||
| 237 | util.printout("Installing "..url) | ||
| 238 | args.rock = url | ||
| 239 | return install.command(args) | ||
| 240 | end | ||
| 241 | end | ||
| 242 | |||
| 243 | install.needs_lock = function(args) | ||
| 244 | if args.pack_binary_rock then | ||
| 245 | return false | ||
| 246 | end | ||
| 247 | return true | ||
| 248 | end | ||
| 249 | |||
| 250 | return install | ||
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index e00b964d..11e36b8c 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | --- Module implementing the LuaRocks "install" command. | 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert |
| 2 | -- Installs binary rocks. | 2 | |
| 3 | local install = {} | 3 | local install = {} |
| 4 | 4 | ||
| 5 | |||
| 6 | |||
| 5 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
| 6 | local path = require("luarocks.path") | 8 | local path = require("luarocks.path") |
| 7 | local repos = require("luarocks.repos") | 9 | local repos = require("luarocks.repos") |
| @@ -15,51 +17,61 @@ local search = require("luarocks.search") | |||
| 15 | local queries = require("luarocks.queries") | 17 | local queries = require("luarocks.queries") |
| 16 | local cfg = require("luarocks.core.cfg") | 18 | local cfg = require("luarocks.core.cfg") |
| 17 | 19 | ||
| 20 | local argparse = require("luarocks.vendor.argparse") | ||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 18 | function install.add_to_parser(parser) | 30 | function install.add_to_parser(parser) |
| 19 | local cmd = parser:command("install", "Install a rock.", util.see_also()) -- luacheck: ignore 431 | 31 | local cmd = parser:command("install", "Install a rock.", util.see_also()) |
| 20 | 32 | ||
| 21 | cmd:argument("rock", "The name of a rock to be fetched from a repository ".. | 33 | cmd:argument("rock", "The name of a rock to be fetched from a repository " .. |
| 22 | "or a filename of a locally available rock.") | 34 | "or a filename of a locally available rock."): |
| 23 | :action(util.namespaced_name_action) | 35 | action(util.namespaced_name_action) |
| 24 | cmd:argument("version", "Version of the rock.") | 36 | cmd:argument("version", "Version of the rock."): |
| 25 | :args("?") | 37 | args("?") |
| 26 | 38 | ||
| 27 | cmd:flag("--keep", "Do not remove previously installed versions of the ".. | 39 | cmd:flag("--keep", "Do not remove previously installed versions of the " .. |
| 28 | "rock after building a new one. This behavior can be made permanent by ".. | 40 | "rock after building a new one. This behavior can be made permanent by " .. |
| 29 | "setting keep_other_versions=true in the configuration file.") | 41 | "setting keep_other_versions=true in the configuration file.") |
| 30 | cmd:flag("--force", "If --keep is not specified, force removal of ".. | 42 | cmd:flag("--force", "If --keep is not specified, force removal of " .. |
| 31 | "previously installed versions if it would break dependencies. ".. | 43 | "previously installed versions if it would break dependencies. " .. |
| 32 | "If rock is already installed, reinstall it anyway.") | 44 | "If rock is already installed, reinstall it anyway.") |
| 33 | cmd:flag("--force-fast", "Like --force, but performs a forced removal ".. | 45 | cmd:flag("--force-fast", "Like --force, but performs a forced removal " .. |
| 34 | "without reporting dependency issues.") | 46 | "without reporting dependency issues.") |
| 35 | cmd:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") | 47 | cmd:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") |
| 36 | cmd:flag("--no-doc", "Install the rock without its documentation.") | 48 | cmd:flag("--no-doc", "Install the rock without its documentation.") |
| 37 | cmd:flag("--verify", "Verify signature of the rockspec or src.rock being ".. | 49 | cmd:flag("--verify", "Verify signature of the rockspec or src.rock being " .. |
| 38 | "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. | 50 | "built. If the rockspec or src.rock is being downloaded, LuaRocks will " .. |
| 39 | "attempt to download the signature as well. Otherwise, the signature ".. | 51 | "attempt to download the signature as well. Otherwise, the signature " .. |
| 40 | "file should be already available locally in the same directory.\n".. | 52 | "file should be already available locally in the same directory.\n" .. |
| 41 | "You need the signer’s public key in your local keyring for this ".. | 53 | "You need the signer’s public key in your local keyring for this " .. |
| 42 | "option to work properly.") | 54 | "option to work properly.") |
| 43 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | 55 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository " .. |
| 44 | "and report if it is available for another Lua version.") | 56 | "and report if it is available for another Lua version.") |
| 45 | util.deps_mode_option(cmd) | 57 | util.deps_mode_option(cmd) |
| 46 | cmd:flag("--no-manifest", "Skip creating/updating the manifest") | 58 | cmd:flag("--no-manifest", "Skip creating/updating the manifest") |
| 47 | cmd:flag("--pin", "If the installed rock is a Lua module, create a ".. | 59 | cmd:flag("--pin", "If the installed rock is a Lua module, create a " .. |
| 48 | "luarocks.lock file listing the exact versions of each dependency found for ".. | 60 | "luarocks.lock file listing the exact versions of each dependency found for " .. |
| 49 | "this rock (recursively), and store it in the rock's directory. ".. | 61 | "this rock (recursively), and store it in the rock's directory. " .. |
| 50 | "Ignores any existing luarocks.lock file in the rock's sources.") | 62 | "Ignores any existing luarocks.lock file in the rock's sources.") |
| 51 | -- luarocks build options | 63 | |
| 52 | parser:flag("--pack-binary-rock"):hidden(true) | 64 | parser:flag("--pack-binary-rock"):hidden(true) |
| 53 | parser:option("--branch"):hidden(true) | 65 | parser:option("--branch"):hidden(true) |
| 54 | parser:flag("--sign"):hidden(true) | 66 | parser:flag("--sign"):hidden(true) |
| 55 | end | 67 | end |
| 56 | 68 | ||
| 57 | 69 | ||
| 58 | --- Install a binary rock. | 70 | |
| 59 | -- @param rock_file string: local or remote filename of a rock. | 71 | |
| 60 | -- @param opts table: installation options | 72 | |
| 61 | -- @return (string, string) or (nil, string, [string]): Name and version of | 73 | |
| 62 | -- installed rock if succeeded or nil and an error message followed by an error code. | 74 | |
| 63 | function install.install_binary_rock(rock_file, opts) | 75 | function install.install_binary_rock(rock_file, opts) |
| 64 | assert(type(rock_file) == "string") | 76 | assert(type(rock_file) == "string") |
| 65 | 77 | ||
| @@ -68,11 +80,11 @@ function install.install_binary_rock(rock_file, opts) | |||
| 68 | 80 | ||
| 69 | local name, version, arch = path.parse_name(rock_file) | 81 | local name, version, arch = path.parse_name(rock_file) |
| 70 | if not name then | 82 | if not name then |
| 71 | return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." | 83 | return nil, "Filename " .. rock_file .. " does not match format 'name-version-revision.arch.rock'." |
| 72 | end | 84 | end |
| 73 | 85 | ||
| 74 | if arch ~= "all" and arch ~= cfg.arch then | 86 | if arch ~= "all" and arch ~= cfg.arch then |
| 75 | return nil, "Incompatible architecture "..arch, "arch" | 87 | return nil, "Incompatible architecture " .. arch, "arch" |
| 76 | end | 88 | end |
| 77 | if repos.is_installed(name, version) then | 89 | if repos.is_installed(name, version) then |
| 78 | if not (opts.force or opts.force_fast) then | 90 | if not (opts.force or opts.force_fast) then |
| @@ -89,13 +101,13 @@ function install.install_binary_rock(rock_file, opts) | |||
| 89 | fs.delete(install_dir) | 101 | fs.delete(install_dir) |
| 90 | fs.remove_dir_if_empty(path.versions_dir(name)) | 102 | fs.remove_dir_if_empty(path.versions_dir(name)) |
| 91 | end) | 103 | end) |
| 92 | 104 | local ok | |
| 93 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) | 105 | local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) |
| 94 | if not ok then return nil, err, errcode end | 106 | if not oks then return nil, err, errcode end |
| 95 | 107 | ||
| 96 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) | 108 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) |
| 97 | if err then | 109 | if err then |
| 98 | return nil, "Failed loading rockspec for installed package: "..err, errcode | 110 | return nil, "Failed loading rockspec for installed package: " .. err, errcode |
| 99 | end | 111 | end |
| 100 | 112 | ||
| 101 | if opts.deps_mode ~= "none" then | 113 | if opts.deps_mode ~= "none" then |
| @@ -104,9 +116,9 @@ function install.install_binary_rock(rock_file, opts) | |||
| 104 | end | 116 | end |
| 105 | 117 | ||
| 106 | if deps_mode ~= "none" then | 118 | if deps_mode ~= "none" then |
| 107 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) | 119 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) and |
| 108 | and "." | 120 | "." or |
| 109 | or install_dir | 121 | install_dir |
| 110 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", deps_mode, opts.verify, deplock_dir) | 122 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", deps_mode, opts.verify, deplock_dir) |
| 111 | if err then return nil, err, errcode end | 123 | if err then return nil, err, errcode end |
| 112 | end | 124 | end |
| @@ -127,42 +139,43 @@ function install.install_binary_rock(rock_file, opts) | |||
| 127 | return name, version | 139 | return name, version |
| 128 | end | 140 | end |
| 129 | 141 | ||
| 130 | --- Installs the dependencies of a binary rock. | 142 | |
| 131 | -- @param rock_file string: local or remote filename of a rock. | 143 | |
| 132 | -- @param opts table: installation options | 144 | |
| 133 | -- @return (string, string) or (nil, string, [string]): Name and version of | 145 | |
| 134 | -- the rock whose dependencies were installed if succeeded or nil and an error message | 146 | |
| 135 | -- followed by an error code. | 147 | |
| 136 | function install.install_binary_rock_deps(rock_file, opts) | 148 | function install.install_binary_rock_deps(rock_file, opts) |
| 137 | assert(type(rock_file) == "string") | 149 | assert(type(rock_file) == "string") |
| 138 | 150 | ||
| 139 | local name, version, arch = path.parse_name(rock_file) | 151 | local name, version, arch = path.parse_name(rock_file) |
| 140 | if not name then | 152 | if not name then |
| 141 | return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." | 153 | return nil, "Filename " .. rock_file .. " does not match format 'name-version-revision.arch.rock'." |
| 142 | end | 154 | end |
| 143 | 155 | ||
| 144 | if arch ~= "all" and arch ~= cfg.arch then | 156 | if arch ~= "all" and arch ~= cfg.arch then |
| 145 | return nil, "Incompatible architecture "..arch, "arch" | 157 | return nil, "Incompatible architecture " .. arch, "arch" |
| 146 | end | 158 | end |
| 147 | 159 | ||
| 148 | local install_dir = path.install_dir(name, version) | 160 | local install_dir = path.install_dir(name, version) |
| 149 | 161 | ||
| 150 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) | 162 | local ok |
| 151 | if not ok then return nil, err, errcode end | 163 | local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) |
| 164 | if not oks then return nil, err, errcode end | ||
| 152 | 165 | ||
| 153 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) | 166 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) |
| 154 | if err then | 167 | if err then |
| 155 | return nil, "Failed loading rockspec for installed package: "..err, errcode | 168 | return nil, "Failed loading rockspec for installed package: " .. err, errcode |
| 156 | end | 169 | end |
| 157 | 170 | ||
| 158 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) | 171 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) and |
| 159 | and "." | 172 | "." or |
| 160 | or install_dir | 173 | install_dir |
| 161 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode, opts.verify, deplock_dir) | 174 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode, opts.verify, deplock_dir) |
| 162 | if err then return nil, err, errcode end | 175 | if err then return nil, err, errcode end |
| 163 | 176 | ||
| 164 | util.printout() | 177 | util.printout() |
| 165 | util.printout("Successfully installed dependencies for " ..name.." "..version) | 178 | util.printout("Successfully installed dependencies for " .. name .. " " .. version) |
| 166 | 179 | ||
| 167 | return name, version | 180 | return name, version |
| 168 | end | 181 | end |
| @@ -173,11 +186,10 @@ local function install_rock_file_deps(filename, opts) | |||
| 173 | if not name then return nil, version end | 186 | if not name then return nil, version end |
| 174 | 187 | ||
| 175 | deps.check_dependencies(nil, opts.deps_mode) | 188 | deps.check_dependencies(nil, opts.deps_mode) |
| 176 | return name, version | 189 | return true |
| 177 | end | 190 | end |
| 178 | 191 | ||
| 179 | local function install_rock_file(filename, opts) | 192 | local function install_rock_file(filename, opts) |
| 180 | assert(type(filename) == "string") | ||
| 181 | 193 | ||
| 182 | local name, version = install.install_binary_rock(filename, opts) | 194 | local name, version = install.install_binary_rock(filename, opts) |
| 183 | if not name then return nil, version end | 195 | if not name then return nil, version end |
| @@ -196,17 +208,17 @@ local function install_rock_file(filename, opts) | |||
| 196 | end | 208 | end |
| 197 | 209 | ||
| 198 | deps.check_dependencies(nil, opts.deps_mode) | 210 | deps.check_dependencies(nil, opts.deps_mode) |
| 199 | return name, version | 211 | return true |
| 200 | end | 212 | end |
| 201 | 213 | ||
| 202 | --- Driver function for the "install" command. | 214 | |
| 203 | -- If an URL or pathname to a binary rock is given, fetches and installs it. | 215 | |
| 204 | -- If a rockspec or a source rock is given, forwards the request to the "build" | 216 | |
| 205 | -- command. | 217 | |
| 206 | -- If a package name is given, forwards the request to "search" and, | 218 | |
| 207 | -- if returned a result, installs the matching rock. | 219 | |
| 208 | -- @return boolean or (nil, string, exitcode): True if installation was | 220 | |
| 209 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | 221 | |
| 210 | function install.command(args) | 222 | function install.command(args) |
| 211 | if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then | 223 | if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then |
| 212 | local build = require("luarocks.cmd.build") | 224 | local build = require("luarocks.cmd.build") |
| @@ -229,12 +241,12 @@ function install.command(args) | |||
| 229 | end | 241 | end |
| 230 | else | 242 | else |
| 231 | local url, err = search.find_rock_checking_lua_versions( | 243 | local url, err = search.find_rock_checking_lua_versions( |
| 232 | queries.new(args.rock, args.namespace, args.version), | 244 | queries.new(args.rock, args.namespace, args.version), |
| 233 | args.check_lua_versions) | 245 | args.check_lua_versions) |
| 234 | if not url then | 246 | if not url then |
| 235 | return nil, err | 247 | return nil, err |
| 236 | end | 248 | end |
| 237 | util.printout("Installing "..url) | 249 | util.printout("Installing " .. url) |
| 238 | args.rock = url | 250 | args.rock = url |
| 239 | return install.command(args) | 251 | return install.command(args) |
| 240 | end | 252 | end |
| @@ -247,4 +259,6 @@ install.needs_lock = function(args) | |||
| 247 | return true | 259 | return true |
| 248 | end | 260 | end |
| 249 | 261 | ||
| 262 | deps.installer = install.command | ||
| 263 | |||
| 250 | return install | 264 | return install |
diff --git a/src/luarocks/cmd/install.tl b/src/luarocks/cmd/install.tl index 157ef772..ca3d3916 100644 --- a/src/luarocks/cmd/install.tl +++ b/src/luarocks/cmd/install.tl | |||
| @@ -180,16 +180,16 @@ function install.install_binary_rock_deps(rock_file: string, opts: IOpts): strin | |||
| 180 | return name, version | 180 | return name, version |
| 181 | end | 181 | end |
| 182 | 182 | ||
| 183 | local function install_rock_file_deps(filename: string, opts: IOpts): string, string | 183 | local function install_rock_file_deps(filename: string, opts: IOpts): boolean, string |
| 184 | 184 | ||
| 185 | local name, version = install.install_binary_rock_deps(filename, opts) | 185 | local name, version = install.install_binary_rock_deps(filename, opts) |
| 186 | if not name then return nil, version end | 186 | if not name then return nil, version end |
| 187 | 187 | ||
| 188 | deps.check_dependencies(nil, opts.deps_mode) | 188 | deps.check_dependencies(nil, opts.deps_mode) |
| 189 | return name, version | 189 | return true |
| 190 | end | 190 | end |
| 191 | 191 | ||
| 192 | local function install_rock_file(filename: string, opts: IOpts): string, string | 192 | local function install_rock_file(filename: string, opts: IOpts): boolean, string |
| 193 | 193 | ||
| 194 | local name, version = install.install_binary_rock(filename, opts) | 194 | local name, version = install.install_binary_rock(filename, opts) |
| 195 | if not name then return nil, version end | 195 | if not name then return nil, version end |
| @@ -208,7 +208,7 @@ local function install_rock_file(filename: string, opts: IOpts): string, string | |||
| 208 | end | 208 | end |
| 209 | 209 | ||
| 210 | deps.check_dependencies(nil, opts.deps_mode) | 210 | deps.check_dependencies(nil, opts.deps_mode) |
| 211 | return name, version | 211 | return true |
| 212 | end | 212 | end |
| 213 | 213 | ||
| 214 | --- Driver function for the "install" command. | 214 | --- Driver function for the "install" command. |
diff --git a/src/luarocks/cmd/lint-original.lua b/src/luarocks/cmd/lint-original.lua new file mode 100644 index 00000000..421803e1 --- /dev/null +++ b/src/luarocks/cmd/lint-original.lua | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | |||
| 2 | --- Module implementing the LuaRocks "lint" command. | ||
| 3 | -- Utility function that checks syntax of the rockspec. | ||
| 4 | local lint = {} | ||
| 5 | |||
| 6 | local util = require("luarocks.util") | ||
| 7 | local download = require("luarocks.download") | ||
| 8 | local fetch = require("luarocks.fetch") | ||
| 9 | |||
| 10 | function lint.add_to_parser(parser) | ||
| 11 | local cmd = parser:command("lint", "Check syntax of a rockspec.\n\n".. | ||
| 12 | "Returns success if the text of the rockspec is syntactically correct, else failure.", | ||
| 13 | util.see_also()) | ||
| 14 | :summary("Check syntax of a rockspec.") | ||
| 15 | |||
| 16 | cmd:argument("rockspec", "The rockspec to check.") | ||
| 17 | end | ||
| 18 | |||
| 19 | function lint.command(args) | ||
| 20 | |||
| 21 | local filename = args.rockspec | ||
| 22 | if not filename:match(".rockspec$") then | ||
| 23 | local err | ||
| 24 | filename, err = download.download_file("rockspec", filename:lower()) | ||
| 25 | if not filename then | ||
| 26 | return nil, err | ||
| 27 | end | ||
| 28 | end | ||
| 29 | |||
| 30 | local rs, err = fetch.load_local_rockspec(filename) | ||
| 31 | if not rs then | ||
| 32 | return nil, "Failed loading rockspec: "..err | ||
| 33 | end | ||
| 34 | |||
| 35 | local ok = true | ||
| 36 | |||
| 37 | -- This should have been done in the type checker, | ||
| 38 | -- but it would break compatibility of other commands. | ||
| 39 | -- Making 'lint' alone be stricter shouldn't be a problem, | ||
| 40 | -- because extra-strict checks is what lint-type commands | ||
| 41 | -- are all about. | ||
| 42 | if not rs.description or not rs.description.license then | ||
| 43 | util.printerr("Rockspec has no description.license field.") | ||
| 44 | ok = false | ||
| 45 | end | ||
| 46 | |||
| 47 | return ok, ok or filename.." failed consistency checks." | ||
| 48 | end | ||
| 49 | |||
| 50 | return lint | ||
diff --git a/src/luarocks/cmd/lint.lua b/src/luarocks/cmd/lint.lua index 421803e1..cfff66c0 100644 --- a/src/luarocks/cmd/lint.lua +++ b/src/luarocks/cmd/lint.lua | |||
| @@ -1,17 +1,24 @@ | |||
| 1 | 1 | ||
| 2 | --- Module implementing the LuaRocks "lint" command. | 2 | |
| 3 | -- Utility function that checks syntax of the rockspec. | 3 | |
| 4 | local lint = {} | 4 | local lint = {} |
| 5 | 5 | ||
| 6 | |||
| 6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
| 7 | local download = require("luarocks.download") | 8 | local download = require("luarocks.download") |
| 8 | local fetch = require("luarocks.fetch") | 9 | local fetch = require("luarocks.fetch") |
| 9 | 10 | ||
| 11 | local argparse = require("luarocks.vendor.argparse") | ||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | |||
| 10 | function lint.add_to_parser(parser) | 17 | function lint.add_to_parser(parser) |
| 11 | local cmd = parser:command("lint", "Check syntax of a rockspec.\n\n".. | 18 | local cmd = parser:command("lint", "Check syntax of a rockspec.\n\n" .. |
| 12 | "Returns success if the text of the rockspec is syntactically correct, else failure.", | 19 | "Returns success if the text of the rockspec is syntactically correct, else failure.", |
| 13 | util.see_also()) | 20 | util.see_also()): |
| 14 | :summary("Check syntax of a rockspec.") | 21 | summary("Check syntax of a rockspec.") |
| 15 | 22 | ||
| 16 | cmd:argument("rockspec", "The rockspec to check.") | 23 | cmd:argument("rockspec", "The rockspec to check.") |
| 17 | end | 24 | end |
| @@ -29,22 +36,26 @@ function lint.command(args) | |||
| 29 | 36 | ||
| 30 | local rs, err = fetch.load_local_rockspec(filename) | 37 | local rs, err = fetch.load_local_rockspec(filename) |
| 31 | if not rs then | 38 | if not rs then |
| 32 | return nil, "Failed loading rockspec: "..err | 39 | return nil, "Failed loading rockspec: " .. err |
| 33 | end | 40 | end |
| 34 | 41 | ||
| 35 | local ok = true | 42 | local ok = true |
| 36 | 43 | ||
| 37 | -- This should have been done in the type checker, | 44 | |
| 38 | -- but it would break compatibility of other commands. | 45 | |
| 39 | -- Making 'lint' alone be stricter shouldn't be a problem, | 46 | |
| 40 | -- because extra-strict checks is what lint-type commands | 47 | |
| 41 | -- are all about. | 48 | |
| 42 | if not rs.description or not rs.description.license then | 49 | if not rs.description or not rs.description.license then |
| 43 | util.printerr("Rockspec has no description.license field.") | 50 | util.printerr("Rockspec has no description.license field.") |
| 44 | ok = false | 51 | ok = false |
| 45 | end | 52 | end |
| 46 | 53 | ||
| 47 | return ok, ok or filename.." failed consistency checks." | 54 | if ok then |
| 55 | return ok | ||
| 56 | end | ||
| 57 | |||
| 58 | return nil, filename .. " failed consistency checks." | ||
| 48 | end | 59 | end |
| 49 | 60 | ||
| 50 | return lint | 61 | return lint |
diff --git a/src/luarocks/cmd/lint.tl b/src/luarocks/cmd/lint.tl index 41fdf096..f3845bfa 100644 --- a/src/luarocks/cmd/lint.tl +++ b/src/luarocks/cmd/lint.tl | |||
| @@ -51,7 +51,11 @@ function lint.command(args: Args): boolean, string, string | |||
| 51 | ok = false | 51 | ok = false |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | return ok, ok or filename.." failed consistency checks." | 54 | if ok then |
| 55 | return ok | ||
| 56 | end | ||
| 57 | |||
| 58 | return nil, filename.." failed consistency checks." | ||
| 55 | end | 59 | end |
| 56 | 60 | ||
| 57 | return lint | 61 | return lint |
diff --git a/src/luarocks/cmd/make-original.lua b/src/luarocks/cmd/make-original.lua new file mode 100644 index 00000000..811078b8 --- /dev/null +++ b/src/luarocks/cmd/make-original.lua | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | |||
| 2 | --- Module implementing the LuaRocks "make" command. | ||
| 3 | -- Builds sources in the current directory, but unlike "build", | ||
| 4 | -- it does not fetch sources, etc., assuming everything is | ||
| 5 | -- available in the current directory. | ||
| 6 | local make = {} | ||
| 7 | |||
| 8 | local build = require("luarocks.build") | ||
| 9 | local util = require("luarocks.util") | ||
| 10 | local cfg = require("luarocks.core.cfg") | ||
| 11 | local fetch = require("luarocks.fetch") | ||
| 12 | local pack = require("luarocks.pack") | ||
| 13 | local remove = require("luarocks.remove") | ||
| 14 | local deps = require("luarocks.deps") | ||
| 15 | local dir = require("luarocks.dir") | ||
| 16 | local fs = require("luarocks.fs") | ||
| 17 | |||
| 18 | function make.cmd_options(parser) | ||
| 19 | parser:flag("--no-install", "Do not install the rock.") | ||
| 20 | parser:flag("--no-doc", "Install the rock without its documentation.") | ||
| 21 | parser:flag("--pack-binary-rock", "Do not install rock. Instead, produce a ".. | ||
| 22 | ".rock file with the contents of compilation in the current directory.") | ||
| 23 | parser:flag("--keep", "Do not remove previously installed versions of the ".. | ||
| 24 | "rock after building a new one. This behavior can be made permanent by ".. | ||
| 25 | "setting keep_other_versions=true in the configuration file.") | ||
| 26 | parser:flag("--force", "If --keep is not specified, force removal of ".. | ||
| 27 | "previously installed versions if it would break dependencies. ".. | ||
| 28 | "If rock is already installed, reinstall it anyway.") | ||
| 29 | parser:flag("--force-fast", "Like --force, but performs a forced removal ".. | ||
| 30 | "without reporting dependency issues.") | ||
| 31 | parser:flag("--verify", "Verify signature of the rockspec or src.rock being ".. | ||
| 32 | "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. | ||
| 33 | "attempt to download the signature as well. Otherwise, the signature ".. | ||
| 34 | "file should be already available locally in the same directory.\n".. | ||
| 35 | "You need the signer’s public key in your local keyring for this ".. | ||
| 36 | "option to work properly.") | ||
| 37 | parser:flag("--sign", "To be used with --pack-binary-rock. Also produce a ".. | ||
| 38 | "signature file for the generated .rock file.") | ||
| 39 | parser:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | ||
| 40 | "and report if it is available for another Lua version.") | ||
| 41 | parser:flag("--pin", "Pin the exact dependencies used for the rockspec".. | ||
| 42 | "being built into a luarocks.lock file in the current directory.") | ||
| 43 | parser:flag("--no-manifest", "Skip creating/updating the manifest") | ||
| 44 | parser:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") | ||
| 45 | util.deps_mode_option(parser) | ||
| 46 | end | ||
| 47 | |||
| 48 | function make.add_to_parser(parser) | ||
| 49 | -- luacheck: push ignore 431 | ||
| 50 | local cmd = parser:command("make", [[ | ||
| 51 | Builds sources in the current directory, but unlike "build", it does not fetch | ||
| 52 | sources, etc., assuming everything is available in the current directory. If no | ||
| 53 | argument is given, it looks for a rockspec in the current directory and in | ||
| 54 | "rockspec/" and "rockspecs/" subdirectories, picking the rockspec with newest | ||
| 55 | version or without version name. If rockspecs for different rocks are found or | ||
| 56 | there are several rockspecs without version, you must specify which to use, | ||
| 57 | through the command-line. | ||
| 58 | |||
| 59 | This command is useful as a tool for debugging rockspecs. | ||
| 60 | To install rocks, you'll normally want to use the "install" and "build" | ||
| 61 | commands. See the help on those for details. | ||
| 62 | |||
| 63 | If the current directory contains a luarocks.lock file, it is used as the | ||
| 64 | authoritative source for exact version of dependencies. The --pin flag | ||
| 65 | overrides and recreates this file scanning dependency based on ranges. | ||
| 66 | ]], util.see_also()) | ||
| 67 | :summary("Compile package in current directory using a rockspec.") | ||
| 68 | -- luacheck: pop | ||
| 69 | |||
| 70 | cmd:argument("rockspec", "Rockspec for the rock to build.") | ||
| 71 | :args("?") | ||
| 72 | |||
| 73 | make.cmd_options(cmd) | ||
| 74 | end | ||
| 75 | |||
| 76 | --- Driver function for "make" command. | ||
| 77 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | ||
| 78 | -- error message otherwise. exitcode is optionally returned. | ||
| 79 | function make.command(args) | ||
| 80 | local rockspec_filename = args.rockspec | ||
| 81 | if not rockspec_filename then | ||
| 82 | local err | ||
| 83 | rockspec_filename, err = util.get_default_rockspec() | ||
| 84 | if not rockspec_filename then | ||
| 85 | return nil, err | ||
| 86 | end | ||
| 87 | end | ||
| 88 | if not rockspec_filename:match("rockspec$") then | ||
| 89 | return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") | ||
| 90 | end | ||
| 91 | |||
| 92 | local cwd = fs.absolute_name(dir.path(".")) | ||
| 93 | local rockspec, err, errcode = fetch.load_rockspec(rockspec_filename) | ||
| 94 | if not rockspec then | ||
| 95 | return nil, err | ||
| 96 | end | ||
| 97 | |||
| 98 | local name, namespace = util.split_namespace(rockspec.name) | ||
| 99 | namespace = namespace or args.namespace | ||
| 100 | |||
| 101 | local opts = { | ||
| 102 | need_to_fetch = false, | ||
| 103 | minimal_mode = true, | ||
| 104 | deps_mode = deps.get_deps_mode(args), | ||
| 105 | build_only_deps = not not (args.only_deps and not args.pack_binary_rock), | ||
| 106 | namespace = namespace, | ||
| 107 | branch = args.branch, | ||
| 108 | verify = not not args.verify, | ||
| 109 | check_lua_versions = not not args.check_lua_versions, | ||
| 110 | pin = not not args.pin, | ||
| 111 | rebuild = true, | ||
| 112 | no_install = not not args.no_install | ||
| 113 | } | ||
| 114 | |||
| 115 | if args.sign and not args.pack_binary_rock then | ||
| 116 | return nil, "In the make command, --sign is meant to be used only with --pack-binary-rock" | ||
| 117 | end | ||
| 118 | |||
| 119 | if args.no_install then | ||
| 120 | return build.build_rockspec(rockspec, opts, cwd) | ||
| 121 | elseif args.pack_binary_rock then | ||
| 122 | return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function() | ||
| 123 | local name, version = build.build_rockspec(rockspec, opts, cwd) -- luacheck: ignore 431 | ||
| 124 | if name and args.no_doc then | ||
| 125 | util.remove_doc_dir(name, version) | ||
| 126 | end | ||
| 127 | return name, version | ||
| 128 | end) | ||
| 129 | else | ||
| 130 | local ok, err = build.build_rockspec(rockspec, opts, cwd) | ||
| 131 | if not ok then return nil, err end | ||
| 132 | local name, version = ok, err -- luacheck: ignore 421 | ||
| 133 | |||
| 134 | if opts.build_only_deps then | ||
| 135 | util.printout("Stopping after installing dependencies for " ..name.." "..version) | ||
| 136 | util.printout() | ||
| 137 | return name, version | ||
| 138 | end | ||
| 139 | |||
| 140 | if args.no_doc then | ||
| 141 | util.remove_doc_dir(name, version) | ||
| 142 | end | ||
| 143 | |||
| 144 | if (not args.keep) and not cfg.keep_other_versions then | ||
| 145 | local ok, err, warn = remove.remove_other_versions(name, version, args.force, args.force_fast) | ||
| 146 | if not ok then | ||
| 147 | return nil, err | ||
| 148 | elseif warn then | ||
| 149 | util.printerr(warn) | ||
| 150 | end | ||
| 151 | end | ||
| 152 | |||
| 153 | deps.check_dependencies(nil, deps.get_deps_mode(args)) | ||
| 154 | return name, version | ||
| 155 | end | ||
| 156 | end | ||
| 157 | |||
| 158 | make.needs_lock = function(args) | ||
| 159 | if args.pack_binary_rock or args.no_install then | ||
| 160 | return false | ||
| 161 | end | ||
| 162 | return true | ||
| 163 | end | ||
| 164 | |||
| 165 | return make | ||
diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index 811078b8..f373c94e 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua | |||
| @@ -1,10 +1,12 @@ | |||
| 1 | 1 | ||
| 2 | --- Module implementing the LuaRocks "make" command. | 2 | |
| 3 | -- Builds sources in the current directory, but unlike "build", | 3 | |
| 4 | -- it does not fetch sources, etc., assuming everything is | 4 | |
| 5 | -- available in the current directory. | 5 | |
| 6 | local make = {} | 6 | local make = {} |
| 7 | 7 | ||
| 8 | |||
| 9 | |||
| 8 | local build = require("luarocks.build") | 10 | local build = require("luarocks.build") |
| 9 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
| 10 | local cfg = require("luarocks.core.cfg") | 12 | local cfg = require("luarocks.core.cfg") |
| @@ -15,38 +17,47 @@ local deps = require("luarocks.deps") | |||
| 15 | local dir = require("luarocks.dir") | 17 | local dir = require("luarocks.dir") |
| 16 | local fs = require("luarocks.fs") | 18 | local fs = require("luarocks.fs") |
| 17 | 19 | ||
| 20 | local argparse = require("luarocks.vendor.argparse") | ||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | |||
| 18 | function make.cmd_options(parser) | 29 | function make.cmd_options(parser) |
| 19 | parser:flag("--no-install", "Do not install the rock.") | 30 | parser:flag("--no-install", "Do not install the rock.") |
| 20 | parser:flag("--no-doc", "Install the rock without its documentation.") | 31 | parser:flag("--no-doc", "Install the rock without its documentation.") |
| 21 | parser:flag("--pack-binary-rock", "Do not install rock. Instead, produce a ".. | 32 | parser:flag("--pack-binary-rock", "Do not install rock. Instead, produce a " .. |
| 22 | ".rock file with the contents of compilation in the current directory.") | 33 | ".rock file with the contents of compilation in the current directory.") |
| 23 | parser:flag("--keep", "Do not remove previously installed versions of the ".. | 34 | parser:flag("--keep", "Do not remove previously installed versions of the " .. |
| 24 | "rock after building a new one. This behavior can be made permanent by ".. | 35 | "rock after building a new one. This behavior can be made permanent by " .. |
| 25 | "setting keep_other_versions=true in the configuration file.") | 36 | "setting keep_other_versions=true in the configuration file.") |
| 26 | parser:flag("--force", "If --keep is not specified, force removal of ".. | 37 | parser:flag("--force", "If --keep is not specified, force removal of " .. |
| 27 | "previously installed versions if it would break dependencies. ".. | 38 | "previously installed versions if it would break dependencies. " .. |
| 28 | "If rock is already installed, reinstall it anyway.") | 39 | "If rock is already installed, reinstall it anyway.") |
| 29 | parser:flag("--force-fast", "Like --force, but performs a forced removal ".. | 40 | parser:flag("--force-fast", "Like --force, but performs a forced removal " .. |
| 30 | "without reporting dependency issues.") | 41 | "without reporting dependency issues.") |
| 31 | parser:flag("--verify", "Verify signature of the rockspec or src.rock being ".. | 42 | parser:flag("--verify", "Verify signature of the rockspec or src.rock being " .. |
| 32 | "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. | 43 | "built. If the rockspec or src.rock is being downloaded, LuaRocks will " .. |
| 33 | "attempt to download the signature as well. Otherwise, the signature ".. | 44 | "attempt to download the signature as well. Otherwise, the signature " .. |
| 34 | "file should be already available locally in the same directory.\n".. | 45 | "file should be already available locally in the same directory.\n" .. |
| 35 | "You need the signer’s public key in your local keyring for this ".. | 46 | "You need the signer's public key in your local keyring for this " .. |
| 36 | "option to work properly.") | 47 | "option to work properly.") |
| 37 | parser:flag("--sign", "To be used with --pack-binary-rock. Also produce a ".. | 48 | parser:flag("--sign", "To be used with --pack-binary-rock. Also produce a " .. |
| 38 | "signature file for the generated .rock file.") | 49 | "signature file for the generated .rock file.") |
| 39 | parser:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | 50 | parser:flag("--check-lua-versions", "If the rock can't be found, check repository " .. |
| 40 | "and report if it is available for another Lua version.") | 51 | "and report if it is available for another Lua version.") |
| 41 | parser:flag("--pin", "Pin the exact dependencies used for the rockspec".. | 52 | parser:flag("--pin", "Pin the exact dependencies used for the rockspec" .. |
| 42 | "being built into a luarocks.lock file in the current directory.") | 53 | "being built into a luarocks.lock file in the current directory.") |
| 43 | parser:flag("--no-manifest", "Skip creating/updating the manifest") | 54 | parser:flag("--no-manifest", "Skip creating/updating the manifest") |
| 44 | parser:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") | 55 | parser:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") |
| 45 | util.deps_mode_option(parser) | 56 | util.deps_mode_option(parser) |
| 46 | end | 57 | end |
| 47 | 58 | ||
| 48 | function make.add_to_parser(parser) | 59 | function make.add_to_parser(parser) |
| 49 | -- luacheck: push ignore 431 | 60 | |
| 50 | local cmd = parser:command("make", [[ | 61 | local cmd = parser:command("make", [[ |
| 51 | Builds sources in the current directory, but unlike "build", it does not fetch | 62 | Builds sources in the current directory, but unlike "build", it does not fetch |
| 52 | sources, etc., assuming everything is available in the current directory. If no | 63 | sources, etc., assuming everything is available in the current directory. If no |
| @@ -63,20 +74,21 @@ commands. See the help on those for details. | |||
| 63 | If the current directory contains a luarocks.lock file, it is used as the | 74 | If the current directory contains a luarocks.lock file, it is used as the |
| 64 | authoritative source for exact version of dependencies. The --pin flag | 75 | authoritative source for exact version of dependencies. The --pin flag |
| 65 | overrides and recreates this file scanning dependency based on ranges. | 76 | overrides and recreates this file scanning dependency based on ranges. |
| 66 | ]], util.see_also()) | 77 | ]], util.see_also()): |
| 67 | :summary("Compile package in current directory using a rockspec.") | 78 | summary("Compile package in current directory using a rockspec.") |
| 68 | -- luacheck: pop | 79 | |
| 69 | 80 | ||
| 70 | cmd:argument("rockspec", "Rockspec for the rock to build.") | 81 | cmd:argument("rockspec", "Rockspec for the rock to build."): |
| 71 | :args("?") | 82 | args("?") |
| 72 | 83 | ||
| 73 | make.cmd_options(cmd) | 84 | make.cmd_options(cmd) |
| 74 | end | 85 | end |
| 75 | 86 | ||
| 76 | --- Driver function for "make" command. | 87 | |
| 77 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | 88 | |
| 78 | -- error message otherwise. exitcode is optionally returned. | 89 | |
| 79 | function make.command(args) | 90 | function make.command(args) |
| 91 | local name, namespace, version | ||
| 80 | local rockspec_filename = args.rockspec | 92 | local rockspec_filename = args.rockspec |
| 81 | if not rockspec_filename then | 93 | if not rockspec_filename then |
| 82 | local err | 94 | local err |
| @@ -86,7 +98,7 @@ function make.command(args) | |||
| 86 | end | 98 | end |
| 87 | end | 99 | end |
| 88 | if not rockspec_filename:match("rockspec$") then | 100 | if not rockspec_filename:match("rockspec$") then |
| 89 | return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") | 101 | return nil, "Invalid argument: 'make' takes a rockspec as a parameter. " .. util.see_help("make") |
| 90 | end | 102 | end |
| 91 | 103 | ||
| 92 | local cwd = fs.absolute_name(dir.path(".")) | 104 | local cwd = fs.absolute_name(dir.path(".")) |
| @@ -95,7 +107,7 @@ function make.command(args) | |||
| 95 | return nil, err | 107 | return nil, err |
| 96 | end | 108 | end |
| 97 | 109 | ||
| 98 | local name, namespace = util.split_namespace(rockspec.name) | 110 | name, namespace = util.split_namespace(rockspec.name) |
| 99 | namespace = namespace or args.namespace | 111 | namespace = namespace or args.namespace |
| 100 | 112 | ||
| 101 | local opts = { | 113 | local opts = { |
| @@ -109,7 +121,7 @@ function make.command(args) | |||
| 109 | check_lua_versions = not not args.check_lua_versions, | 121 | check_lua_versions = not not args.check_lua_versions, |
| 110 | pin = not not args.pin, | 122 | pin = not not args.pin, |
| 111 | rebuild = true, | 123 | rebuild = true, |
| 112 | no_install = not not args.no_install | 124 | no_install = not not args.no_install, |
| 113 | } | 125 | } |
| 114 | 126 | ||
| 115 | if args.sign and not args.pack_binary_rock then | 127 | if args.sign and not args.pack_binary_rock then |
| @@ -117,10 +129,15 @@ function make.command(args) | |||
| 117 | end | 129 | end |
| 118 | 130 | ||
| 119 | if args.no_install then | 131 | if args.no_install then |
| 120 | return build.build_rockspec(rockspec, opts, cwd) | 132 | name, version = build.build_rockspec(rockspec, opts, cwd) |
| 133 | if name then | ||
| 134 | return true | ||
| 135 | else | ||
| 136 | return nil, version | ||
| 137 | end | ||
| 121 | elseif args.pack_binary_rock then | 138 | elseif args.pack_binary_rock then |
| 122 | return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function() | 139 | return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function() |
| 123 | local name, version = build.build_rockspec(rockspec, opts, cwd) -- luacheck: ignore 431 | 140 | name, version = build.build_rockspec(rockspec, opts, cwd) |
| 124 | if name and args.no_doc then | 141 | if name and args.no_doc then |
| 125 | util.remove_doc_dir(name, version) | 142 | util.remove_doc_dir(name, version) |
| 126 | end | 143 | end |
| @@ -129,12 +146,12 @@ function make.command(args) | |||
| 129 | else | 146 | else |
| 130 | local ok, err = build.build_rockspec(rockspec, opts, cwd) | 147 | local ok, err = build.build_rockspec(rockspec, opts, cwd) |
| 131 | if not ok then return nil, err end | 148 | if not ok then return nil, err end |
| 132 | local name, version = ok, err -- luacheck: ignore 421 | 149 | name, version = ok, err |
| 133 | 150 | ||
| 134 | if opts.build_only_deps then | 151 | if opts.build_only_deps then |
| 135 | util.printout("Stopping after installing dependencies for " ..name.." "..version) | 152 | util.printout("Stopping after installing dependencies for " .. name .. " " .. version) |
| 136 | util.printout() | 153 | util.printout() |
| 137 | return name, version | 154 | return name ~= nil, version |
| 138 | end | 155 | end |
| 139 | 156 | ||
| 140 | if args.no_doc then | 157 | if args.no_doc then |
| @@ -151,7 +168,7 @@ function make.command(args) | |||
| 151 | end | 168 | end |
| 152 | 169 | ||
| 153 | deps.check_dependencies(nil, deps.get_deps_mode(args)) | 170 | deps.check_dependencies(nil, deps.get_deps_mode(args)) |
| 154 | return name, version | 171 | return name ~= nil, version |
| 155 | end | 172 | end |
| 156 | end | 173 | end |
| 157 | 174 | ||
diff --git a/src/luarocks/cmd/make.tl b/src/luarocks/cmd/make.tl index 4d29c6d6..17af28ae 100644 --- a/src/luarocks/cmd/make.tl +++ b/src/luarocks/cmd/make.tl | |||
| @@ -88,6 +88,7 @@ end | |||
| 88 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | 88 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an |
| 89 | -- error message otherwise. exitcode is optionally returned. | 89 | -- error message otherwise. exitcode is optionally returned. |
| 90 | function make.command(args: Args): boolean, string | 90 | function make.command(args: Args): boolean, string |
| 91 | local name, namespace, version: string, string, string | ||
| 91 | local rockspec_filename = args.rockspec | 92 | local rockspec_filename = args.rockspec |
| 92 | if not rockspec_filename then | 93 | if not rockspec_filename then |
| 93 | local err: string | 94 | local err: string |
| @@ -106,7 +107,7 @@ function make.command(args: Args): boolean, string | |||
| 106 | return nil, err | 107 | return nil, err |
| 107 | end | 108 | end |
| 108 | 109 | ||
| 109 | local name, namespace = util.split_namespace(rockspec.name) | 110 | name, namespace = util.split_namespace(rockspec.name) |
| 110 | namespace = namespace or args.namespace | 111 | namespace = namespace or args.namespace |
| 111 | 112 | ||
| 112 | local opts: BOpts = { | 113 | local opts: BOpts = { |
| @@ -128,10 +129,15 @@ function make.command(args: Args): boolean, string | |||
| 128 | end | 129 | end |
| 129 | 130 | ||
| 130 | if args.no_install then | 131 | if args.no_install then |
| 131 | return build.build_rockspec(rockspec, opts, cwd) | 132 | name, version = build.build_rockspec(rockspec, opts, cwd) |
| 133 | if name then | ||
| 134 | return true | ||
| 135 | else | ||
| 136 | return nil, version | ||
| 137 | end | ||
| 132 | elseif args.pack_binary_rock then | 138 | elseif args.pack_binary_rock then |
| 133 | return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function(): string, string | 139 | return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function(): string, string |
| 134 | local name, version = build.build_rockspec(rockspec, opts, cwd) -- luacheck: ignore 431 | 140 | name, version = build.build_rockspec(rockspec, opts, cwd) -- luacheck: ignore 431 |
| 135 | if name and args.no_doc then | 141 | if name and args.no_doc then |
| 136 | util.remove_doc_dir(name, version) | 142 | util.remove_doc_dir(name, version) |
| 137 | end | 143 | end |
| @@ -140,12 +146,12 @@ function make.command(args: Args): boolean, string | |||
| 140 | else | 146 | else |
| 141 | local ok, err = build.build_rockspec(rockspec, opts, cwd) | 147 | local ok, err = build.build_rockspec(rockspec, opts, cwd) |
| 142 | if not ok then return nil, err end | 148 | if not ok then return nil, err end |
| 143 | local name, version = ok, err -- luacheck: ignore 421 | 149 | name, version = ok, err -- luacheck: ignore 421 |
| 144 | 150 | ||
| 145 | if opts.build_only_deps then | 151 | if opts.build_only_deps then |
| 146 | util.printout("Stopping after installing dependencies for " ..name.." "..version) | 152 | util.printout("Stopping after installing dependencies for " ..name.." "..version) |
| 147 | util.printout() | 153 | util.printout() |
| 148 | return name, version | 154 | return name ~= nil, version |
| 149 | end | 155 | end |
| 150 | 156 | ||
| 151 | if args.no_doc then | 157 | if args.no_doc then |
| @@ -162,7 +168,7 @@ function make.command(args: Args): boolean, string | |||
| 162 | end | 168 | end |
| 163 | 169 | ||
| 164 | deps.check_dependencies(nil, deps.get_deps_mode(args)) | 170 | deps.check_dependencies(nil, deps.get_deps_mode(args)) |
| 165 | return name, version | 171 | return name ~= nil, version |
| 166 | end | 172 | end |
| 167 | end | 173 | end |
| 168 | 174 | ||
diff --git a/src/luarocks/cmd/new_version-original.lua b/src/luarocks/cmd/new_version-original.lua new file mode 100644 index 00000000..2ec084e0 --- /dev/null +++ b/src/luarocks/cmd/new_version-original.lua | |||
| @@ -0,0 +1,228 @@ | |||
| 1 | |||
| 2 | --- Module implementing the LuaRocks "new_version" command. | ||
| 3 | -- Utility function that writes a new rockspec, updating data from a previous one. | ||
| 4 | local new_version = {} | ||
| 5 | |||
| 6 | local util = require("luarocks.util") | ||
| 7 | local download = require("luarocks.download") | ||
| 8 | local fetch = require("luarocks.fetch") | ||
| 9 | local persist = require("luarocks.persist") | ||
| 10 | local fs = require("luarocks.fs") | ||
| 11 | local dir = require("luarocks.dir") | ||
| 12 | local type_rockspec = require("luarocks.type.rockspec") | ||
| 13 | |||
| 14 | function new_version.add_to_parser(parser) | ||
| 15 | local cmd = parser:command("new_version", [[ | ||
| 16 | This is a utility function that writes a new rockspec, updating data from a | ||
| 17 | previous one. | ||
| 18 | |||
| 19 | If a package name is given, it downloads the latest rockspec from the default | ||
| 20 | server. If a rockspec is given, it uses it instead. If no argument is given, it | ||
| 21 | looks for a rockspec same way 'luarocks make' does. | ||
| 22 | |||
| 23 | If the version number is not given and tag is passed using --tag, it is used as | ||
| 24 | the version, with 'v' removed from beginning. Otherwise, it only increments the | ||
| 25 | revision number of the given (or downloaded) rockspec. | ||
| 26 | |||
| 27 | If a URL is given, it replaces the one from the old rockspec with the given URL. | ||
| 28 | If a URL is not given and a new version is given, it tries to guess the new URL | ||
| 29 | by replacing occurrences of the version number in the URL or tag; if the guessed | ||
| 30 | URL is invalid, the old URL is restored. It also tries to download the new URL | ||
| 31 | to determine the new MD5 checksum. | ||
| 32 | |||
| 33 | If a tag is given, it replaces the one from the old rockspec. If there is an old | ||
| 34 | tag but no new one passed, it is guessed in the same way URL is. | ||
| 35 | |||
| 36 | If a directory is not given, it defaults to the current directory. | ||
| 37 | |||
| 38 | WARNING: it writes the new rockspec to the given directory, overwriting the file | ||
| 39 | if it already exists.]], util.see_also()) | ||
| 40 | :summary("Auto-write a rockspec for a new version of a rock.") | ||
| 41 | |||
| 42 | cmd:argument("rock", "Package name or rockspec.") | ||
| 43 | :args("?") | ||
| 44 | cmd:argument("new_version", "New version of the rock.") | ||
| 45 | :args("?") | ||
| 46 | cmd:argument("new_url", "New URL of the rock.") | ||
| 47 | :args("?") | ||
| 48 | |||
| 49 | cmd:option("--dir", "Output directory for the new rockspec.") | ||
| 50 | cmd:option("--tag", "New SCM tag.") | ||
| 51 | end | ||
| 52 | |||
| 53 | |||
| 54 | local function try_replace(tbl, field, old, new) | ||
| 55 | if not tbl[field] then | ||
| 56 | return false | ||
| 57 | end | ||
| 58 | local old_field = tbl[field] | ||
| 59 | local new_field = tbl[field]:gsub(old, new) | ||
| 60 | if new_field ~= old_field then | ||
| 61 | util.printout("Guessing new '"..field.."' field as "..new_field) | ||
| 62 | tbl[field] = new_field | ||
| 63 | return true | ||
| 64 | end | ||
| 65 | return false | ||
| 66 | end | ||
| 67 | |||
| 68 | -- Try to download source file using URL from a rockspec. | ||
| 69 | -- If it specified MD5, update it. | ||
| 70 | -- @return (true, false) if MD5 was not specified or it stayed same, | ||
| 71 | -- (true, true) if MD5 changed, (nil, string) on error. | ||
| 72 | local function check_url_and_update_md5(out_rs, invalid_is_error) | ||
| 73 | local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package) | ||
| 74 | if not file then | ||
| 75 | if invalid_is_error then | ||
| 76 | return nil, "invalid URL - "..temp_dir | ||
| 77 | end | ||
| 78 | util.warning("invalid URL - "..temp_dir) | ||
| 79 | return true, false | ||
| 80 | end | ||
| 81 | do | ||
| 82 | local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) | ||
| 83 | if not inferred_dir then | ||
| 84 | return nil, found_dir | ||
| 85 | end | ||
| 86 | |||
| 87 | if found_dir and found_dir ~= inferred_dir then | ||
| 88 | out_rs.source.dir = found_dir | ||
| 89 | end | ||
| 90 | end | ||
| 91 | if file then | ||
| 92 | if out_rs.source.md5 then | ||
| 93 | util.printout("File successfully downloaded. Updating MD5 checksum...") | ||
| 94 | local new_md5, err = fs.get_md5(file) | ||
| 95 | if not new_md5 then | ||
| 96 | return nil, err | ||
| 97 | end | ||
| 98 | local old_md5 = out_rs.source.md5 | ||
| 99 | out_rs.source.md5 = new_md5 | ||
| 100 | return true, new_md5 ~= old_md5 | ||
| 101 | else | ||
| 102 | util.printout("File successfully downloaded.") | ||
| 103 | return true, false | ||
| 104 | end | ||
| 105 | end | ||
| 106 | end | ||
| 107 | |||
| 108 | local function update_source_section(out_rs, url, tag, old_ver, new_ver) | ||
| 109 | if tag then | ||
| 110 | out_rs.source.tag = tag | ||
| 111 | end | ||
| 112 | if url then | ||
| 113 | out_rs.source.url = url | ||
| 114 | return check_url_and_update_md5(out_rs) | ||
| 115 | end | ||
| 116 | if new_ver == old_ver then | ||
| 117 | return true | ||
| 118 | end | ||
| 119 | if out_rs.source.dir then | ||
| 120 | try_replace(out_rs.source, "dir", old_ver, new_ver) | ||
| 121 | end | ||
| 122 | if out_rs.source.file then | ||
| 123 | try_replace(out_rs.source, "file", old_ver, new_ver) | ||
| 124 | end | ||
| 125 | |||
| 126 | local old_url = out_rs.source.url | ||
| 127 | if try_replace(out_rs.source, "url", old_ver, new_ver) then | ||
| 128 | local ok, md5_changed = check_url_and_update_md5(out_rs, true) | ||
| 129 | if ok then | ||
| 130 | return ok, md5_changed | ||
| 131 | end | ||
| 132 | out_rs.source.url = old_url | ||
| 133 | end | ||
| 134 | if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then | ||
| 135 | return true | ||
| 136 | end | ||
| 137 | -- Couldn't replace anything significant, use the old URL. | ||
| 138 | local ok, md5_changed = check_url_and_update_md5(out_rs) | ||
| 139 | if not ok then | ||
| 140 | return nil, md5_changed | ||
| 141 | end | ||
| 142 | if md5_changed then | ||
| 143 | util.warning("URL is the same, but MD5 has changed. Old rockspec is broken.") | ||
| 144 | end | ||
| 145 | return true | ||
| 146 | end | ||
| 147 | |||
| 148 | function new_version.command(args) | ||
| 149 | if not args.rock then | ||
| 150 | local err | ||
| 151 | args.rock, err = util.get_default_rockspec() | ||
| 152 | if not args.rock then | ||
| 153 | return nil, err | ||
| 154 | end | ||
| 155 | end | ||
| 156 | |||
| 157 | local filename, err | ||
| 158 | if args.rock:match("rockspec$") then | ||
| 159 | filename, err = fetch.fetch_url(args.rock) | ||
| 160 | if not filename then | ||
| 161 | return nil, err | ||
| 162 | end | ||
| 163 | else | ||
| 164 | filename, err = download.download_file("rockspec", args.rock:lower()) | ||
| 165 | if not filename then | ||
| 166 | return nil, err | ||
| 167 | end | ||
| 168 | end | ||
| 169 | |||
| 170 | local valid_rs, err = fetch.load_rockspec(filename) | ||
| 171 | if not valid_rs then | ||
| 172 | return nil, err | ||
| 173 | end | ||
| 174 | |||
| 175 | local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") | ||
| 176 | local new_ver, new_rev | ||
| 177 | |||
| 178 | if args.tag and not args.new_version then | ||
| 179 | args.new_version = args.tag:gsub("^v", "") | ||
| 180 | end | ||
| 181 | |||
| 182 | local out_dir | ||
| 183 | if args.dir then | ||
| 184 | out_dir = dir.normalize(args.dir) | ||
| 185 | end | ||
| 186 | |||
| 187 | if args.new_version then | ||
| 188 | new_ver, new_rev = args.new_version:match("(.*)%-(%d+)$") | ||
| 189 | new_rev = tonumber(new_rev) | ||
| 190 | if not new_rev then | ||
| 191 | new_ver = args.new_version | ||
| 192 | new_rev = 1 | ||
| 193 | end | ||
| 194 | else | ||
| 195 | new_ver = old_ver | ||
| 196 | new_rev = tonumber(old_rev) + 1 | ||
| 197 | end | ||
| 198 | local new_rockver = new_ver:gsub("-", "") | ||
| 199 | |||
| 200 | local out_rs, err = persist.load_into_table(filename) | ||
| 201 | local out_name = out_rs.package:lower() | ||
| 202 | out_rs.version = new_rockver.."-"..new_rev | ||
| 203 | |||
| 204 | local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) | ||
| 205 | if not ok then return nil, err end | ||
| 206 | |||
| 207 | if out_rs.build and out_rs.build.type == "module" then | ||
| 208 | out_rs.build.type = "builtin" | ||
| 209 | end | ||
| 210 | |||
| 211 | local out_filename = out_name.."-"..new_rockver.."-"..new_rev..".rockspec" | ||
| 212 | if out_dir then | ||
| 213 | out_filename = dir.path(out_dir, out_filename) | ||
| 214 | fs.make_dir(out_dir) | ||
| 215 | end | ||
| 216 | persist.save_from_table(out_filename, out_rs, type_rockspec.order) | ||
| 217 | |||
| 218 | util.printout("Wrote "..out_filename) | ||
| 219 | |||
| 220 | local valid_out_rs, err = fetch.load_local_rockspec(out_filename) | ||
| 221 | if not valid_out_rs then | ||
| 222 | return nil, "Failed loading generated rockspec: "..err | ||
| 223 | end | ||
| 224 | |||
| 225 | return true | ||
| 226 | end | ||
| 227 | |||
| 228 | return new_version | ||
diff --git a/src/luarocks/cmd/new_version.lua b/src/luarocks/cmd/new_version.lua index 2ec084e0..33b98801 100644 --- a/src/luarocks/cmd/new_version.lua +++ b/src/luarocks/cmd/new_version.lua | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local string = _tl_compat and _tl_compat.string or string | ||
| 2 | |||
| 1 | 3 | ||
| 2 | --- Module implementing the LuaRocks "new_version" command. | ||
| 3 | -- Utility function that writes a new rockspec, updating data from a previous one. | ||
| 4 | local new_version = {} | 4 | local new_version = {} |
| 5 | 5 | ||
| 6 | |||
| 6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
| 7 | local download = require("luarocks.download") | 8 | local download = require("luarocks.download") |
| 8 | local fetch = require("luarocks.fetch") | 9 | local fetch = require("luarocks.fetch") |
| @@ -11,6 +12,18 @@ local fs = require("luarocks.fs") | |||
| 11 | local dir = require("luarocks.dir") | 12 | local dir = require("luarocks.dir") |
| 12 | local type_rockspec = require("luarocks.type.rockspec") | 13 | local type_rockspec = require("luarocks.type.rockspec") |
| 13 | 14 | ||
| 15 | local argparse = require("luarocks.vendor.argparse") | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 14 | function new_version.add_to_parser(parser) | 27 | function new_version.add_to_parser(parser) |
| 15 | local cmd = parser:command("new_version", [[ | 28 | local cmd = parser:command("new_version", [[ |
| 16 | This is a utility function that writes a new rockspec, updating data from a | 29 | This is a utility function that writes a new rockspec, updating data from a |
| @@ -36,15 +49,15 @@ tag but no new one passed, it is guessed in the same way URL is. | |||
| 36 | If a directory is not given, it defaults to the current directory. | 49 | If a directory is not given, it defaults to the current directory. |
| 37 | 50 | ||
| 38 | WARNING: it writes the new rockspec to the given directory, overwriting the file | 51 | WARNING: it writes the new rockspec to the given directory, overwriting the file |
| 39 | if it already exists.]], util.see_also()) | 52 | if it already exists.]], util.see_also()): |
| 40 | :summary("Auto-write a rockspec for a new version of a rock.") | 53 | summary("Auto-write a rockspec for a new version of a rock.") |
| 41 | 54 | ||
| 42 | cmd:argument("rock", "Package name or rockspec.") | 55 | cmd:argument("rock", "Package name or rockspec."): |
| 43 | :args("?") | 56 | args("?") |
| 44 | cmd:argument("new_version", "New version of the rock.") | 57 | cmd:argument("new_version", "New version of the rock."): |
| 45 | :args("?") | 58 | args("?") |
| 46 | cmd:argument("new_url", "New URL of the rock.") | 59 | cmd:argument("new_url", "New URL of the rock."): |
| 47 | :args("?") | 60 | args("?") |
| 48 | 61 | ||
| 49 | cmd:option("--dir", "Output directory for the new rockspec.") | 62 | cmd:option("--dir", "Output directory for the new rockspec.") |
| 50 | cmd:option("--tag", "New SCM tag.") | 63 | cmd:option("--tag", "New SCM tag.") |
| @@ -58,24 +71,24 @@ local function try_replace(tbl, field, old, new) | |||
| 58 | local old_field = tbl[field] | 71 | local old_field = tbl[field] |
| 59 | local new_field = tbl[field]:gsub(old, new) | 72 | local new_field = tbl[field]:gsub(old, new) |
| 60 | if new_field ~= old_field then | 73 | if new_field ~= old_field then |
| 61 | util.printout("Guessing new '"..field.."' field as "..new_field) | 74 | util.printout("Guessing new '" .. field .. "' field as " .. new_field) |
| 62 | tbl[field] = new_field | 75 | tbl[field] = new_field |
| 63 | return true | 76 | return true |
| 64 | end | 77 | end |
| 65 | return false | 78 | return false |
| 66 | end | 79 | end |
| 67 | 80 | ||
| 68 | -- Try to download source file using URL from a rockspec. | 81 | |
| 69 | -- If it specified MD5, update it. | 82 | |
| 70 | -- @return (true, false) if MD5 was not specified or it stayed same, | 83 | |
| 71 | -- (true, true) if MD5 changed, (nil, string) on error. | 84 | |
| 72 | local function check_url_and_update_md5(out_rs, invalid_is_error) | 85 | local function check_url_and_update_md5(out_rs, invalid_is_error) |
| 73 | local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package) | 86 | local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-" .. out_rs.package) |
| 74 | if not file then | 87 | if not file then |
| 75 | if invalid_is_error then | 88 | if invalid_is_error then |
| 76 | return nil, "invalid URL - "..temp_dir | 89 | return nil, "invalid URL - " .. temp_dir |
| 77 | end | 90 | end |
| 78 | util.warning("invalid URL - "..temp_dir) | 91 | util.warning("invalid URL - " .. temp_dir) |
| 79 | return true, false | 92 | return true, false |
| 80 | end | 93 | end |
| 81 | do | 94 | do |
| @@ -134,7 +147,7 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver) | |||
| 134 | if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then | 147 | if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then |
| 135 | return true | 148 | return true |
| 136 | end | 149 | end |
| 137 | -- Couldn't replace anything significant, use the old URL. | 150 | |
| 138 | local ok, md5_changed = check_url_and_update_md5(out_rs) | 151 | local ok, md5_changed = check_url_and_update_md5(out_rs) |
| 139 | if not ok then | 152 | if not ok then |
| 140 | return nil, md5_changed | 153 | return nil, md5_changed |
| @@ -197,9 +210,9 @@ function new_version.command(args) | |||
| 197 | end | 210 | end |
| 198 | local new_rockver = new_ver:gsub("-", "") | 211 | local new_rockver = new_ver:gsub("-", "") |
| 199 | 212 | ||
| 200 | local out_rs, err = persist.load_into_table(filename) | 213 | local out_rs, err = persist.load_into_table(filename), string |
| 201 | local out_name = out_rs.package:lower() | 214 | local out_name = out_rs.package:lower() |
| 202 | out_rs.version = new_rockver.."-"..new_rev | 215 | out_rs.version = new_rockver .. "-" .. tostring(new_rev) |
| 203 | 216 | ||
| 204 | local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) | 217 | local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) |
| 205 | if not ok then return nil, err end | 218 | if not ok then return nil, err end |
| @@ -208,18 +221,18 @@ function new_version.command(args) | |||
| 208 | out_rs.build.type = "builtin" | 221 | out_rs.build.type = "builtin" |
| 209 | end | 222 | end |
| 210 | 223 | ||
| 211 | local out_filename = out_name.."-"..new_rockver.."-"..new_rev..".rockspec" | 224 | local out_filename = out_name .. "-" .. new_rockver .. "-" .. tostring(new_rev) .. ".rockspec" |
| 212 | if out_dir then | 225 | if out_dir then |
| 213 | out_filename = dir.path(out_dir, out_filename) | 226 | out_filename = dir.path(out_dir, out_filename) |
| 214 | fs.make_dir(out_dir) | 227 | fs.make_dir(out_dir) |
| 215 | end | 228 | end |
| 216 | persist.save_from_table(out_filename, out_rs, type_rockspec.order) | 229 | persist.save_from_table(out_filename, out_rs, type_rockspec.order) |
| 217 | 230 | ||
| 218 | util.printout("Wrote "..out_filename) | 231 | util.printout("Wrote " .. out_filename) |
| 219 | 232 | ||
| 220 | local valid_out_rs, err = fetch.load_local_rockspec(out_filename) | 233 | local valid_out_rs, err = fetch.load_local_rockspec(out_filename) |
| 221 | if not valid_out_rs then | 234 | if not valid_out_rs then |
| 222 | return nil, "Failed loading generated rockspec: "..err | 235 | return nil, "Failed loading generated rockspec: " .. err |
| 223 | end | 236 | end |
| 224 | 237 | ||
| 225 | return true | 238 | return true |
diff --git a/src/luarocks/cmd/new_version.tl b/src/luarocks/cmd/new_version.tl index d61cb48b..b2fdf81a 100644 --- a/src/luarocks/cmd/new_version.tl +++ b/src/luarocks/cmd/new_version.tl | |||
| @@ -186,7 +186,7 @@ function new_version.command(args: Args): boolean, string | boolean | |||
| 186 | end | 186 | end |
| 187 | 187 | ||
| 188 | local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") | 188 | local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") |
| 189 | local new_ver, new_rev: string, string | 189 | local new_ver, new_rev: string, string | number |
| 190 | 190 | ||
| 191 | if args.tag and not args.new_version then | 191 | if args.tag and not args.new_version then |
| 192 | args.new_version = args.tag:gsub("^v", "") | 192 | args.new_version = args.tag:gsub("^v", "") |
| @@ -212,7 +212,7 @@ function new_version.command(args: Args): boolean, string | boolean | |||
| 212 | 212 | ||
| 213 | local out_rs, err = persist.load_into_table(filename) as Rockspec, string | 213 | local out_rs, err = persist.load_into_table(filename) as Rockspec, string |
| 214 | local out_name = out_rs.package:lower() | 214 | local out_name = out_rs.package:lower() |
| 215 | out_rs.version = new_rockver.."-"..new_rev | 215 | out_rs.version = new_rockver.."-"..tostring(new_rev) |
| 216 | 216 | ||
| 217 | local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) | 217 | local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) |
| 218 | if not ok then return nil, err end | 218 | if not ok then return nil, err end |
| @@ -221,7 +221,7 @@ function new_version.command(args: Args): boolean, string | boolean | |||
| 221 | out_rs.build.type = "builtin" | 221 | out_rs.build.type = "builtin" |
| 222 | end | 222 | end |
| 223 | 223 | ||
| 224 | local out_filename = out_name.."-"..new_rockver.."-"..new_rev..".rockspec" | 224 | local out_filename = out_name.."-"..new_rockver.."-"..tostring(new_rev)..".rockspec" |
| 225 | if out_dir then | 225 | if out_dir then |
| 226 | out_filename = dir.path(out_dir, out_filename) | 226 | out_filename = dir.path(out_dir, out_filename) |
| 227 | fs.make_dir(out_dir) | 227 | fs.make_dir(out_dir) |
