From c0d6ec090bcfbdc3895809fd914b3724e2742782 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 17 Jul 2013 18:14:18 -0300 Subject: Fix: make sure that --keep flag forwards correctly from 'install' to 'build'. --- src/luarocks/install.lua | 4 ++-- src/luarocks/util.lua | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index e1b44203..c181d612 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -134,7 +134,7 @@ function 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, deps.get_deps_mode(flags), flags["local"] and "--local") + return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode")) elseif name:match("%.rock$") then ok, err = install_binary_rock(name, deps.get_deps_mode(flags)) if not ok then return nil, err end @@ -152,7 +152,7 @@ function run(...) elseif type(results) == "string" then local url = results util.printout("Installing "..url.."...") - return run(url) + return run(url, util.forward_flags(flags)) else util.printout() util.printerr("Could not determine which rock to install.") diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index b2428f62..ba20acfa 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -85,6 +85,38 @@ function parse_flags(...) return flags, unpack(args) end +--- Build a sequence of flags for forwarding from one command to +-- another (for example, from "install" to "build"). +-- @param flags table: A table of parsed flags +-- @param ... string...: A variable number of flags to be checked +-- in the flags table. If no flags are passed as varargs, the +-- entire flags table is forwarded. +-- @return string... A variable number of strings +function forward_flags(flags, ...) + assert(type(flags) == "table") + local out = {} + local filter = select('#', ...) + local function add_flag(flagname) + if flags[flagname] then + if flags[flagname] == true then + table.insert(out, "--"..flagname) + else + table.insert(out, "--"..flagname.."="..flags[flagname]) + end + end + end + if filter > 0 then + for i = 1, filter do + add_flag(select(i, ...)) + end + else + for flagname, _ in pairs(flags) do + add_flag(flagname) + end + end + return unpack(out) +end + --- Merges contents of src on top of dst's contents. -- @param dst Destination table, which will receive src's contents. -- @param src Table which provides new contents to dst. -- cgit v1.2.3-55-g6feb