From 90e5f9a67023cde3ed745a9a82f662ade82a81c1 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 21 Nov 2011 00:40:42 -0200 Subject: Fix --pack-binary-rock and implement it for 'luarocks make' as well. Closes #51. --- src/luarocks/build.lua | 29 +---------------------------- src/luarocks/cfg.lua | 2 +- src/luarocks/make.lua | 15 +++++++++++++-- src/luarocks/pack.lua | 37 ++++++++++++++++++++++++++++++++----- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 3c7f4405..aa39ac9e 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -291,33 +291,6 @@ local function do_build(name, version) return nil, "Don't know what to do with "..name end -local function pack_binary_rock(name, version) - - -- The --pack-binary-rock option for "luarocks build" basically performs - -- "luarocks build" on a temporary tree and then "luarocks pack". The - -- alternative would require refactoring parts of luarocks.build and - -- luarocks.pack, which would save a few file operations: the idea would be - -- to shave off the final deploy steps from the build phase and the initial - -- collect steps from the pack phase. - - 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, @@ -337,7 +310,7 @@ function run(...) if not ok then return nil, err end if flags["pack-binary-rock"] then - return pack_binary_rock(name, version) + return pack.pack_binary_rock(name, version, do_build, name, version) else return do_build(name, version) end diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 68c13718..bab74e45 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -24,7 +24,7 @@ end _M.site_config = site_config -program_version = "2.0.6" +program_version = "2.0.7" user_agent = "LuaRocks/"..program_version local persist = require("luarocks.persist") diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 4af5a16c..d39dd226 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -9,9 +9,11 @@ local build = require("luarocks.build") local fs = require("luarocks.fs") local util = require("luarocks.util") local cfg = require("luarocks.cfg") +local fetch = require("luarocks.fetch") +local pack = require("luarocks.pack") help_summary = "Compile package in current directory using a rockspec." -help_arguments = "[]" +help_arguments = "[--pack-binary-rock] []" help = [[ Builds sources in the current directory, but unlike "build", it does not fetch sources, etc., assuming everything is @@ -22,6 +24,10 @@ is found, you must specify which to use, through the command-line. This command is useful as a tool for debugging rockspecs. To install rocks, you'll normally want to use the "install" and "build" commands. See the help on those for details. + +If --pack-binary-rock is passed, the rock is not installed; +instead, a .rock file with the contents of compilation is produced +in the current directory. ]] --- Driver function for "make" command. @@ -54,5 +60,10 @@ function run(...) return nil, "Invalid argument: 'make' takes a rockspec as a parameter. See help." end - return build.build_rockspec(rockspec, false, true) + if flags["pack-binary-rock"] then + local rspec, err, errcode = fetch.load_rockspec(rockspec) + return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true) + else + return build.build_rockspec(rockspec, false, true) + end end diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index b85b7460..f7a7ad12 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -80,16 +80,16 @@ 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. -function pack_binary_rock(name, version) +local function do_pack_binary_rock(name, version) assert(type(name) == "string") assert(type(version) == "string" or not version) local query = search.make_query(name, version) query.exact_name = true local results = {} - for _, tree in ipairs(cfg.rocks_trees) do - search.manifest_search(results, path.rocks_dir(tree), query) - end + + search.manifest_search(results, cfg.rocks_dir, query) + if not next(results) then return nil, "'"..name.."' does not seem to be an installed rock." end @@ -149,6 +149,33 @@ function pack_binary_rock(name, version) return rock_file end +function pack_binary_rock(name, version, cmd, ...) + + -- The --pack-binary-rock option for "luarocks build" basically performs + -- "luarocks build" on a temporary tree and then "luarocks pack". The + -- alternative would require refactoring parts of luarocks.build and + -- luarocks.pack, which would save a few file operations: the idea would be + -- to shave off the final deploy steps from the build phase and the initial + -- collect steps from the pack phase. + + 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 = cmd(...) + 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 do_pack_binary_rock(rname, rversion) +end + --- Driver function for the "pack" command. -- @param arg string: may be a rockspec file, for creating a source rock, -- or the name of an installed package, for creating a binary rock. @@ -167,7 +194,7 @@ function run(...) if arg:match(".*%.rockspec") then file, err = pack_source_rock(arg) else - file, err = pack_binary_rock(arg, version) + file, err = do_pack_binary_rock(arg, version) end if err then return nil, err -- cgit v1.2.3-55-g6feb