aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/build.lua111
-rw-r--r--src/luarocks/download.lua45
-rw-r--r--src/luarocks/pack.lua43
-rw-r--r--src/luarocks/remove.lua50
-rw-r--r--src/luarocks/search.lua72
5 files changed, 9 insertions, 312 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index f3b054d2..ceaa20dd 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -1,43 +1,15 @@
1 1
2--- Module implementing the LuaRocks "build" command.
3-- Builds a rock, compiling its C parts if any.
4local build = {} 2local build = {}
5 3
6local pack = require("luarocks.pack")
7local path = require("luarocks.path") 4local path = require("luarocks.path")
8local util = require("luarocks.util") 5local util = require("luarocks.util")
9local repos = require("luarocks.repos")
10local fetch = require("luarocks.fetch") 6local fetch = require("luarocks.fetch")
11local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
12local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
13local deps = require("luarocks.deps") 9local deps = require("luarocks.deps")
14local writer = require("luarocks.manif.writer")
15local remove = require("luarocks.remove")
16local cfg = require("luarocks.core.cfg") 10local cfg = require("luarocks.core.cfg")
17 11local repos = require("luarocks.repos")
18build.help_summary = "Build/compile a rock." 12local writer = require("luarocks.manif.writer")
19build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}"
20build.help = [[
21Build and install a rock, compiling its C parts if any.
22Argument may be a rockspec file, a source rock file
23or the name of a rock to be fetched from a repository.
24
25--pack-binary-rock Do not install rock. Instead, produce a .rock file
26 with the contents of compilation in the current
27 directory.
28
29--keep Do not remove previously installed versions of the
30 rock after building a new one. This behavior can
31 be made permanent by setting keep_other_versions=true
32 in the configuration file.
33
34--branch=<name> Override the `source.branch` field in the loaded
35 rockspec. Allows to specify a different branch to
36 fetch. Particularly for SCM rocks.
37
38--only-deps Installs only the dependencies of the rock.
39
40]]..util.deps_mode_help()
41 13
42--- Install files to a given location. 14--- Install files to a given location.
43-- Takes a table where the array part is a list of filenames to be copied. 15-- Takes a table where the array part is a list of filenames to be copied.
@@ -361,83 +333,4 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m
361 return name, version 333 return name, version
362end 334end
363 335
364--- Build and install a rock.
365-- @param rock_file string: local or remote filename of a rock.
366-- @param need_to_fetch boolean: true if sources need to be fetched,
367-- false if the rockspec was obtained from inside a source rock.
368-- @param deps_mode: string: Which trees to check dependencies for:
369-- "one" for the current default tree, "all" for all trees,
370-- "order" for all trees with priority >= the current default, "none" for no trees.
371-- @param build_only_deps boolean: true to build the listed dependencies only.
372-- @return boolean or (nil, string, [string]): True if build was successful,
373-- or false and an error message and an optional error code.
374function build.build_rock(rock_file, need_to_fetch, deps_mode, build_only_deps)
375 assert(type(rock_file) == "string")
376 assert(type(need_to_fetch) == "boolean")
377
378 local ok, err, errcode
379 local unpack_dir
380 unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file)
381 if not unpack_dir then
382 return nil, err, errcode
383 end
384 local rockspec_file = path.rockspec_name_from_rock(rock_file)
385 ok, err = fs.change_dir(unpack_dir)
386 if not ok then return nil, err end
387 ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode, build_only_deps)
388 fs.pop_dir()
389 return ok, err, errcode
390end
391
392local function do_build(name, version, deps_mode, build_only_deps)
393 if name:match("%.rockspec$") then
394 return build.build_rockspec(name, true, false, deps_mode, build_only_deps)
395 elseif name:match("%.src%.rock$") then
396 return build.build_rock(name, false, deps_mode, build_only_deps)
397 elseif name:match("%.all%.rock$") then
398 local install = require("luarocks.install")
399 local install_fun = build_only_deps and install.install_binary_rock_deps or install.install_binary_rock
400 return install_fun(name, deps_mode)
401 elseif name:match("%.rock$") then
402 return build.build_rock(name, true, deps_mode, build_only_deps)
403 elseif not name:match(dir.separator) then
404 local search = require("luarocks.search")
405 return search.act_on_src_or_rockspec(do_build, name:lower(), version, nil, deps_mode, build_only_deps)
406 end
407 return nil, "Don't know what to do with "..name
408end
409
410--- Driver function for "build" command.
411-- @param name string: A local or remote rockspec or rock file.
412-- If a package name is given, forwards the request to "search" and,
413-- if returned a result, installs the matching rock.
414-- @param version string: When passing a package name, a version number may
415-- also be given.
416-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
417-- error message otherwise. exitcode is optionally returned.
418function build.command(flags, name, version)
419 if type(name) ~= "string" then
420 return nil, "Argument missing. "..util.see_help("build")
421 end
422 assert(type(version) == "string" or not version)
423
424 if flags["pack-binary-rock"] then
425 return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags))
426 else
427 local ok, err = fs.check_command_permissions(flags)
428 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
429 ok, err = do_build(name, version, deps.get_deps_mode(flags), flags["only-deps"])
430 if not ok then return nil, err end
431 name, version = ok, err
432 if flags["only-deps"] then
433 return name, version
434 end
435 if (not flags["keep"]) and not cfg.keep_other_versions then
436 local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"])
437 if not ok then util.printerr(err) end
438 end
439 return name, version
440 end
441end
442
443return build 336return build
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index 557d1b65..c0f2678f 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -1,9 +1,5 @@
1
2--- Module implementing the luarocks "download" command.
3-- Download a rock from the repository.
4local download = {} 1local download = {}
5 2
6local util = require("luarocks.util")
7local path = require("luarocks.path") 3local path = require("luarocks.path")
8local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
9local search = require("luarocks.search") 5local search = require("luarocks.search")
@@ -11,16 +7,6 @@ local fs = require("luarocks.fs")
11local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
12local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
13 9
14download.help_summary = "Download a specific rock file from a rocks server."
15download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]"
16
17download.help = [[
18--all Download all files if there are multiple matches.
19--source Download .src.rock if available.
20--rockspec Download .rockspec if available.
21--arch=<arch> Download rock for a specific architecture.
22]]
23
24local function get_file(filename) 10local function get_file(filename)
25 local protocol, pathname = dir.split_url(filename) 11 local protocol, pathname = dir.split_url(filename)
26 if protocol == "file" then 12 if protocol == "file" then
@@ -46,8 +32,8 @@ function download.download(arch, name, version, all)
46 local has_result = false 32 local has_result = false
47 local all_ok = true 33 local all_ok = true
48 local any_err = "" 34 local any_err = ""
49 for name, result in pairs(results) do 35 for _, result in pairs(results) do
50 for version, items in pairs(result) do 36 for _, items in pairs(result) do
51 for _, item in ipairs(items) do 37 for _, item in ipairs(items) do
52 -- Ignore provided rocks. 38 -- Ignore provided rocks.
53 if item.arch ~= "installed" then 39 if item.arch ~= "installed" then
@@ -77,31 +63,4 @@ function download.download(arch, name, version, all)
77 (search_err and ": "..search_err or ".") 63 (search_err and ": "..search_err or ".")
78end 64end
79 65
80--- Driver function for the "download" command.
81-- @param name string: a rock name.
82-- @param version string or nil: if the name of a package is given, a
83-- version may also be passed.
84-- @return boolean or (nil, string): true if successful or nil followed
85-- by an error message.
86function download.command(flags, name, version)
87 assert(type(version) == "string" or not version)
88 if type(name) ~= "string" and not flags["all"] then
89 return nil, "Argument missing. "..util.see_help("download")
90 end
91 if not name then name, version = "", "" end
92
93 local arch
94
95 if flags["source"] then
96 arch = "src"
97 elseif flags["rockspec"] then
98 arch = "rockspec"
99 elseif flags["arch"] then
100 arch = flags["arch"]
101 end
102
103 local dl, err = download.download(arch, name:lower(), version, flags["all"])
104 return dl and true, err
105end
106
107return download 66return download
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index 655cbf37..b721a209 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -1,6 +1,5 @@
1 1
2--- Module implementing the LuaRocks "pack" command. 2-- Create rock files, packing sources or binaries.
3-- Creates a rock, packing sources or binaries.
4local pack = {} 3local pack = {}
5 4
6local unpack = unpack or table.unpack 5local unpack = unpack or table.unpack
@@ -15,15 +14,6 @@ local dir = require("luarocks.dir")
15local manif = require("luarocks.manif") 14local manif = require("luarocks.manif")
16local search = require("luarocks.search") 15local search = require("luarocks.search")
17 16
18pack.help_summary = "Create a rock, packing sources or binaries."
19pack.help_arguments = "{<rockspec>|<name> [<version>]}"
20pack.help = [[
21Argument may be a rockspec file, for creating a source rock,
22or the name of an installed package, for creating a binary rock.
23In the latter case, the app version may be given as a second
24argument.
25]]
26
27--- Create a source rock. 17--- Create a source rock.
28-- Packages a rockspec and its required source files in a rock 18-- Packages a rockspec and its required source files in a rock
29-- file with the .src.rock extension, which can later be built and 19-- file with the .src.rock extension, which can later be built and
@@ -86,7 +76,7 @@ end
86-- @param tree string or nil: An optional tree to pick the package from. 76-- @param tree string or nil: An optional tree to pick the package from.
87-- @return string or (nil, string): The filename of the resulting 77-- @return string or (nil, string): The filename of the resulting
88-- .src.rock file; or nil and an error message. 78-- .src.rock file; or nil and an error message.
89local function do_pack_binary_rock(name, version, tree) 79function pack.pack_installed_rock(name, version, tree)
90 assert(type(name) == "string") 80 assert(type(name) == "string")
91 assert(type(version) == "string" or not version) 81 assert(type(version) == "string" or not version)
92 82
@@ -160,34 +150,7 @@ function pack.pack_binary_rock(name, version, cmd, ...)
160 if not rname then 150 if not rname then
161 rname, rversion = name, version 151 rname, rversion = name, version
162 end 152 end
163 return do_pack_binary_rock(rname, rversion, temp_dir) 153 return pack.pack_installed_rock(rname, rversion, temp_dir)
164end
165
166--- Driver function for the "pack" command.
167-- @param arg string: may be a rockspec file, for creating a source rock,
168-- or the name of an installed package, for creating a binary rock.
169-- @param version string or nil: if the name of a package is given, a
170-- version may also be passed.
171-- @return boolean or (nil, string): true if successful or nil followed
172-- by an error message.
173function pack.command(flags, arg, version)
174 assert(type(version) == "string" or not version)
175 if type(arg) ~= "string" then
176 return nil, "Argument missing. "..util.see_help("pack")
177 end
178
179 local file, err
180 if arg:match(".*%.rockspec") then
181 file, err = pack.pack_source_rock(arg)
182 else
183 file, err = do_pack_binary_rock(arg:lower(), version, flags["tree"])
184 end
185 if err then
186 return nil, err
187 else
188 util.printout("Packed: "..file)
189 return true
190 end
191end 154end
192 155
193return pack 156return pack
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index e7f37604..6cc8334f 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -1,6 +1,3 @@
1
2--- Module implementing the LuaRocks "remove" command.
3-- Uninstalls rocks.
4local remove = {} 1local remove = {}
5 2
6local search = require("luarocks.search") 3local search = require("luarocks.search")
@@ -10,19 +7,6 @@ local repos = require("luarocks.repos")
10local path = require("luarocks.path") 7local path = require("luarocks.path")
11local util = require("luarocks.util") 8local util = require("luarocks.util")
12local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
13local fs = require("luarocks.fs")
14
15remove.help_summary = "Uninstall a rock."
16remove.help_arguments = "[--force|--force-fast] <name> [<version>]"
17remove.help = [[
18Argument is the name of a rock to be uninstalled.
19If a version is not given, try to remove all versions at once.
20Will only perform the removal if it does not break dependencies.
21To override this check and force the removal, use --force.
22To perform a forced removal without reporting dependency issues,
23use --force-fast.
24
25]]..util.deps_mode_help()
26 10
27--- Obtain a list of packages that depend on the given set of packages 11--- Obtain a list of packages that depend on the given set of packages
28-- (where all packages of the set are versions of one program). 12-- (where all packages of the set are versions of one program).
@@ -128,38 +112,4 @@ function remove.remove_other_versions(name, version, force, fast)
128 return true 112 return true
129end 113end
130 114
131--- Driver function for the "remove" command.
132-- @param name string: name of a rock. If a version is given, refer to
133-- a specific version; otherwise, try to remove all versions.
134-- @param version string: When passing a package name, a version number
135-- may also be given.
136-- @return boolean or (nil, string, exitcode): True if removal was
137-- successful, nil and an error message otherwise. exitcode is optionally returned.
138function remove.command(flags, name, version)
139 if type(name) ~= "string" then
140 return nil, "Argument missing. "..util.see_help("remove")
141 end
142
143 local deps_mode = flags["deps-mode"] or cfg.deps_mode
144
145 local ok, err = fs.check_command_permissions(flags)
146 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
147
148 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$")
149 local filename = name
150 if rock_type then
151 name, version = path.parse_name(filename)
152 if not name then return nil, "Invalid "..rock_type.." filename: "..filename end
153 end
154
155 local results = {}
156 name = name:lower()
157 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version))
158 if not results[name] then
159 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir)
160 end
161
162 return remove.remove_search_results(results, name, deps_mode, flags["force"], flags["force-fast"])
163end
164
165return remove 115return remove
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 44eff694..c59f9534 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -1,9 +1,5 @@
1
2--- Module implementing the LuaRocks "search" command.
3-- Queries LuaRocks servers.
4local search = {} 1local search = {}
5 2
6
7local dir = require("luarocks.dir") 3local dir = require("luarocks.dir")
8local path = require("luarocks.path") 4local path = require("luarocks.path")
9local manif = require("luarocks.manif") 5local manif = require("luarocks.manif")
@@ -11,17 +7,6 @@ local deps = require("luarocks.deps")
11local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
12local util = require("luarocks.util") 8local util = require("luarocks.util")
13 9
14search.help_summary = "Query the LuaRocks servers."
15search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }"
16search.help = [[
17--source Return only rockspecs and source rocks,
18 to be used with the "build" command.
19--binary Return only pure Lua and binary rocks (rocks that can be used
20 with the "install" command without requiring a C toolchain).
21--all List all contents of the server that are suitable to
22 this platform, do not filter by name.
23]]
24
25--- Convert the arch field of a query table to table format. 10--- Convert the arch field of a query table to table format.
26-- @param query table: A query table. 11-- @param query table: A query table.
27local function query_arch_as_table(query) 12local function query_arch_as_table(query)
@@ -55,7 +40,7 @@ end
55-- identifier), "rockspec" or "installed" 40-- identifier), "rockspec" or "installed"
56-- @param repo string: Pathname of a local repository of URL of 41-- @param repo string: Pathname of a local repository of URL of
57-- rocks server. 42-- rocks server.
58local function store_result(results, name, version, arch, repo) 43function search.store_result(results, name, version, arch, repo)
59 assert(type(results) == "table") 44 assert(type(results) == "table")
60 assert(type(name) == "string") 45 assert(type(name) == "string")
61 assert(type(version) == "string") 46 assert(type(version) == "string")
@@ -108,7 +93,7 @@ local function store_if_match(results, repo, name, version, arch, query)
108 if match_name(query, name) then 93 if match_name(query, name) then
109 if query.arch[arch] or query.arch["any"] then 94 if query.arch[arch] or query.arch["any"] then
110 if deps.match_constraints(deps.parse_version(version), query.constraints) then 95 if deps.match_constraints(deps.parse_version(version), query.constraints) then
111 store_result(results, name, version, arch, repo) 96 search.store_result(results, name, version, arch, repo)
112 end 97 end
113 end 98 end
114 end 99 end
@@ -370,28 +355,6 @@ function search.print_results(results, porcelain)
370 end 355 end
371end 356end
372 357
373--- Splits a list of search results into two lists, one for "source" results
374-- to be used with the "build" command, and one for "binary" results to be
375-- used with the "install" command.
376-- @param results table: A search results table.
377-- @return (table, table): Two tables, one for source and one for binary
378-- results.
379local function split_source_and_binary_results(results)
380 local sources, binaries = {}, {}
381 for name, versions in pairs(results) do
382 for version, repositories in pairs(versions) do
383 for _, repo in ipairs(repositories) do
384 local where = sources
385 if repo.arch == "all" or repo.arch == cfg.arch then
386 where = binaries
387 end
388 store_result(where, name, version, repo.arch, repo.repo)
389 end
390 end
391 end
392 return sources, binaries
393end
394
395--- Given a name and optionally a version, try to find in the rocks 358--- Given a name and optionally a version, try to find in the rocks
396-- servers a single .src.rock or .rockspec file that satisfies 359-- servers a single .src.rock or .rockspec file that satisfies
397-- the request, and run the given function on it; or display to the 360-- the request, and run the given function on it; or display to the
@@ -448,35 +411,4 @@ function search.pick_installed_rock(name, version, given_tree)
448 return name, version, repo, repo_url 411 return name, version, repo, repo_url
449end 412end
450 413
451--- Driver function for "search" command.
452-- @param name string: A substring of a rock name to search.
453-- @param version string or nil: a version may also be passed.
454-- @return boolean or (nil, string): True if build was successful; nil and an
455-- error message otherwise.
456function search.command(flags, name, version)
457 if flags["all"] then
458 name, version = "", nil
459 end
460
461 if type(name) ~= "string" and not flags["all"] then
462 return nil, "Enter name and version or use --all. "..util.see_help("search")
463 end
464
465 local query = search.make_query(name:lower(), version)
466 query.exact_name = false
467 local results, err = search.search_repos(query)
468 local porcelain = flags["porcelain"]
469 util.title("Search results:", porcelain, "=")
470 local sources, binaries = split_source_and_binary_results(results)
471 if next(sources) and not flags["binary"] then
472 util.title("Rockspecs and source rocks:", porcelain)
473 search.print_results(sources, porcelain)
474 end
475 if next(binaries) and not flags["source"] then
476 util.title("Binary and pure-Lua rocks:", porcelain)
477 search.print_results(binaries, porcelain)
478 end
479 return true
480end
481
482return search 414return search