2
1
--- Module implementing the LuaRocks "install" command.
3
2
-- Installs binary rocks.
4
module("luarocks.install", package.seeall)
3
--module("luarocks.install", package.seeall)
5
package.loaded["luarocks.install"] = install
6
7
local path = require("luarocks.path")
7
local rep = require("luarocks.rep")
8
local repos = require("luarocks.repos")
8
9
local fetch = require("luarocks.fetch")
9
10
local util = require("luarocks.util")
10
11
local fs = require("luarocks.fs")
11
12
local deps = require("luarocks.deps")
12
13
local manif = require("luarocks.manif")
14
local remove = require("luarocks.remove")
13
15
local cfg = require("luarocks.cfg")
15
help_summary = "Install a rock."
17
help_arguments = "{<rock>|<name> [<version>]}"
17
install.help_summary = "Install a rock."
19
install.help_arguments = "{<rock>|<name> [<version>]}"
20
22
Argument may be the name of a rock to be fetched from a repository
21
23
or a filename of a locally available rock.
25
--keep Do not remove previously installed versions of the
26
rock after installing a new one. This behavior can
27
be made permanent by setting keep_other_versions=true
28
in the configuration file.
29
]]..util.deps_mode_help()
24
32
--- Install a binary rock.
25
33
-- @param rock_file string: local or remote filename of a rock.
26
function install_binary_rock(rock_file, no_deps)
34
-- @param deps_mode: string: Which trees to check dependencies for:
35
-- "one" for the current default tree, "all" for all trees,
36
-- "order" for all trees with priority >= the current default, "none" for no trees.
37
-- @return (string, string) or (nil, string, [string]): Name and version of
38
-- installed rock if succeeded or nil and an error message followed by an error code.
39
function install.install_binary_rock(rock_file, deps_mode)
27
40
assert(type(rock_file) == "string")
29
42
local name, version, arch = path.parse_name(rock_file)
37
47
if arch ~= "all" and arch ~= cfg.arch then
38
48
return nil, "Incompatible architecture "..arch, "arch"
40
if rep.is_installed(name, version) then
41
rep.delete_version(name, version)
50
if repos.is_installed(name, version) then
51
repos.delete_version(name, version)
44
54
local rollback = util.schedule_function(function()
54
64
return nil, "Failed loading rockspec for installed package: "..err, errcode
67
if deps_mode == "none" then
58
68
util.printerr("Warning: skipping dependency checks.")
60
70
ok, err, errcode = deps.check_external_deps(rockspec, "install")
67
77
if err then return nil, err end
71
ok, err, errcode = deps.fulfill_dependencies(rockspec)
80
if deps_mode ~= "none" then
81
ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode)
72
82
if err then return nil, err, errcode end
75
local wrap_bin_scripts = true
76
if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then
77
wrap_bin_scripts = false
80
ok, err = rep.deploy_files(name, version, rep.should_wrap_bin_scripts(rockspec))
85
ok, err = repos.deploy_files(name, version, repos.should_wrap_bin_scripts(rockspec))
81
86
if err then return nil, err end
83
88
util.remove_scheduled_function(rollback)
84
89
rollback = util.schedule_function(function()
85
rep.delete_version(name, version)
90
repos.delete_version(name, version)
88
ok, err = rep.run_hook(rockspec, "post_install")
93
ok, err = repos.run_hook(rockspec, "post_install")
89
94
if err then return nil, err end
91
ok, err = manif.update_manifest(name, version)
96
ok, err = manif.update_manifest(name, version, nil, deps_mode)
92
97
if err then return nil, err end
112
117
-- if returned a result, installs the matching rock.
113
118
-- @param version string: When passing a package name, a version number
114
119
-- may also be given.
120
-- @return boolean or (nil, string, exitcode): True if installation was
121
-- successful, nil and an error message otherwise. exitcode is optionally returned.
122
function install.run(...)
116
123
local flags, name, version = util.parse_flags(...)
117
124
if type(name) ~= "string" then
118
return nil, "Argument missing, see help."
125
return nil, "Argument missing. "..util.see_help("install")
121
128
local ok, err = fs.check_command_permissions(flags)
122
if not ok then return nil, err end
129
if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
124
131
if name:match("%.rockspec$") or name:match("%.src%.rock$") then
125
132
util.printout("Using "..name.."... switching to 'build' mode")
126
133
local build = require("luarocks.build")
127
return build.run(name, flags["local"] and "--local")
134
return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode"))
128
135
elseif name:match("%.rock$") then
129
return install_binary_rock(name, flags["nodeps"])
136
ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags))
137
if not ok then return nil, err end
138
local name, version = ok, err
139
if (not flags["keep"]) and not cfg.keep_other_versions then
140
local ok, err = remove.remove_other_versions(name, version, flags["force"])
141
if not ok then util.printerr(err) end
131
145
local search = require("luarocks.search")
132
146
local results, err = search.find_suitable_rock(search.make_query(name:lower(), version))
137
149
elseif type(results) == "string" then
138
150
local url = results
139
151
util.printout("Installing "..url.."...")
152
return install.run(url, util.forward_flags(flags))
143
155
util.printerr("Could not determine which rock to install.")
145
util.printout("Search results:")
146
util.printout("---------------")
156
util.title("Search results:")
147
157
search.print_results(results)
148
158
return nil, (next(results) and "Please narrow your query." or "No results found.")