aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnacio Burgueño <iburgueno@gmail.com>2015-04-14 13:46:35 -0300
committerIgnacio Burgueño <iburgueno@gmail.com>2015-04-14 13:46:35 -0300
commit2ee6bd7b5d840375b8887d68a89ad53b6bd53c00 (patch)
tree05cdec68b6ac4976b68724bff6ca997550ab9a73
parent6dd402bb702f9eee7eecd833f9325e71c0d84a04 (diff)
parent15ad97bb124c800a95ac0d2d46f747e711fd3f8e (diff)
downloadluarocks-2ee6bd7b5d840375b8887d68a89ad53b6bd53c00.tar.gz
luarocks-2ee6bd7b5d840375b8887d68a89ad53b6bd53c00.tar.bz2
luarocks-2ee6bd7b5d840375b8887d68a89ad53b6bd53c00.zip
Merge pull request #349 from ignacio/build_only_deps
Adds --only-deps flag to the 'build' command.
-rw-r--r--.travis.yml2
-rw-r--r--src/luarocks/build.lua36
-rw-r--r--src/luarocks/install.lua49
-rw-r--r--src/luarocks/util.lua1
-rw-r--r--test/testing.lua12
-rwxr-xr-xtest/testing.sh5
6 files changed, 91 insertions, 14 deletions
diff --git a/.travis.yml b/.travis.yml
index 54778583..db762a84 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,8 @@ language: c
2 2
3compiler: gcc 3compiler: gcc
4 4
5sudo: false
6
5env: 7env:
6 matrix: 8 matrix:
7 - LUA_VER=5.1.5 9 - LUA_VER=5.1.5
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 96191b11..977be344 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -37,6 +37,8 @@ or the name of a rock to be fetched from a repository.
37 rockspec. Allows to specify a different branch to 37 rockspec. Allows to specify a different branch to
38 fetch. Particularly for SCM rocks. 38 fetch. Particularly for SCM rocks.
39 39
40--only-deps Installs only the dependencies of the rock.
41
40]]..util.deps_mode_help() 42]]..util.deps_mode_help()
41 43
42--- Install files to a given location. 44--- Install files to a given location.
@@ -157,9 +159,10 @@ end
157-- @param deps_mode string: Dependency mode: "one" for the current default tree, 159-- @param deps_mode string: Dependency mode: "one" for the current default tree,
158-- "all" for all trees, "order" for all trees with priority >= the current default, 160-- "all" for all trees, "order" for all trees with priority >= the current default,
159-- "none" for no trees. 161-- "none" for no trees.
162-- @param build_only_deps boolean: true to build the listed dependencies only.
160-- @return (string, string) or (nil, string, [string]): Name and version of 163-- @return (string, string) or (nil, string, [string]): Name and version of
161-- installed rock if succeeded or nil and an error message followed by an error code. 164-- installed rock if succeeded or nil and an error message followed by an error code.
162function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) 165function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode, build_only_deps)
163 assert(type(rockspec_file) == "string") 166 assert(type(rockspec_file) == "string")
164 assert(type(need_to_fetch) == "boolean") 167 assert(type(need_to_fetch) == "boolean")
165 168
@@ -181,13 +184,19 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m
181 end 184 end
182 end 185 end
183 186
187 local name, version = rockspec.name, rockspec.version
188 if build_only_deps then
189 util.printout("Stopping after installing dependencies for " ..name.." "..version)
190 util.printout()
191 return name, version
192 end
193
184 local ok 194 local ok
185 ok, err, errcode = deps.check_external_deps(rockspec, "build") 195 ok, err, errcode = deps.check_external_deps(rockspec, "build")
186 if err then 196 if err then
187 return nil, err, errcode 197 return nil, err, errcode
188 end 198 end
189 199
190 local name, version = rockspec.name, rockspec.version
191 if repos.is_installed(name, version) then 200 if repos.is_installed(name, version) then
192 repos.delete_version(name, version) 201 repos.delete_version(name, version)
193 end 202 end
@@ -341,9 +350,10 @@ end
341-- @param deps_mode: string: Which trees to check dependencies for: 350-- @param deps_mode: string: Which trees to check dependencies for:
342-- "one" for the current default tree, "all" for all trees, 351-- "one" for the current default tree, "all" for all trees,
343-- "order" for all trees with priority >= the current default, "none" for no trees. 352-- "order" for all trees with priority >= the current default, "none" for no trees.
353-- @param build_only_deps boolean: true to build the listed dependencies only.
344-- @return boolean or (nil, string, [string]): True if build was successful, 354-- @return boolean or (nil, string, [string]): True if build was successful,
345-- or false and an error message and an optional error code. 355-- or false and an error message and an optional error code.
346function build.build_rock(rock_file, need_to_fetch, deps_mode) 356function build.build_rock(rock_file, need_to_fetch, deps_mode, build_only_deps)
347 assert(type(rock_file) == "string") 357 assert(type(rock_file) == "string")
348 assert(type(need_to_fetch) == "boolean") 358 assert(type(need_to_fetch) == "boolean")
349 359
@@ -356,24 +366,25 @@ function build.build_rock(rock_file, need_to_fetch, deps_mode)
356 local rockspec_file = path.rockspec_name_from_rock(rock_file) 366 local rockspec_file = path.rockspec_name_from_rock(rock_file)
357 ok, err = fs.change_dir(unpack_dir) 367 ok, err = fs.change_dir(unpack_dir)
358 if not ok then return nil, err end 368 if not ok then return nil, err end
359 ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) 369 ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode, build_only_deps)
360 fs.pop_dir() 370 fs.pop_dir()
361 return ok, err, errcode 371 return ok, err, errcode
362end 372end
363 373
364local function do_build(name, version, deps_mode) 374local function do_build(name, version, deps_mode, build_only_deps)
365 if name:match("%.rockspec$") then 375 if name:match("%.rockspec$") then
366 return build.build_rockspec(name, true, false, deps_mode) 376 return build.build_rockspec(name, true, false, deps_mode, build_only_deps)
367 elseif name:match("%.src%.rock$") then 377 elseif name:match("%.src%.rock$") then
368 return build.build_rock(name, false, deps_mode) 378 return build.build_rock(name, false, deps_mode, build_only_deps)
369 elseif name:match("%.all%.rock$") then 379 elseif name:match("%.all%.rock$") then
370 local install = require("luarocks.install") 380 local install = require("luarocks.install")
371 return install.install_binary_rock(name, deps_mode) 381 local install_fun = build_only_deps and install.install_binary_rock_deps or install.install_binary_rock
382 return install_fun(name, deps_mode)
372 elseif name:match("%.rock$") then 383 elseif name:match("%.rock$") then
373 return build.build_rock(name, true, deps_mode) 384 return build.build_rock(name, true, deps_mode, build_only_deps)
374 elseif not name:match(dir.separator) then 385 elseif not name:match(dir.separator) then
375 local search = require("luarocks.search") 386 local search = require("luarocks.search")
376 return search.act_on_src_or_rockspec(build.run, name:lower(), version, deps.deps_mode_to_flag(deps_mode)) 387 return search.act_on_src_or_rockspec(build.run, name:lower(), version, deps.deps_mode_to_flag(deps_mode), build_only_deps and "--only-deps")
377 end 388 end
378 return nil, "Don't know what to do with "..name 389 return nil, "Don't know what to do with "..name
379end 390end
@@ -398,9 +409,12 @@ function build.run(...)
398 else 409 else
399 local ok, err = fs.check_command_permissions(flags) 410 local ok, err = fs.check_command_permissions(flags)
400 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end 411 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
401 ok, err = do_build(name, version, deps.get_deps_mode(flags)) 412 ok, err = do_build(name, version, deps.get_deps_mode(flags), flags["only-deps"])
402 if not ok then return nil, err end 413 if not ok then return nil, err end
403 local name, version = ok, err 414 local name, version = ok, err
415 if flags["only-deps"] then
416 return name, version
417 end
404 if (not flags["keep"]) and not cfg.keep_other_versions then 418 if (not flags["keep"]) and not cfg.keep_other_versions then
405 local ok, err = remove.remove_other_versions(name, version, flags["force"]) 419 local ok, err = remove.remove_other_versions(name, version, flags["force"])
406 if not ok then util.printerr(err) end 420 if not ok then util.printerr(err) end
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 7678c0cc..6d457fc2 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -26,6 +26,8 @@ or a filename of a locally available rock.
26 rock after installing a new one. This behavior can 26 rock after installing a new one. This behavior can
27 be made permanent by setting keep_other_versions=true 27 be made permanent by setting keep_other_versions=true
28 in the configuration file. 28 in the configuration file.
29
30--only-deps Installs only the dependencies of the rock.
29]]..util.deps_mode_help() 31]]..util.deps_mode_help()
30 32
31 33
@@ -109,6 +111,43 @@ function install.install_binary_rock(rock_file, deps_mode)
109 return name, version 111 return name, version
110end 112end
111 113
114--- Installs the dependencies of a binary rock.
115-- @param rock_file string: local or remote filename of a rock.
116-- @param deps_mode: string: Which trees to check dependencies for:
117-- "one" for the current default tree, "all" for all trees,
118-- "order" for all trees with priority >= the current default, "none" for no trees.
119-- @return (string, string) or (nil, string, [string]): Name and version of
120-- the rock whose dependencies were installed if succeeded or nil and an error message
121-- followed by an error code.
122function install.install_binary_rock_deps(rock_file, deps_mode)
123 assert(type(rock_file) == "string")
124
125 local name, version, arch = path.parse_name(rock_file)
126 if not name then
127 return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'."
128 end
129
130 if arch ~= "all" and arch ~= cfg.arch then
131 return nil, "Incompatible architecture "..arch, "arch"
132 end
133
134 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, path.install_dir(name, version))
135 if not ok then return nil, err, errcode end
136
137 local rockspec, err, errcode = fetch.load_rockspec(path.rockspec_file(name, version))
138 if err then
139 return nil, "Failed loading rockspec for installed package: "..err, errcode
140 end
141
142 ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode)
143 if err then return nil, err, errcode end
144
145 util.printout()
146 util.printout("Succesfully installed dependencies for " ..name.." "..version)
147
148 return name, version
149end
150
112--- Driver function for the "install" command. 151--- Driver function for the "install" command.
113-- @param name string: name of a binary rock. If an URL or pathname 152-- @param name string: name of a binary rock. If an URL or pathname
114-- to a binary rock is given, fetches and installs it. If a rockspec or a 153-- to a binary rock is given, fetches and installs it. If a rockspec or a
@@ -131,12 +170,16 @@ function install.run(...)
131 if name:match("%.rockspec$") or name:match("%.src%.rock$") then 170 if name:match("%.rockspec$") or name:match("%.src%.rock$") then
132 util.printout("Using "..name.."... switching to 'build' mode") 171 util.printout("Using "..name.."... switching to 'build' mode")
133 local build = require("luarocks.build") 172 local build = require("luarocks.build")
134 return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode")) 173 return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode", "only-deps"))
135 elseif name:match("%.rock$") then 174 elseif name:match("%.rock$") then
136 ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags)) 175 if flags["only-deps"] then
176 ok, err = install.install_binary_rock_deps(name, deps.get_deps_mode(flags))
177 else
178 ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags))
179 end
137 if not ok then return nil, err end 180 if not ok then return nil, err end
138 local name, version = ok, err 181 local name, version = ok, err
139 if (not flags["keep"]) and not cfg.keep_other_versions then 182 if (not flags["only-deps"]) and (not flags["keep"]) and not cfg.keep_other_versions then
140 local ok, err = remove.remove_other_versions(name, version, flags["force"]) 183 local ok, err = remove.remove_other_versions(name, version, flags["force"])
141 if not ok then util.printerr(err) end 184 if not ok then util.printerr(err) end
142 end 185 end
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 366a7ace..682c99e9 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -102,6 +102,7 @@ local supported_flags = {
102 ["no-refresh"] = true, 102 ["no-refresh"] = true,
103 ["nodeps"] = true, 103 ["nodeps"] = true,
104 ["old-versions"] = true, 104 ["old-versions"] = true,
105 ["only-deps"] = true,
105 ["only-from"] = "<server>", 106 ["only-from"] = "<server>",
106 ["only-server"] = "<server>", 107 ["only-server"] = "<server>",
107 ["only-sources"] = "<url>", 108 ["only-sources"] = "<url>",
diff --git a/test/testing.lua b/test/testing.lua
index 376d6e9a..86f3ab34 100644
--- a/test/testing.lua
+++ b/test/testing.lua
@@ -140,6 +140,18 @@ local tests = {
140 and rm "./validate-args-${verrev_validate_args}.rockspec" 140 and rm "./validate-args-${verrev_validate_args}.rockspec"
141 end, 141 end,
142 test_build_supported_platforms = function() return run "$luarocks build lpty" end, 142 test_build_supported_platforms = function() return run "$luarocks build lpty" end,
143 test_build_only_deps_rockspec = function()
144 return run "$luarocks download --rockspec lxsh ${verrev_lxsh}"
145 and run "$luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps"
146 and (not run "$luarocks show lxsh")
147 end,
148 test_build_only_deps_src_rock = function()
149 return run "$luarocks download --source lxsh ${verrev_lxsh}"
150 and run "$luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps"
151 and (not run "$luarocks show lxsh")
152 end,
153 test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and (not run "$luarocks show luasec") end,
154 test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and (not run "$luarocks show lxsh") end,
143 fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end, 155 fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end,
144 fail_build_invalidpatch = function() 156 fail_build_invalidpatch = function()
145 need_luasocket() 157 need_luasocket()
diff --git a/test/testing.sh b/test/testing.sh
index b75b51d7..0fa6fe92 100755
--- a/test/testing.sh
+++ b/test/testing.sh
@@ -249,6 +249,7 @@ mkdir -p "$testing_server"
249 get "$luarocks_repo/cprint-${verrev_cprint}.rockspec" 249 get "$luarocks_repo/cprint-${verrev_cprint}.rockspec"
250 get "$luarocks_repo/wsapi-1.6-1.src.rock" 250 get "$luarocks_repo/wsapi-1.6-1.src.rock"
251 get "$luarocks_repo/lxsh-${verrev_lxsh}.src.rock" 251 get "$luarocks_repo/lxsh-${verrev_lxsh}.src.rock"
252 get "$luarocks_repo/lxsh-${verrev_lxsh}.rockspec"
252 get "$luarocks_repo/abelhas-${verrev_abelhas}.rockspec" 253 get "$luarocks_repo/abelhas-${verrev_abelhas}.rockspec"
253 get "$luarocks_repo/lzlib-0.4.1.53-1.src.rock" 254 get "$luarocks_repo/lzlib-0.4.1.53-1.src.rock"
254 get "$luarocks_repo/lpeg-0.12-1.src.rock" 255 get "$luarocks_repo/lpeg-0.12-1.src.rock"
@@ -385,6 +386,10 @@ test_build_install_bin() { $luarocks build luarepl; }
385test_build_nohttps() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks build ./validate-args-${version_validate_args}-1.rockspec && rm ./validate-args-${version_validate_args}-1.rockspec; } 386test_build_nohttps() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks build ./validate-args-${version_validate_args}-1.rockspec && rm ./validate-args-${version_validate_args}-1.rockspec; }
386test_build_https() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks install $luasec && $luarocks build ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; } 387test_build_https() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks install $luasec && $luarocks build ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; }
387test_build_supported_platforms() { $luarocks build lpty; } 388test_build_supported_platforms() { $luarocks build lpty; }
389test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
390test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
391test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; }
392test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
388fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } 393fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; }
389fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } 394fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; }
390 395