diff options
| author | Ignacio Burgueño <ignaciob@inconcertcc.com> | 2015-04-14 12:34:54 -0300 |
|---|---|---|
| committer | Ignacio Burgueño <ignaciob@inconcertcc.com> | 2015-04-14 12:34:54 -0300 |
| commit | 6b350de4daaccba8b142c5db0d8fb8fabaa1649b (patch) | |
| tree | 31afb5a925cbc5990c5aa7a05cc84d0825afad70 | |
| parent | 0f67be5258e25d8cf68b2a50535e82dd0c757206 (diff) | |
| download | luarocks-6b350de4daaccba8b142c5db0d8fb8fabaa1649b.tar.gz luarocks-6b350de4daaccba8b142c5db0d8fb8fabaa1649b.tar.bz2 luarocks-6b350de4daaccba8b142c5db0d8fb8fabaa1649b.zip | |
Adds --only-deps flag to install command
Introduces new function in 'install' module to only install
the dependencies of a rock.
Also adds the tests to the wip Lua test driver.
| -rw-r--r-- | src/luarocks/build.lua | 3 | ||||
| -rw-r--r-- | src/luarocks/install.lua | 49 | ||||
| -rw-r--r-- | test/testing.lua | 12 | ||||
| -rwxr-xr-x | test/testing.sh | 22 |
4 files changed, 64 insertions, 22 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 70a53e14..977be344 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -378,7 +378,8 @@ local function do_build(name, version, deps_mode, build_only_deps) | |||
| 378 | return build.build_rock(name, false, deps_mode, build_only_deps) | 378 | return build.build_rock(name, false, deps_mode, build_only_deps) |
| 379 | elseif name:match("%.all%.rock$") then | 379 | elseif name:match("%.all%.rock$") then |
| 380 | local install = require("luarocks.install") | 380 | local install = require("luarocks.install") |
| 381 | 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) | ||
| 382 | elseif name:match("%.rock$") then | 383 | elseif name:match("%.rock$") then |
| 383 | return build.build_rock(name, true, deps_mode, build_only_deps) | 384 | return build.build_rock(name, true, deps_mode, build_only_deps) |
| 384 | elseif not name:match(dir.separator) then | 385 | elseif not name:match(dir.separator) then |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 7678c0cc..415186ba 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 |
| 110 | end | 112 | end |
| 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. | ||
| 122 | function 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 nstalling dependencies for " ..name.." "..version) | ||
| 147 | |||
| 148 | return name, version | ||
| 149 | end | ||
| 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/test/testing.lua b/test/testing.lua index 376d6e9a..45ee941a 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 run "$luarocks show lxsh; [ $? -ne 0 ]; };" | ||
| 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 run "$luarocks show lxsh; [ $? -ne 0 ]; };" | ||
| 152 | end, | ||
| 153 | test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and run "$luarocks show luasec; [ $? -ne 0 ]; };" end, | ||
| 154 | test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and run "$luarocks show lxsh; [ $? -ne 0 ]; };" 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 78e60a76..7f0a4ae0 100755 --- a/test/testing.sh +++ b/test/testing.sh | |||
| @@ -387,24 +387,10 @@ test_build_install_bin() { $luarocks build luarepl; } | |||
| 387 | test_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; } | 387 | test_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; } |
| 388 | test_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; } | 388 | test_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; } |
| 389 | test_build_supported_platforms() { $luarocks build lpty; } | 389 | test_build_supported_platforms() { $luarocks build lpty; } |
| 390 | test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} ; $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps; $luarocks show lxsh; | 390 | test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } |
| 391 | if [ $? -ne 0 ] | 391 | test_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 ]; }; } |
| 392 | then return 0; | 392 | test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; } |
| 393 | fi; | 393 | test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } |
| 394 | return 1; | ||
| 395 | } | ||
| 396 | test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} ; $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps; $luarocks show lxsh; | ||
| 397 | if [ $? -ne 0 ] | ||
| 398 | then return 0; | ||
| 399 | fi; | ||
| 400 | return 1; | ||
| 401 | } | ||
| 402 | test_build_only_deps() { $luarocks build luasec --only-deps; $luarocks show luasec; | ||
| 403 | if [ $? -ne 0 ] | ||
| 404 | then return 0; | ||
| 405 | fi; | ||
| 406 | return 1; | ||
| 407 | } | ||
| 408 | fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } | 394 | fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } |
| 409 | fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } | 395 | fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } |
| 410 | 396 | ||
