aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-07-04 15:16:25 -0300
committerHisham Muhammad <hisham@gobolinux.org>2013-07-04 15:16:25 -0300
commitaff559479ce9af00327295927e2ed85d72fe6cd0 (patch)
tree4cead054c5d9c5b67f084bebecc91e8079ab5131
parentd124cdb40076e6f5363bd7e152c6ef0479c4bf9a (diff)
downloadluarocks-aff559479ce9af00327295927e2ed85d72fe6cd0.tar.gz
luarocks-aff559479ce9af00327295927e2ed85d72fe6cd0.tar.bz2
luarocks-aff559479ce9af00327295927e2ed85d72fe6cd0.zip
Remove other previously installed versions when running 'build' or 'install'.
-rw-r--r--src/luarocks/build.lua28
-rw-r--r--src/luarocks/deps.lua21
-rw-r--r--src/luarocks/install.lua16
-rw-r--r--src/luarocks/make_manifest.lua7
-rw-r--r--src/luarocks/pack.lua2
-rw-r--r--src/luarocks/purge.lua2
-rw-r--r--src/luarocks/remove.lua97
7 files changed, 106 insertions, 67 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 71b3cb89..71dcda94 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -12,18 +12,23 @@ local fs = require("luarocks.fs")
12local dir = require("luarocks.dir") 12local dir = require("luarocks.dir")
13local deps = require("luarocks.deps") 13local deps = require("luarocks.deps")
14local manif = require("luarocks.manif") 14local manif = require("luarocks.manif")
15local search = require("luarocks.search")
16local remove = require("luarocks.remove")
15local cfg = require("luarocks.cfg") 17local cfg = require("luarocks.cfg")
16 18
17help_summary = "Build/compile a rock." 19help_summary = "Build/compile a rock."
18help_arguments = "[--pack-binary-rock] {<rockspec>|<rock>|<name> [<version>]}" 20help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}"
19help = [[ 21help = [[
20Build and install a rock, compiling its C parts if any. 22Build and install a rock, compiling its C parts if any.
21Argument may be a rockspec file, a source rock file 23Argument may be a rockspec file, a source rock file
22or the name of a rock to be fetched from a repository. 24or the name of a rock to be fetched from a repository.
23 25
24If --pack-binary-rock is passed, the rock is not installed; 26--pack-binary-rock Do not install rock. Instead, produce a .rock file
25instead, a .rock file with the contents of compilation is produced 27 with the contents of compilation in the current
26in the current directory. 28 directory.
29
30--keep Do not remove previously installed versions of the
31 rock after building a new one.
27]] 32]]
28 33
29--- Install files to a given location. 34--- Install files to a given location.
@@ -114,8 +119,8 @@ end
114-- @param deps_mode string: Dependency mode: "one" for the current default tree, 119-- @param deps_mode string: Dependency mode: "one" for the current default tree,
115-- "all" for all trees, "order" for all trees with priority >= the current default, 120-- "all" for all trees, "order" for all trees with priority >= the current default,
116-- "none" for no trees. 121-- "none" for no trees.
117-- @return boolean or (nil, string, [string]): True if succeeded or 122-- @return (string, string) or (nil, string, [string]): Name and version of
118-- nil and an error message followed by an error code. 123-- installed rock if succeeded or nil and an error message followed by an error code.
119function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) 124function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode)
120 assert(type(rockspec_file) == "string") 125 assert(type(rockspec_file) == "string")
121 assert(type(need_to_fetch) == "boolean") 126 assert(type(need_to_fetch) == "boolean")
@@ -272,7 +277,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode)
272 util.printout(name.." "..version.." is now built and installed in "..root_dir.." "..license) 277 util.printout(name.." "..version.." is now built and installed in "..root_dir.." "..license)
273 278
274 util.remove_scheduled_function(rollback) 279 util.remove_scheduled_function(rollback)
275 return true 280 return name, version
276end 281end
277 282
278--- Build and install a rock. 283--- Build and install a rock.
@@ -336,6 +341,13 @@ function run(...)
336 else 341 else
337 local ok, err = fs.check_command_permissions(flags) 342 local ok, err = fs.check_command_permissions(flags)
338 if not ok then return nil, err end 343 if not ok then return nil, err end
339 return do_build(name, version, deps.get_deps_mode(flags)) 344 ok, err = do_build(name, version, deps.get_deps_mode(flags))
345 if not ok then return nil, err end
346 local name, version = ok, err
347 if (not flags["keep"]) and not cfg.keep_other_versions then
348 local ok, err = remove.remove_other_versions(name, version, flags["force"])
349 if not ok then util.printerr(err) end
350 end
351 return name, version
340 end 352 end
341end 353end
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 6d5f3fef..7aefd40e 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -290,15 +290,18 @@ function match_constraints(version, constraints)
290 local ok = true 290 local ok = true
291 setmetatable(version, version_mt) 291 setmetatable(version, version_mt)
292 for _, constr in pairs(constraints) do 292 for _, constr in pairs(constraints) do
293 local constr_version = constr.version 293 if type(constr.version) == "string" then
294 setmetatable(constr.version, version_mt) 294 constr.version = parse_version(constr.version)
295 if constr.op == "==" then ok = version == constr_version 295 end
296 elseif constr.op == "~=" then ok = version ~= constr_version 296 local constr_version, constr_op = constr.version, constr.op
297 elseif constr.op == ">" then ok = version > constr_version 297 setmetatable(constr_version, version_mt)
298 elseif constr.op == "<" then ok = version < constr_version 298 if constr_op == "==" then ok = version == constr_version
299 elseif constr.op == ">=" then ok = version >= constr_version 299 elseif constr_op == "~=" then ok = version ~= constr_version
300 elseif constr.op == "<=" then ok = version <= constr_version 300 elseif constr_op == ">" then ok = version > constr_version
301 elseif constr.op == "~>" then ok = partial_match(version, constr_version) 301 elseif constr_op == "<" then ok = version < constr_version
302 elseif constr_op == ">=" then ok = version >= constr_version
303 elseif constr_op == "<=" then ok = version <= constr_version
304 elseif constr_op == "~>" then ok = partial_match(version, constr_version)
302 end 305 end
303 if not ok then break end 306 if not ok then break end
304 end 307 end
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 3960dcb8..8ada2d50 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -10,6 +10,7 @@ local util = require("luarocks.util")
10local fs = require("luarocks.fs") 10local fs = require("luarocks.fs")
11local deps = require("luarocks.deps") 11local deps = require("luarocks.deps")
12local manif = require("luarocks.manif") 12local manif = require("luarocks.manif")
13local remove = require("luarocks.remove")
13local cfg = require("luarocks.cfg") 14local cfg = require("luarocks.cfg")
14 15
15help_summary = "Install a rock." 16help_summary = "Install a rock."
@@ -26,8 +27,8 @@ or a filename of a locally available rock.
26-- @param deps_mode: string: Which trees to check dependencies for: 27-- @param deps_mode: string: Which trees to check dependencies for:
27-- "one" for the current default tree, "all" for all trees, 28-- "one" for the current default tree, "all" for all trees,
28-- "order" for all trees with priority >= the current default, "none" for no trees. 29-- "order" for all trees with priority >= the current default, "none" for no trees.
29-- @return boolean or (nil, string, [string]): True if succeeded or 30-- @return (string, string) or (nil, string, [string]): Name and version of
30-- nil and an error message and an optional error code. 31-- installed rock if succeeded or nil and an error message followed by an error code.
31function install_binary_rock(rock_file, deps_mode) 32function install_binary_rock(rock_file, deps_mode)
32 assert(type(rock_file) == "string") 33 assert(type(rock_file) == "string")
33 34
@@ -103,7 +104,7 @@ function install_binary_rock(rock_file, deps_mode)
103 util.printout(name.." "..version.." is now installed in "..root_dir.." "..license) 104 util.printout(name.." "..version.." is now installed in "..root_dir.." "..license)
104 105
105 util.remove_scheduled_function(rollback) 106 util.remove_scheduled_function(rollback)
106 return true 107 return name, version
107end 108end
108 109
109--- Driver function for the "install" command. 110--- Driver function for the "install" command.
@@ -130,7 +131,14 @@ function run(...)
130 local build = require("luarocks.build") 131 local build = require("luarocks.build")
131 return build.run(name, deps.get_deps_mode(flags), flags["local"] and "--local") 132 return build.run(name, deps.get_deps_mode(flags), flags["local"] and "--local")
132 elseif name:match("%.rock$") then 133 elseif name:match("%.rock$") then
133 return install_binary_rock(name, deps.get_deps_mode(flags)) 134 ok, err = install_binary_rock(name, deps.get_deps_mode(flags))
135 if not ok then return nil, err end
136 local name, version = ok, err
137 if (not flags["keep"]) and not cfg.keep_other_versions then
138 local ok, err = remove.remove_other_versions(name, version, flags["force"])
139 if not ok then util.printerr(err) end
140 end
141 return name, version
134 else 142 else
135 local search = require("luarocks.search") 143 local search = require("luarocks.search")
136 local results, err = search.find_suitable_rock(search.make_query(name:lower(), version)) 144 local results, err = search.find_suitable_rock(search.make_query(name:lower(), version))
diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua
index f793dcf2..a698f830 100644
--- a/src/luarocks/make_manifest.lua
+++ b/src/luarocks/make_manifest.lua
@@ -13,6 +13,9 @@ help_summary = "Compile a manifest file for a repository."
13 13
14help = [[ 14help = [[
15<argument>, if given, is a local repository pathname. 15<argument>, if given, is a local repository pathname.
16
17--local-tree If given, do not write versioned versions of the manifest file.
18 Use this when rebuilding the manifest of a local rocks tree.
16]] 19]]
17 20
18--- Driver function for "make_manifest" command. 21--- Driver function for "make_manifest" command.
@@ -28,8 +31,8 @@ function run(...)
28 31
29 util.printout("Making manifest for "..repo) 32 util.printout("Making manifest for "..repo)
30 33
31 local ok, err = manif.make_manifest(repo, deps.get_deps_mode(flags), true) 34 local ok, err = manif.make_manifest(repo, deps.get_deps_mode(flags), not flags["local-tree"])
32 if ok then 35 if ok and not flags["local-tree"] then
33 util.printout("Generating index.html for "..repo) 36 util.printout("Generating index.html for "..repo)
34 index.make_index(repo) 37 index.make_index(repo)
35 end 38 end
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index eaa0e165..ed340a35 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -111,7 +111,7 @@ local function do_pack_binary_rock(name, version)
111 111
112 local root = path.root_dir(info.repo) 112 local root = path.root_dir(info.repo)
113 local prefix = path.install_dir(name, version, root) 113 local prefix = path.install_dir(name, version, root)
114 114print(prefix)
115 if not fs.exists(prefix) then 115 if not fs.exists(prefix) then
116 return nil, "'"..name.." "..version.."' does not seem to be an installed rock." 116 return nil, "'"..name.." "..version.."' does not seem to be an installed rock."
117 end 117 end
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua
index 46a023e9..6b094061 100644
--- a/src/luarocks/purge.lua
+++ b/src/luarocks/purge.lua
@@ -44,5 +44,5 @@ function run(...)
44 end 44 end
45 end 45 end
46 end 46 end
47 return manif.make_manifest(cfg.rocks_dir, "one", true) 47 return manif.make_manifest(cfg.rocks_dir, "one")
48end 48end
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index 8c899a0a..96816419 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -69,6 +69,58 @@ local function delete_versions(name, versions)
69 return true 69 return true
70end 70end
71 71
72function remove_search_results(results, name, deps_mode, force)
73 local versions = results[name]
74
75 local version = next(versions)
76 local second = next(versions, version)
77
78 util.printout("Checking stability of dependencies on the absence of")
79 util.printout(name.." "..table.concat(util.keys(versions), ", ").."...")
80 util.printout()
81
82 local dependents = check_dependents(name, versions, deps_mode)
83
84 if #dependents == 0 or force then
85 if #dependents > 0 then
86 util.printerr("The following packages may be broken by this forced removal:")
87 for _, dependent in ipairs(dependents) do
88 util.printerr(dependent.name.." "..dependent.version)
89 end
90 util.printerr()
91 end
92 local ok, err = delete_versions(name, versions)
93 if not ok then return nil, err end
94 ok, err = manif.make_manifest(cfg.rocks_dir, deps_mode)
95 if not ok then return nil, err end
96 else
97 if not second then
98 util.printerr("Will not remove "..name.." "..version..".")
99 util.printerr("Removing it would break dependencies for: ")
100 else
101 util.printerr("Will not remove installed versions of "..name..".")
102 util.printerr("Removing them would break dependencies for: ")
103 end
104 for _, dependent in ipairs(dependents) do
105 util.printerr(dependent.name.." "..dependent.version)
106 end
107 util.printerr()
108 util.printerr("Use --force to force removal (warning: this may break modules).")
109 return nil, "Failed removing."
110 end
111 util.printout("Removal successful.")
112 return true
113end
114
115function remove_other_versions(name, version, force)
116 local results = {}
117 search.manifest_search(results, cfg.rocks_dir, { name = name, exact_name = true, constraints = {{ op = "~=", version = version}} })
118 if results[name] then
119 return remove_search_results(results, name, cfg.deps_mode, force)
120 end
121 return true
122end
123
72--- Driver function for the "remove" command. 124--- Driver function for the "remove" command.
73-- @param name string: name of a rock. If a version is given, refer to 125-- @param name string: name of a rock. If a version is given, refer to
74-- a specific version; otherwise, try to remove all versions. 126-- a specific version; otherwise, try to remove all versions.
@@ -97,48 +149,9 @@ function run(...)
97 149
98 local results = {} 150 local results = {}
99 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) 151 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version))
100 152 if not results[name] then
101 local versions = results[name]
102 if not versions then
103 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in local tree." 153 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in local tree."
104 else
105 local version = next(versions)
106 local second = next(versions, version)
107
108 util.printout("Checking stability of dependencies on the absence of")
109 util.printout(name.." "..table.concat(util.keys(versions), ", ").."...")
110 util.printout()
111
112 local dependents = check_dependents(name, versions, deps_mode)
113
114 if #dependents == 0 or flags["force"] then
115 if #dependents > 0 then
116 util.printerr("The following packages may be broken by this forced removal:")
117 for _, dependent in ipairs(dependents) do
118 util.printerr(dependent.name.." "..dependent.version)
119 end
120 util.printerr()
121 end
122 local ok, err = delete_versions(name, versions)
123 if not ok then return nil, err end
124 ok, err = manif.make_manifest(cfg.rocks_dir, deps_mode)
125 if not ok then return nil, err end
126 else
127 if not second then
128 util.printerr("Will not remove "..name.." "..version..".")
129 util.printerr("Removing it would break dependencies for: ")
130 else
131 util.printerr("Will not remove all versions of "..name..".")
132 util.printerr("Removing them would break dependencies for: ")
133 end
134 for _, dependent in ipairs(dependents) do
135 util.printerr(dependent.name.." "..dependent.version)
136 end
137 util.printerr()
138 util.printerr("Use --force to force removal (warning: this may break modules).")
139 return nil, "Failed removing."
140 end
141 end 154 end
142 util.printout("Removal successful.") 155
143 return true 156 return remove_search_results(results, name, deps_mode, flags["force"])
144end 157end