diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2011-11-21 00:40:42 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2011-11-21 00:40:42 -0200 |
commit | 90e5f9a67023cde3ed745a9a82f662ade82a81c1 (patch) | |
tree | d475af94bc53a8ba050023fb9b769120b79583e7 | |
parent | 9a29f682dcd6ed9d451a7ae16023cad285dcb9ab (diff) | |
download | luarocks-90e5f9a67023cde3ed745a9a82f662ade82a81c1.tar.gz luarocks-90e5f9a67023cde3ed745a9a82f662ade82a81c1.tar.bz2 luarocks-90e5f9a67023cde3ed745a9a82f662ade82a81c1.zip |
Fix --pack-binary-rock and implement it for 'luarocks make' as well. Closes #51.
-rw-r--r-- | src/luarocks/build.lua | 29 | ||||
-rw-r--r-- | src/luarocks/cfg.lua | 2 | ||||
-rw-r--r-- | src/luarocks/make.lua | 15 | ||||
-rw-r--r-- | 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) | |||
291 | return nil, "Don't know what to do with "..name | 291 | return nil, "Don't know what to do with "..name |
292 | end | 292 | end |
293 | 293 | ||
294 | local function pack_binary_rock(name, version) | ||
295 | |||
296 | -- The --pack-binary-rock option for "luarocks build" basically performs | ||
297 | -- "luarocks build" on a temporary tree and then "luarocks pack". The | ||
298 | -- alternative would require refactoring parts of luarocks.build and | ||
299 | -- luarocks.pack, which would save a few file operations: the idea would be | ||
300 | -- to shave off the final deploy steps from the build phase and the initial | ||
301 | -- collect steps from the pack phase. | ||
302 | |||
303 | local temp_dir = fs.make_temp_dir("luarocks-build-pack-"..dir.base_name(name)) | ||
304 | if not temp_dir then | ||
305 | return nil, "Failed creating temporary directory." | ||
306 | end | ||
307 | util.schedule_function(fs.delete, temp_dir) | ||
308 | |||
309 | path.use_tree(temp_dir) | ||
310 | local ok, err = do_build(name, version) | ||
311 | if not ok then | ||
312 | return nil, err | ||
313 | end | ||
314 | local rname, rversion = path.parse_name(name) | ||
315 | if not rname then | ||
316 | rname, rversion = name, version | ||
317 | end | ||
318 | return pack.pack_binary_rock(rname, rversion) | ||
319 | end | ||
320 | |||
321 | --- Driver function for "build" command. | 294 | --- Driver function for "build" command. |
322 | -- @param name string: A local or remote rockspec or rock file. | 295 | -- @param name string: A local or remote rockspec or rock file. |
323 | -- If a package name is given, forwards the request to "search" and, | 296 | -- If a package name is given, forwards the request to "search" and, |
@@ -337,7 +310,7 @@ function run(...) | |||
337 | if not ok then return nil, err end | 310 | if not ok then return nil, err end |
338 | 311 | ||
339 | if flags["pack-binary-rock"] then | 312 | if flags["pack-binary-rock"] then |
340 | return pack_binary_rock(name, version) | 313 | return pack.pack_binary_rock(name, version, do_build, name, version) |
341 | else | 314 | else |
342 | return do_build(name, version) | 315 | return do_build(name, version) |
343 | end | 316 | 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 | |||
24 | 24 | ||
25 | _M.site_config = site_config | 25 | _M.site_config = site_config |
26 | 26 | ||
27 | program_version = "2.0.6" | 27 | program_version = "2.0.7" |
28 | user_agent = "LuaRocks/"..program_version | 28 | user_agent = "LuaRocks/"..program_version |
29 | 29 | ||
30 | local persist = require("luarocks.persist") | 30 | 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") | |||
9 | local fs = require("luarocks.fs") | 9 | local fs = require("luarocks.fs") |
10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
11 | local cfg = require("luarocks.cfg") | 11 | local cfg = require("luarocks.cfg") |
12 | local fetch = require("luarocks.fetch") | ||
13 | local pack = require("luarocks.pack") | ||
12 | 14 | ||
13 | help_summary = "Compile package in current directory using a rockspec." | 15 | help_summary = "Compile package in current directory using a rockspec." |
14 | help_arguments = "[<rockspec>]" | 16 | help_arguments = "[--pack-binary-rock] [<rockspec>]" |
15 | help = [[ | 17 | help = [[ |
16 | Builds sources in the current directory, but unlike "build", | 18 | Builds sources in the current directory, but unlike "build", |
17 | it does not fetch sources, etc., assuming everything is | 19 | 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. | |||
22 | This command is useful as a tool for debugging rockspecs. | 24 | This command is useful as a tool for debugging rockspecs. |
23 | To install rocks, you'll normally want to use the "install" and | 25 | To install rocks, you'll normally want to use the "install" and |
24 | "build" commands. See the help on those for details. | 26 | "build" commands. See the help on those for details. |
27 | |||
28 | If --pack-binary-rock is passed, the rock is not installed; | ||
29 | instead, a .rock file with the contents of compilation is produced | ||
30 | in the current directory. | ||
25 | ]] | 31 | ]] |
26 | 32 | ||
27 | --- Driver function for "make" command. | 33 | --- Driver function for "make" command. |
@@ -54,5 +60,10 @@ function run(...) | |||
54 | return nil, "Invalid argument: 'make' takes a rockspec as a parameter. See help." | 60 | return nil, "Invalid argument: 'make' takes a rockspec as a parameter. See help." |
55 | end | 61 | end |
56 | 62 | ||
57 | return build.build_rockspec(rockspec, false, true) | 63 | if flags["pack-binary-rock"] then |
64 | local rspec, err, errcode = fetch.load_rockspec(rockspec) | ||
65 | return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true) | ||
66 | else | ||
67 | return build.build_rockspec(rockspec, false, true) | ||
68 | end | ||
58 | end | 69 | 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 | |||
80 | -- @param version string or nil: A version number may also be passed. | 80 | -- @param version string or nil: A version number may also be passed. |
81 | -- @return string or (nil, string): The filename of the resulting | 81 | -- @return string or (nil, string): The filename of the resulting |
82 | -- .src.rock file; or nil and an error message. | 82 | -- .src.rock file; or nil and an error message. |
83 | function pack_binary_rock(name, version) | 83 | local function do_pack_binary_rock(name, version) |
84 | assert(type(name) == "string") | 84 | assert(type(name) == "string") |
85 | assert(type(version) == "string" or not version) | 85 | assert(type(version) == "string" or not version) |
86 | 86 | ||
87 | local query = search.make_query(name, version) | 87 | local query = search.make_query(name, version) |
88 | query.exact_name = true | 88 | query.exact_name = true |
89 | local results = {} | 89 | local results = {} |
90 | for _, tree in ipairs(cfg.rocks_trees) do | 90 | |
91 | search.manifest_search(results, path.rocks_dir(tree), query) | 91 | search.manifest_search(results, cfg.rocks_dir, query) |
92 | end | 92 | |
93 | if not next(results) then | 93 | if not next(results) then |
94 | return nil, "'"..name.."' does not seem to be an installed rock." | 94 | return nil, "'"..name.."' does not seem to be an installed rock." |
95 | end | 95 | end |
@@ -149,6 +149,33 @@ function pack_binary_rock(name, version) | |||
149 | return rock_file | 149 | return rock_file |
150 | end | 150 | end |
151 | 151 | ||
152 | function pack_binary_rock(name, version, cmd, ...) | ||
153 | |||
154 | -- The --pack-binary-rock option for "luarocks build" basically performs | ||
155 | -- "luarocks build" on a temporary tree and then "luarocks pack". The | ||
156 | -- alternative would require refactoring parts of luarocks.build and | ||
157 | -- luarocks.pack, which would save a few file operations: the idea would be | ||
158 | -- to shave off the final deploy steps from the build phase and the initial | ||
159 | -- collect steps from the pack phase. | ||
160 | |||
161 | local temp_dir = fs.make_temp_dir("luarocks-build-pack-"..dir.base_name(name)) | ||
162 | if not temp_dir then | ||
163 | return nil, "Failed creating temporary directory." | ||
164 | end | ||
165 | util.schedule_function(fs.delete, temp_dir) | ||
166 | |||
167 | path.use_tree(temp_dir) | ||
168 | local ok, err = cmd(...) | ||
169 | if not ok then | ||
170 | return nil, err | ||
171 | end | ||
172 | local rname, rversion = path.parse_name(name) | ||
173 | if not rname then | ||
174 | rname, rversion = name, version | ||
175 | end | ||
176 | return do_pack_binary_rock(rname, rversion) | ||
177 | end | ||
178 | |||
152 | --- Driver function for the "pack" command. | 179 | --- Driver function for the "pack" command. |
153 | -- @param arg string: may be a rockspec file, for creating a source rock, | 180 | -- @param arg string: may be a rockspec file, for creating a source rock, |
154 | -- or the name of an installed package, for creating a binary rock. | 181 | -- or the name of an installed package, for creating a binary rock. |
@@ -167,7 +194,7 @@ function run(...) | |||
167 | if arg:match(".*%.rockspec") then | 194 | if arg:match(".*%.rockspec") then |
168 | file, err = pack_source_rock(arg) | 195 | file, err = pack_source_rock(arg) |
169 | else | 196 | else |
170 | file, err = pack_binary_rock(arg, version) | 197 | file, err = do_pack_binary_rock(arg, version) |
171 | end | 198 | end |
172 | if err then | 199 | if err then |
173 | return nil, err | 200 | return nil, err |