aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Ouellette <oue.paul18@gmail.com>2019-06-12 18:57:06 -0400
committerPaul Ouellette <oue.paul18@gmail.com>2019-07-29 17:07:39 -0400
commit3afab9d46de3889241c0f882cb312b8ec4a385ed (patch)
treede701561f2f6c5994d526436f68d671e65463b0e
parente92c37b6e3b30268033eaf2ad634998340c0fa3e (diff)
downloadluarocks-3afab9d46de3889241c0f882cb312b8ec4a385ed.tar.gz
luarocks-3afab9d46de3889241c0f882cb312b8ec4a385ed.tar.bz2
luarocks-3afab9d46de3889241c0f882cb312b8ec4a385ed.zip
Move build command to argparse
-rw-r--r--src/luarocks/cmd.lua8
-rw-r--r--src/luarocks/cmd/build.lua115
-rw-r--r--src/luarocks/cmd/install.lua2
-rw-r--r--src/luarocks/cmd/remove.lua2
-rw-r--r--src/luarocks/cmd/test.lua2
-rw-r--r--src/luarocks/deps.lua15
-rw-r--r--src/luarocks/util.lua31
7 files changed, 81 insertions, 94 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index 23ca023a..4929b326 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -370,6 +370,7 @@ Variables:
370 :argname("<server>") 370 :argname("<server>")
371 parser:option("--only-sources", "Restrict downloads to paths matching the given URL.") 371 parser:option("--only-sources", "Restrict downloads to paths matching the given URL.")
372 :argname("<url>") 372 :argname("<url>")
373 parser:option("--namespace"):hidden(true) -- TODO: Description
373 parser:option("--lua-dir", "Which Lua installation to use.") 374 parser:option("--lua-dir", "Which Lua installation to use.")
374 :argname("<prefix>") 375 :argname("<prefix>")
375 parser:option("--lua-version", "Which Lua version to use.") 376 parser:option("--lua-version", "Which Lua version to use.")
@@ -461,6 +462,11 @@ function cmd.run_command(program_name, description, commands, external_namespace
461 os.exit(cmd.errorcodes.OK) 462 os.exit(cmd.errorcodes.OK)
462 end 463 end
463 464
465 -- Compatibility for old flag
466 if args.nodeps then
467 args.deps_mode = "none"
468 end
469
464 if args.timeout then -- setting it in the config file will kick-in earlier in the process 470 if args.timeout then -- setting it in the config file will kick-in earlier in the process
465 cfg.connection_timeout = args.timeout 471 cfg.connection_timeout = args.timeout
466 end 472 end
@@ -472,7 +478,7 @@ function cmd.run_command(program_name, description, commands, external_namespace
472 args.lua_dir = args.value 478 args.lua_dir = args.value
473 end 479 end
474 end 480 end
475 481
476 ----------------------------------------------------------------------------- 482 -----------------------------------------------------------------------------
477 local lua_found, err = init_config(args) 483 local lua_found, err = init_config(args)
478 if err then 484 if err then
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua
index 23a94fa7..2b9f4dd6 100644
--- a/src/luarocks/cmd/build.lua
+++ b/src/luarocks/cmd/build.lua
@@ -18,40 +18,37 @@ local search = require("luarocks.search")
18local make = require("luarocks.cmd.make") 18local make = require("luarocks.cmd.make")
19local cmd = require("luarocks.cmd") 19local cmd = require("luarocks.cmd")
20 20
21cmd_build.help_summary = "build/compile a rock." 21function cmd_build.add_to_parser(parser)
22cmd_build.help_arguments = "[<flags...>] {<rockspec>|<rock>|<name> [<version>]}" 22 local cmd = parser:command("build", "Build and install a rock, compiling "..
23cmd_build.help = [[ 23 "its C parts if any.", util.see_also())
24Build and install a rock, compiling its C parts if any. 24 :summary("Build/compile a rock.")
25Argument may be a rockspec file, a source rock file 25 :add_help(false)
26or the name of a rock to be fetched from a repository. 26
27 27 cmd:argument("rock", "A rockspec file, a source rock file, or the name of "..
28--pack-binary-rock Do not install rock. Instead, produce a .rock file 28 "a rock to be fetched from a repository.")
29 with the contents of compilation in the current 29 cmd:argument("version", "Rock version.")
30 directory. 30 :args("?")
31 31
32--keep Do not remove previously installed versions of the 32 cmd:flag("--pack-binary-rock", "Do not install rock. Instead, produce a "..
33 rock after building a new one. This behavior can 33 ".rock file with the contents of compilation in the current directory.")
34 be made permanent by setting keep_other_versions=true 34 cmd:flag("--keep", "Do not remove previously installed versions of the "..
35 in the configuration file. 35 "rock after building a new one. This behavior can be made permanent by "..
36 36 "setting keep_other_versions=true in the configuration file.")
37--branch=<name> Override the `source.branch` field in the loaded 37 cmd:option("--branch", "Override the `source.branch` field in the loaded "..
38 rockspec. Allows to specify a different branch to 38 "rockspec. Allows to specify a different branch to fetch. Particularly "..
39 fetch. Particularly for "dev" rocks. 39 'for "dev" rocks.')
40 40 :argname("<name>")
41--only-deps Installs only the dependencies of the rock. 41 cmd:flag("--only-deps", "Installs only the dependencies of the rock.")
42 42 cmd:flag("--verify", "Verify signature of the rockspec or src.rock being "..
43--verify Verify signature of the rockspec or src.rock being 43 "built. If the rockspec or src.rock is being downloaded, LuaRocks will "..
44 built. If the rockspec or src.rock is being downloaded, 44 "attempt to download the signature as well. Otherwise, the signature "..
45 LuaRocks will attempt to download the signature as well. 45 "file should be already available locally in the same directory.\n"..
46 Otherwise, the signature file should be already 46 "You need the signer’s public key in your local keyring for this "..
47 available locally in the same directory. 47 "option to work properly.")
48 You need the signer’s public key in your local 48 cmd:flag("--sign", "To be used with --pack-binary-rock. Also produce a "..
49 keyring for this option to work properly. 49 "signature file for the generated .rock file.")
50 50 util.deps_mode_option(cmd)
51--sign To be used with --pack-binary-rock. Also produce 51end
52 a signature file for the generated .rock file.
53
54]]..util.deps_mode_help()
55 52
56--- Build and install a rock. 53--- Build and install a rock.
57-- @param rock_filename string: local or remote filename of a rock. 54-- @param rock_filename string: local or remote filename of a rock.
@@ -132,58 +129,54 @@ local function remove_doc_dir(name, version)
132end 129end
133 130
134--- Driver function for "build" command. 131--- Driver function for "build" command.
135-- @param name string: A local or remote rockspec or rock file.
136-- If a package name is given, forwards the request to "search" and, 132-- If a package name is given, forwards the request to "search" and,
137-- if returned a result, installs the matching rock. 133-- if returned a result, installs the matching rock.
138-- @param version string: When passing a package name, a version number may 134-- When passing a package name, a version number may also be given.
139-- also be given.
140-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an 135-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
141-- error message otherwise. exitcode is optionally returned. 136-- error message otherwise. exitcode is optionally returned.
142function cmd_build.command(flags, name, version) 137function cmd_build.command(args)
143 assert(type(name) == "string" or not name) 138 if not args.rock then
144 assert(type(version) == "string" or not version) 139 return make.command(args)
145
146 if not name then
147 return make.command(flags)
148 end 140 end
149 141
150 name = util.adjust_name_and_namespace(name, flags) 142 local name = util.adjust_name_and_namespace(args.rock, args)
151 143
152 local opts = build.opts({ 144 local opts = build.opts({
153 need_to_fetch = true, 145 need_to_fetch = true,
154 minimal_mode = false, 146 minimal_mode = false,
155 deps_mode = deps.get_deps_mode(flags), 147 deps_mode = deps.get_deps_mode(args),
156 build_only_deps = not not flags["only-deps"], 148 build_only_deps = not not args.only_deps,
157 namespace = flags["namespace"], 149 namespace = args.namespace,
158 branch = not not flags["branch"], 150 branch = not not args.branch,
159 verify = not not flags["verify"], 151 verify = not not args.verify,
160 }) 152 })
161 153
162 if flags["sign"] and not flags["pack-binary-rock"] then 154 if args.sign and not args.pack_binary_rock then
163 return nil, "In the build command, --sign is meant to be used only with --pack-binary-rock" 155 return nil, "In the build command, --sign is meant to be used only with --pack-binary-rock"
164 end 156 end
165 157
166 if flags["pack-binary-rock"] then 158 if args.pack_binary_rock then
167 return pack.pack_binary_rock(name, version, flags["sign"], function() 159 return pack.pack_binary_rock(name, args.version, args.sign, function()
168 opts.build_only_deps = false 160 opts.build_only_deps = false
169 local status, err, errcode = do_build(name, version, opts) 161 local status, err, errcode = do_build(name, args.version, opts)
170 if status and flags["no-doc"] then 162 if status and args.no_doc then
171 remove_doc_dir(name, version) 163 remove_doc_dir(name, args.version)
172 end 164 end
173 return status, err, errcode 165 return status, err, errcode
174 end) 166 end)
175 end 167 end
176 168
177 local ok, err = fs.check_command_permissions(flags) 169 local ok, err = fs.check_command_permissions(args)
178 if not ok then 170 if not ok then
179 return nil, err, cmd.errorcodes.PERMISSIONDENIED 171 return nil, err, cmd.errorcodes.PERMISSIONDENIED
180 end 172 end
181 173
182 ok, err = do_build(name, version, opts) 174 ok, err = do_build(name, args.version, opts)
183 if not ok then return nil, err end 175 if not ok then return nil, err end
176 local version
184 name, version = ok, err 177 name, version = ok, err
185 178
186 if flags["no-doc"] then 179 if args.no_doc then
187 remove_doc_dir(name, version) 180 remove_doc_dir(name, version)
188 end 181 end
189 182
@@ -191,15 +184,15 @@ function cmd_build.command(flags, name, version)
191 util.printout("Stopping after installing dependencies for " ..name.." "..version) 184 util.printout("Stopping after installing dependencies for " ..name.." "..version)
192 util.printout() 185 util.printout()
193 else 186 else
194 if (not flags["keep"]) and not cfg.keep_other_versions then 187 if (not args.keep) and not cfg.keep_other_versions then
195 local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"]) 188 local ok, err = remove.remove_other_versions(name, version, args.force, args.force_fast)
196 if not ok then 189 if not ok then
197 util.printerr(err) 190 util.printerr(err)
198 end 191 end
199 end 192 end
200 end 193 end
201 194
202 writer.check_dependencies(nil, deps.get_deps_mode(flags)) 195 writer.check_dependencies(nil, deps.get_deps_mode(args))
203 return name, version 196 return name, version
204end 197end
205 198
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua
index d1d7bf6c..ec6da14f 100644
--- a/src/luarocks/cmd/install.lua
+++ b/src/luarocks/cmd/install.lua
@@ -41,7 +41,7 @@ or a filename of a locally available rock.
41 You need the signer’s public key in your local 41 You need the signer’s public key in your local
42 keyring for this option to work properly. 42 keyring for this option to work properly.
43 43
44]]..util.deps_mode_help() 44]]--..util.deps_mode_help()
45 45
46install.opts = util.opts_table("install.opts", { 46install.opts = util.opts_table("install.opts", {
47 namespace = "string?", 47 namespace = "string?",
diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua
index 5ddf7477..f9345670 100644
--- a/src/luarocks/cmd/remove.lua
+++ b/src/luarocks/cmd/remove.lua
@@ -24,7 +24,7 @@ To override this check and force the removal, use --force.
24To perform a forced removal without reporting dependency issues, 24To perform a forced removal without reporting dependency issues,
25use --force-fast. 25use --force-fast.
26 26
27]]..util.deps_mode_help() 27]]--..util.deps_mode_help()
28 28
29--- Driver function for the "remove" command. 29--- Driver function for the "remove" command.
30-- @param name string: name of a rock. If a version is given, refer to 30-- @param name string: name of a rock. If a version is given, refer to
diff --git a/src/luarocks/cmd/test.lua b/src/luarocks/cmd/test.lua
index 413a029c..06ac0068 100644
--- a/src/luarocks/cmd/test.lua
+++ b/src/luarocks/cmd/test.lua
@@ -23,7 +23,7 @@ test suite arguments.
23 specified in the rockspec and it could not be 23 specified in the rockspec and it could not be
24 auto-detected. 24 auto-detected.
25 25
26]]..util.deps_mode_help() 26]]--..util.deps_mode_help()
27 27
28function cmd_test.command(flags, argument, ...) 28function cmd_test.command(flags, argument, ...)
29 assert(type(argument) == "string" or not argument) 29 assert(type(argument) == "string" or not argument)
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 9ee21772..af05ed05 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -569,20 +569,9 @@ function deps.check_lua_libdir(vars)
569 return nil, "Failed finding Lua library. You may need to configure LUA_LIBDIR.", "dependency" 569 return nil, "Failed finding Lua library. You may need to configure LUA_LIBDIR.", "dependency"
570end 570end
571 571
572local valid_deps_modes = {
573 one = true,
574 order = true,
575 all = true,
576 none = true,
577}
578
579function deps.check_deps_mode_flag(flag)
580 return valid_deps_modes[flag]
581end
582
583function deps.get_deps_mode(flags) 572function deps.get_deps_mode(flags)
584 if flags["deps-mode"] then 573 if flags["deps_mode"] then
585 return flags["deps-mode"] 574 return flags["deps_mode"]
586 else 575 else
587 return cfg.deps_mode 576 return cfg.deps_mode
588 end 577 end
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 60cfb3d8..635d3a97 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -215,23 +215,22 @@ function util.this_program(default)
215 return prog 215 return prog
216end 216end
217 217
218function util.deps_mode_help(program) 218function util.deps_mode_option(parser)
219 local cfg = require("luarocks.core.cfg") 219 local cfg = require("luarocks.core.cfg")
220 return [[ 220
221--deps-mode=<mode> How to handle dependencies. Four modes are supported: 221 parser:option("--deps-mode", "How to handle dependencies. Four modes are supported:\n"..
222 * all - use all trees from the rocks_trees list 222 "* all - use all trees from the rocks_trees list for finding dependencies\n"..
223 for finding dependencies 223 "* one - use only the current tree (possibly set with --tree)\n"..
224 * one - use only the current tree (possibly set 224 "* order - use trees based on order (use the current tree and all "..
225 with --tree) 225 "trees below it on the rocks_trees list)\n"..
226 * order - use trees based on order (use the current 226 "* none - ignore dependencies altogether.\n"..
227 tree and all trees below it on the rocks_trees list) 227 "The default mode may be set with the deps_mode entry in the configuration file.\n"..
228 * none - ignore dependencies altogether. 228 'The current default is "'..cfg.deps_mode..'".\n'..
229 The default mode may be set with the deps_mode entry 229 "Type '"..util.this_program(program or "luarocks").."' with no "..
230 in the configuration file. 230 "arguments to see your list of rocks trees.")
231 The current default is "]]..cfg.deps_mode..[[". 231 :argname("<mode>")
232 Type ']]..util.this_program(program or "luarocks")..[[' with no arguments to see 232 :choices({"all", "one", "order", "none"})
233 your list of rocks trees. 233 parser:flag("--nodeps"):hidden(true)
234]]
235end 234end
236 235
237function util.see_help(command, program) 236function util.see_help(command, program)