~ubuntu-branches/ubuntu/vivid/luarocks/vivid-proposed

« back to all changes in this revision

Viewing changes to src/luarocks/install.lua

  • Committer: Package Import Robot
  • Author(s): Enrico Tassi
  • Date: 2014-10-11 15:26:47 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20141011152647-bkfciayfdz6elvv3
Tags: 2.2.0+dfsg-1
* New upstream release
* patch 0001-Fixed-detection-of-Debian-paths removed (applied upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
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)
 
4
local install = {}
 
5
package.loaded["luarocks.install"] = install
5
6
 
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")
14
16
 
15
 
help_summary = "Install a rock."
16
 
 
17
 
help_arguments = "{<rock>|<name> [<version>]}"
18
 
 
19
 
help = [[
 
17
install.help_summary = "Install a rock."
 
18
 
 
19
install.help_arguments = "{<rock>|<name> [<version>]}"
 
20
 
 
21
install.help = [[
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.
22
 
]]
 
24
 
 
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()
 
30
 
23
31
 
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")
28
41
 
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"
39
49
   end
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)
42
52
   end
43
53
   
44
54
   local rollback = util.schedule_function(function()
54
64
      return nil, "Failed loading rockspec for installed package: "..err, errcode
55
65
   end
56
66
 
57
 
   if no_deps then
 
67
   if deps_mode == "none" then
58
68
      util.printerr("Warning: skipping dependency checks.")
59
69
   else
60
70
      ok, err, errcode = deps.check_external_deps(rockspec, "install")
67
77
      if err then return nil, err end
68
78
   end
69
79
 
70
 
   if not no_deps then
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
73
83
   end
74
84
 
75
 
   local wrap_bin_scripts = true
76
 
   if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then
77
 
      wrap_bin_scripts = false
78
 
   end
79
 
 
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
82
87
 
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)
86
91
   end)
87
92
 
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
90
95
   
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
93
98
   
94
99
   local license = ""
101
106
   util.printout(name.." "..version.." is now installed in "..root_dir.." "..license)
102
107
   
103
108
   util.remove_scheduled_function(rollback)
104
 
   return true
 
109
   return name, version
105
110
end
106
111
 
107
112
--- Driver function for the "install" command.
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.
115
 
function run(...)
 
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")
119
126
   end
120
127
 
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
123
130
 
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
 
142
      end
 
143
      return name, version
130
144
   else
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.."...")
140
 
         return run(url)
 
152
         return install.run(url, util.forward_flags(flags))
141
153
      else
142
154
         util.printout()
143
155
         util.printerr("Could not determine which rock to install.")
144
 
         util.printout()
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.")
149
159
      end
150
160
   end
151
161
end
 
162
 
 
163
return install