From 081a224ea61bf406ba79716cef3f07e44aa15ee4 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 26 Aug 2011 19:59:21 -0300 Subject: Implemented a flag --pack-binary-rock to "luarocks build", that compiles into a sandbox and packs the .rock file, without installing it into any of the configured rocks trees. Closes #15. --- src/luarocks/build.lua | 62 ++++++++++++++++++++++++++++++++----------- src/luarocks/command_line.lua | 14 +++------- src/luarocks/pack.lua | 2 +- src/luarocks/path.lua | 8 ++++++ 4 files changed, 58 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 5ed2406a..1341a9ae 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -14,11 +14,14 @@ local manif = require("luarocks.manif") local cfg = require("luarocks.cfg") help_summary = "Build/compile a rock." -help_arguments = "{|| []}" +help_arguments = "[--pack-binary-rock] {|| []}" help = [[ -Build a rock, compiling its C parts if any. +Build and install a rock, compiling its C parts if any. Argument may be a rockspec file, a source rock file or the name of a rock to be fetched from a repository. + +If --pack-binary-rock is passed, the rock is not installed; +instead, a .rock file with the contents of compilation is produced. ]] --- Install files to a given location. @@ -269,6 +272,42 @@ function build_rock(rock_file, need_to_fetch) return ok, err, errcode end +local function do_build(name, version) + if name:match("%.rockspec$") then + return build_rockspec(name, true) + elseif name:match("%.src%.rock$") then + return build_rock(name, false) + elseif name:match("%.all%.rock$") then + local install = require("luarocks.install") + return install.install_binary_rock(name) + elseif name:match("%.rock$") then + return build_rock(name, true) + elseif not name:match(dir.separator) then + local search = require("luarocks.search") + return search.act_on_src_or_rockspec(run, name:lower(), version) + end + return nil, "Don't know what to do with "..name +end + +local function pack_binary_rock(name, version) + local temp_dir = fs.make_temp_dir("luarocks-build-pack-"..dir.base_name(name)) + if not temp_dir then + return nil, "Failed creating temporary directory." + end + util.schedule_function(fs.delete, temp_dir) + + path.use_tree(temp_dir) + local ok, err = do_build(name, version) + if not ok then + return nil, err + end + local rname, rversion = path.parse_name(name) + if not rname then + rname, rversion = name, version + end + return pack.pack_binary_rock(rname, rversion) +end + --- Driver function for "build" command. -- @param name string: A local or remote rockspec or rock file. -- If a package name is given, forwards the request to "search" and, @@ -286,19 +325,10 @@ function run(...) local ok, err = fs.check_command_permissions(flags) if not ok then return nil, err end - - if name:match("%.rockspec$") then - return build_rockspec(name, true) - elseif name:match("%.src%.rock$") then - return build_rock(name, false) - elseif name:match("%.all%.rock$") then - local install = require("luarocks.install") - return install.install_binary_rock(name) - elseif name:match("%.rock$") then - return build_rock(name, true) - elseif not name:match(dir.separator) then - local search = require("luarocks.search") - return search.act_on_src_or_rockspec(run, name:lower(), version) + + if flags["pack-binary-rock"] then + return pack_binary_rock(name, version) + else + return do_build(name, version) end - return nil, "Don't know what to do with "..name end diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index ff8699ff..02793c5a 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -33,14 +33,6 @@ local function is_writable(tree) end end -local function use_tree(tree) - cfg.root_dir = tree - cfg.rocks_dir = path.rocks_dir(tree) - cfg.deploy_bin_dir = path.deploy_bin_dir(tree) - cfg.deploy_lua_dir = path.deploy_lua_dir(tree) - cfg.deploy_lib_dir = path.deploy_lib_dir(tree) -end - --- Main command-line processor. -- Parses input arguments and calls the appropriate driver function -- to execute the action requested on the command-line, forwarding @@ -97,12 +89,12 @@ function run_command(...) die("Argument error: use --to=") end local root_dir = fs.absolute_name(flags["to"]) - use_tree(root_dir) + path.use_tree(root_dir) elseif flags["local"] then - use_tree(cfg.home_tree) + path.use_tree(cfg.home_tree) else local trees = cfg.rocks_trees - use_tree(trees[#trees]) + path.use_tree(trees[#trees]) end if type(cfg.root_dir) == "string" then diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index e22bdc38..b85b7460 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -80,7 +80,7 @@ end -- @param version string or nil: A version number may also be passed. -- @return string or (nil, string): The filename of the resulting -- .src.rock file; or nil and an error message. -local function pack_binary_rock(name, version) +function pack_binary_rock(name, version) assert(type(name) == "string") assert(type(version) == "string" or not version) diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 219164ea..8c795e8b 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -297,6 +297,14 @@ function versioned_name(file, prefix, name, version) return dir.path(prefix, name_version.."-"..rest) end +function use_tree(tree) + cfg.root_dir = tree + cfg.rocks_dir = rocks_dir(tree) + cfg.deploy_bin_dir = deploy_bin_dir(tree) + cfg.deploy_lua_dir = deploy_lua_dir(tree) + cfg.deploy_lib_dir = deploy_lib_dir(tree) +end + --- Driver function for "path" command. -- @return boolean This function always succeeds. function run(...) -- cgit v1.2.3-55-g6feb