diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2011-08-26 19:59:21 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2011-08-26 19:59:21 -0300 |
| commit | 081a224ea61bf406ba79716cef3f07e44aa15ee4 (patch) | |
| tree | 030070ee72331f07cd63794fa99d462a3a818f23 | |
| parent | c0dc905564c23bf25c8514b127f7eecc2793af10 (diff) | |
| download | luarocks-081a224ea61bf406ba79716cef3f07e44aa15ee4.tar.gz luarocks-081a224ea61bf406ba79716cef3f07e44aa15ee4.tar.bz2 luarocks-081a224ea61bf406ba79716cef3f07e44aa15ee4.zip | |
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.
| -rw-r--r-- | src/luarocks/build.lua | 62 | ||||
| -rw-r--r-- | src/luarocks/command_line.lua | 14 | ||||
| -rw-r--r-- | src/luarocks/pack.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/path.lua | 8 |
4 files changed, 58 insertions, 28 deletions
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") | |||
| 14 | local cfg = require("luarocks.cfg") | 14 | local cfg = require("luarocks.cfg") |
| 15 | 15 | ||
| 16 | help_summary = "Build/compile a rock." | 16 | help_summary = "Build/compile a rock." |
| 17 | help_arguments = "{<rockspec>|<rock>|<name> [<version>]}" | 17 | help_arguments = "[--pack-binary-rock] {<rockspec>|<rock>|<name> [<version>]}" |
| 18 | help = [[ | 18 | help = [[ |
| 19 | Build a rock, compiling its C parts if any. | 19 | Build and install a rock, compiling its C parts if any. |
| 20 | Argument may be a rockspec file, a source rock file | 20 | Argument may be a rockspec file, a source rock file |
| 21 | or the name of a rock to be fetched from a repository. | 21 | or the name of a rock to be fetched from a repository. |
| 22 | |||
| 23 | If --pack-binary-rock is passed, the rock is not installed; | ||
| 24 | instead, a .rock file with the contents of compilation is produced. | ||
| 22 | ]] | 25 | ]] |
| 23 | 26 | ||
| 24 | --- Install files to a given location. | 27 | --- Install files to a given location. |
| @@ -269,6 +272,42 @@ function build_rock(rock_file, need_to_fetch) | |||
| 269 | return ok, err, errcode | 272 | return ok, err, errcode |
| 270 | end | 273 | end |
| 271 | 274 | ||
| 275 | local function do_build(name, version) | ||
| 276 | if name:match("%.rockspec$") then | ||
| 277 | return build_rockspec(name, true) | ||
| 278 | elseif name:match("%.src%.rock$") then | ||
| 279 | return build_rock(name, false) | ||
| 280 | elseif name:match("%.all%.rock$") then | ||
| 281 | local install = require("luarocks.install") | ||
| 282 | return install.install_binary_rock(name) | ||
| 283 | elseif name:match("%.rock$") then | ||
| 284 | return build_rock(name, true) | ||
| 285 | elseif not name:match(dir.separator) then | ||
| 286 | local search = require("luarocks.search") | ||
| 287 | return search.act_on_src_or_rockspec(run, name:lower(), version) | ||
| 288 | end | ||
| 289 | return nil, "Don't know what to do with "..name | ||
| 290 | end | ||
| 291 | |||
| 292 | local function pack_binary_rock(name, version) | ||
| 293 | local temp_dir = fs.make_temp_dir("luarocks-build-pack-"..dir.base_name(name)) | ||
| 294 | if not temp_dir then | ||
| 295 | return nil, "Failed creating temporary directory." | ||
| 296 | end | ||
| 297 | util.schedule_function(fs.delete, temp_dir) | ||
| 298 | |||
| 299 | path.use_tree(temp_dir) | ||
| 300 | local ok, err = do_build(name, version) | ||
| 301 | if not ok then | ||
| 302 | return nil, err | ||
| 303 | end | ||
| 304 | local rname, rversion = path.parse_name(name) | ||
| 305 | if not rname then | ||
| 306 | rname, rversion = name, version | ||
| 307 | end | ||
| 308 | return pack.pack_binary_rock(rname, rversion) | ||
| 309 | end | ||
| 310 | |||
| 272 | --- Driver function for "build" command. | 311 | --- Driver function for "build" command. |
| 273 | -- @param name string: A local or remote rockspec or rock file. | 312 | -- @param name string: A local or remote rockspec or rock file. |
| 274 | -- If a package name is given, forwards the request to "search" and, | 313 | -- If a package name is given, forwards the request to "search" and, |
| @@ -286,19 +325,10 @@ function run(...) | |||
| 286 | 325 | ||
| 287 | local ok, err = fs.check_command_permissions(flags) | 326 | local ok, err = fs.check_command_permissions(flags) |
| 288 | if not ok then return nil, err end | 327 | if not ok then return nil, err end |
| 289 | 328 | ||
| 290 | if name:match("%.rockspec$") then | 329 | if flags["pack-binary-rock"] then |
| 291 | return build_rockspec(name, true) | 330 | return pack_binary_rock(name, version) |
| 292 | elseif name:match("%.src%.rock$") then | 331 | else |
| 293 | return build_rock(name, false) | 332 | return do_build(name, version) |
| 294 | elseif name:match("%.all%.rock$") then | ||
| 295 | local install = require("luarocks.install") | ||
| 296 | return install.install_binary_rock(name) | ||
| 297 | elseif name:match("%.rock$") then | ||
| 298 | return build_rock(name, true) | ||
| 299 | elseif not name:match(dir.separator) then | ||
| 300 | local search = require("luarocks.search") | ||
| 301 | return search.act_on_src_or_rockspec(run, name:lower(), version) | ||
| 302 | end | 333 | end |
| 303 | return nil, "Don't know what to do with "..name | ||
| 304 | end | 334 | 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) | |||
| 33 | end | 33 | end |
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | local function use_tree(tree) | ||
| 37 | cfg.root_dir = tree | ||
| 38 | cfg.rocks_dir = path.rocks_dir(tree) | ||
| 39 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | ||
| 40 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | ||
| 41 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | ||
| 42 | end | ||
| 43 | |||
| 44 | --- Main command-line processor. | 36 | --- Main command-line processor. |
| 45 | -- Parses input arguments and calls the appropriate driver function | 37 | -- Parses input arguments and calls the appropriate driver function |
| 46 | -- to execute the action requested on the command-line, forwarding | 38 | -- to execute the action requested on the command-line, forwarding |
| @@ -97,12 +89,12 @@ function run_command(...) | |||
| 97 | die("Argument error: use --to=<path>") | 89 | die("Argument error: use --to=<path>") |
| 98 | end | 90 | end |
| 99 | local root_dir = fs.absolute_name(flags["to"]) | 91 | local root_dir = fs.absolute_name(flags["to"]) |
| 100 | use_tree(root_dir) | 92 | path.use_tree(root_dir) |
| 101 | elseif flags["local"] then | 93 | elseif flags["local"] then |
| 102 | use_tree(cfg.home_tree) | 94 | path.use_tree(cfg.home_tree) |
| 103 | else | 95 | else |
| 104 | local trees = cfg.rocks_trees | 96 | local trees = cfg.rocks_trees |
| 105 | use_tree(trees[#trees]) | 97 | path.use_tree(trees[#trees]) |
| 106 | end | 98 | end |
| 107 | 99 | ||
| 108 | if type(cfg.root_dir) == "string" then | 100 | 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 | |||
| 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 | local function pack_binary_rock(name, version) | 83 | function 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 | ||
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) | |||
| 297 | return dir.path(prefix, name_version.."-"..rest) | 297 | return dir.path(prefix, name_version.."-"..rest) |
| 298 | end | 298 | end |
| 299 | 299 | ||
| 300 | function use_tree(tree) | ||
| 301 | cfg.root_dir = tree | ||
| 302 | cfg.rocks_dir = rocks_dir(tree) | ||
| 303 | cfg.deploy_bin_dir = deploy_bin_dir(tree) | ||
| 304 | cfg.deploy_lua_dir = deploy_lua_dir(tree) | ||
| 305 | cfg.deploy_lib_dir = deploy_lib_dir(tree) | ||
| 306 | end | ||
| 307 | |||
| 300 | --- Driver function for "path" command. | 308 | --- Driver function for "path" command. |
| 301 | -- @return boolean This function always succeeds. | 309 | -- @return boolean This function always succeeds. |
| 302 | function run(...) | 310 | function run(...) |
