From 0f67be5258e25d8cf68b2a50535e82dd0c757206 Mon Sep 17 00:00:00 2001 From: Ignacio Burgueño Date: Tue, 14 Apr 2015 02:15:31 -0300 Subject: Adds --only-deps flag to the 'build' command. As discussed in #287, adds a new flag (--only-deps) to the 'build' command, so only the dependencies of a rock are installed, and not the rock itself. --- test/testing.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/testing.sh b/test/testing.sh index b75b51d7..78e60a76 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -249,6 +249,7 @@ mkdir -p "$testing_server" get "$luarocks_repo/cprint-${verrev_cprint}.rockspec" get "$luarocks_repo/wsapi-1.6-1.src.rock" get "$luarocks_repo/lxsh-${verrev_lxsh}.src.rock" + get "$luarocks_repo/lxsh-${verrev_lxsh}.rockspec" get "$luarocks_repo/abelhas-${verrev_abelhas}.rockspec" get "$luarocks_repo/lzlib-0.4.1.53-1.src.rock" get "$luarocks_repo/lpeg-0.12-1.src.rock" @@ -262,6 +263,7 @@ mkdir -p "$testing_server" get "$luarocks_repo/lua-path-0.2.3-1.src.rock" get "$luarocks_repo/lua-cjson-2.1.0-1.src.rock" get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock" + get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock" ) $luarocks_admin_nocov make_manifest "$testing_server" @@ -385,6 +387,24 @@ test_build_install_bin() { $luarocks build luarepl; } 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; } 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; } test_build_supported_platforms() { $luarocks build lpty; } +test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} ; $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps; $luarocks show lxsh; + if [ $? -ne 0 ] + then return 0; + fi; + return 1; +} +test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} ; $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps; $luarocks show lxsh; + if [ $? -ne 0 ] + then return 0; + fi; + return 1; +} +test_build_only_deps() { $luarocks build luasec --only-deps; $luarocks show luasec; + if [ $? -ne 0 ] + then return 0; + fi; + return 1; +} fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } -- cgit v1.2.3-55-g6feb From 6b350de4daaccba8b142c5db0d8fb8fabaa1649b Mon Sep 17 00:00:00 2001 From: Ignacio Burgueño Date: Tue, 14 Apr 2015 12:34:54 -0300 Subject: 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. --- src/luarocks/build.lua | 3 ++- src/luarocks/install.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++--- test/testing.lua | 12 ++++++++++++ test/testing.sh | 22 ++++------------------ 4 files changed, 64 insertions(+), 22 deletions(-) (limited to 'test') 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) return build.build_rock(name, false, deps_mode, build_only_deps) elseif name:match("%.all%.rock$") then local install = require("luarocks.install") - return install.install_binary_rock(name, deps_mode) + local install_fun = build_only_deps and install.install_binary_rock_deps or install.install_binary_rock + return install_fun(name, deps_mode) elseif name:match("%.rock$") then return build.build_rock(name, true, deps_mode, build_only_deps) 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. rock after installing a new one. This behavior can be made permanent by setting keep_other_versions=true in the configuration file. + +--only-deps Installs only the dependencies of the rock. ]]..util.deps_mode_help() @@ -109,6 +111,43 @@ function install.install_binary_rock(rock_file, deps_mode) return name, version end +--- Installs the dependencies of a binary rock. +-- @param rock_file string: local or remote filename of a rock. +-- @param deps_mode: string: Which trees to check dependencies for: +-- "one" for the current default tree, "all" for all trees, +-- "order" for all trees with priority >= the current default, "none" for no trees. +-- @return (string, string) or (nil, string, [string]): Name and version of +-- the rock whose dependencies were installed if succeeded or nil and an error message +-- followed by an error code. +function install.install_binary_rock_deps(rock_file, deps_mode) + assert(type(rock_file) == "string") + + local name, version, arch = path.parse_name(rock_file) + if not name then + return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." + end + + if arch ~= "all" and arch ~= cfg.arch then + return nil, "Incompatible architecture "..arch, "arch" + end + + local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, path.install_dir(name, version)) + if not ok then return nil, err, errcode end + + local rockspec, err, errcode = fetch.load_rockspec(path.rockspec_file(name, version)) + if err then + return nil, "Failed loading rockspec for installed package: "..err, errcode + end + + ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode) + if err then return nil, err, errcode end + + util.printout() + util.printout("Succesfully nstalling dependencies for " ..name.." "..version) + + return name, version +end + --- Driver function for the "install" command. -- @param name string: name of a binary rock. If an URL or pathname -- to a binary rock is given, fetches and installs it. If a rockspec or a @@ -131,12 +170,16 @@ function install.run(...) if name:match("%.rockspec$") or name:match("%.src%.rock$") then util.printout("Using "..name.."... switching to 'build' mode") local build = require("luarocks.build") - return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode")) + return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode", "only-deps")) elseif name:match("%.rock$") then - ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags)) + if flags["only-deps"] then + ok, err = install.install_binary_rock_deps(name, deps.get_deps_mode(flags)) + else + ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags)) + end if not ok then return nil, err end local name, version = ok, err - if (not flags["keep"]) and not cfg.keep_other_versions then + if (not flags["only-deps"]) and (not flags["keep"]) and not cfg.keep_other_versions then local ok, err = remove.remove_other_versions(name, version, flags["force"]) if not ok then util.printerr(err) end 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 = { and rm "./validate-args-${verrev_validate_args}.rockspec" end, test_build_supported_platforms = function() return run "$luarocks build lpty" end, + test_build_only_deps_rockspec = function() + return run "$luarocks download --rockspec lxsh ${verrev_lxsh}" + and run "$luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps" + and run "$luarocks show lxsh; [ $? -ne 0 ]; };" + end, + test_build_only_deps_src_rock = function() + return run "$luarocks download --source lxsh ${verrev_lxsh}" + and run "$luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps" + and run "$luarocks show lxsh; [ $? -ne 0 ]; };" + end, + test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and run "$luarocks show luasec; [ $? -ne 0 ]; };" end, + test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and run "$luarocks show lxsh; [ $? -ne 0 ]; };" end, fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end, fail_build_invalidpatch = function() 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; } 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; } 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; } test_build_supported_platforms() { $luarocks build lpty; } -test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} ; $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps; $luarocks show lxsh; - if [ $? -ne 0 ] - then return 0; - fi; - return 1; -} -test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} ; $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps; $luarocks show lxsh; - if [ $? -ne 0 ] - then return 0; - fi; - return 1; -} -test_build_only_deps() { $luarocks build luasec --only-deps; $luarocks show luasec; - if [ $? -ne 0 ] - then return 0; - fi; - return 1; -} +test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } +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 ]; }; } +test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; } +test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } -- cgit v1.2.3-55-g6feb From 15ad97bb124c800a95ac0d2d46f747e711fd3f8e Mon Sep 17 00:00:00 2001 From: Ignacio Burgueño Date: Tue, 14 Apr 2015 13:06:09 -0300 Subject: Address issues spotted in the review --- src/luarocks/install.lua | 2 +- test/testing.lua | 8 ++++---- test/testing.sh | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 415186ba..6d457fc2 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -143,7 +143,7 @@ function install.install_binary_rock_deps(rock_file, deps_mode) if err then return nil, err, errcode end util.printout() - util.printout("Succesfully nstalling dependencies for " ..name.." "..version) + util.printout("Succesfully installed dependencies for " ..name.." "..version) return name, version end diff --git a/test/testing.lua b/test/testing.lua index 45ee941a..86f3ab34 100644 --- a/test/testing.lua +++ b/test/testing.lua @@ -143,15 +143,15 @@ local tests = { test_build_only_deps_rockspec = function() return run "$luarocks download --rockspec lxsh ${verrev_lxsh}" and run "$luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps" - and run "$luarocks show lxsh; [ $? -ne 0 ]; };" + and (not run "$luarocks show lxsh") end, test_build_only_deps_src_rock = function() return run "$luarocks download --source lxsh ${verrev_lxsh}" and run "$luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps" - and run "$luarocks show lxsh; [ $? -ne 0 ]; };" + and (not run "$luarocks show lxsh") end, - test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and run "$luarocks show luasec; [ $? -ne 0 ]; };" end, - test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and run "$luarocks show lxsh; [ $? -ne 0 ]; };" end, + test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and (not run "$luarocks show luasec") end, + test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and (not run "$luarocks show lxsh") end, fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end, fail_build_invalidpatch = function() need_luasocket() diff --git a/test/testing.sh b/test/testing.sh index 7f0a4ae0..0fa6fe92 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -263,7 +263,6 @@ mkdir -p "$testing_server" get "$luarocks_repo/lua-path-0.2.3-1.src.rock" get "$luarocks_repo/lua-cjson-2.1.0-1.src.rock" get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock" - get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock" ) $luarocks_admin_nocov make_manifest "$testing_server" -- cgit v1.2.3-55-g6feb