diff options
| author | Hisham Muhammad <hisham@NewMachine.localdomain> | 2010-08-30 11:08:46 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@NewMachine.localdomain> | 2010-08-30 11:08:46 -0300 |
| commit | 9b0d029971da9863194ede96a835302564d1e4a7 (patch) | |
| tree | 15f06e59c31ad6685bcc6bae7dca539847639317 /src | |
| parent | ca3d0e48c44fafafc5dff8f27a9a5ac5da090050 (diff) | |
| download | luarocks-9b0d029971da9863194ede96a835302564d1e4a7.tar.gz luarocks-9b0d029971da9863194ede96a835302564d1e4a7.tar.bz2 luarocks-9b0d029971da9863194ede96a835302564d1e4a7.zip | |
Add 'luarocks path' command for easy configuration of LUA_PATH and LUA_CPATH
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/build/builtin.lua | 19 | ||||
| -rw-r--r-- | src/luarocks/cfg.lua | 17 | ||||
| -rw-r--r-- | src/luarocks/path.lua | 22 |
3 files changed, 39 insertions, 19 deletions
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 3473abcb..7c24340e 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
| @@ -8,19 +8,6 @@ local util = require("luarocks.util") | |||
| 8 | local cfg = require("luarocks.cfg") | 8 | local cfg = require("luarocks.cfg") |
| 9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
| 10 | 10 | ||
| 11 | --- Check if platform was detected | ||
| 12 | -- @param query string: The platform name to check. | ||
| 13 | -- @return boolean: true if LuaRocks is currently running on queried platform. | ||
| 14 | local function is_platform(query) | ||
| 15 | assert(type(query) == "string") | ||
| 16 | |||
| 17 | for _, platform in ipairs(cfg.platforms) do | ||
| 18 | if platform == query then | ||
| 19 | return true | ||
| 20 | end | ||
| 21 | end | ||
| 22 | end | ||
| 23 | |||
| 24 | --- Run a command displaying its execution on standard output. | 11 | --- Run a command displaying its execution on standard output. |
| 25 | -- @return boolean: true if command succeeds (status code 0), false | 12 | -- @return boolean: true if command succeeds (status code 0), false |
| 26 | -- otherwise. | 13 | -- otherwise. |
| @@ -76,7 +63,7 @@ function run(rockspec) | |||
| 76 | end | 63 | end |
| 77 | end | 64 | end |
| 78 | 65 | ||
| 79 | if is_platform("mingw32") then | 66 | if cfg.is_platform("mingw32") then |
| 80 | compile_object = function(object, source, defines, incdirs) | 67 | compile_object = function(object, source, defines, incdirs) |
| 81 | local extras = {} | 68 | local extras = {} |
| 82 | add_flags(extras, "-D%s", defines) | 69 | add_flags(extras, "-D%s", defines) |
| @@ -105,7 +92,7 @@ function run(rockspec) | |||
| 105 | dir.path(variables.LUA_LIBDIR, "lua5.1.lib"), "-l" .. (variables.MSVCRT or "msvcr80"), "-luser32") | 92 | dir.path(variables.LUA_LIBDIR, "lua5.1.lib"), "-l" .. (variables.MSVCRT or "msvcr80"), "-luser32") |
| 106 | return ok, wrapname | 93 | return ok, wrapname |
| 107 | end | 94 | end |
| 108 | elseif is_platform("win32") then | 95 | elseif cfg.is_platform("win32") then |
| 109 | compile_object = function(object, source, defines, incdirs) | 96 | compile_object = function(object, source, defines, incdirs) |
| 110 | local extras = {} | 97 | local extras = {} |
| 111 | add_flags(extras, "-D%s", defines) | 98 | add_flags(extras, "-D%s", defines) |
| @@ -157,7 +144,7 @@ function run(rockspec) | |||
| 157 | local extras = { unpack(objects) } | 144 | local extras = { unpack(objects) } |
| 158 | add_flags(extras, "-L%s", libdirs) | 145 | add_flags(extras, "-L%s", libdirs) |
| 159 | add_flags(extras, "-l%s", libraries) | 146 | add_flags(extras, "-l%s", libraries) |
| 160 | if is_platform("cygwin") then | 147 | if cfg.is_platform("cygwin") then |
| 161 | add_flags(extras, "-l%s", {"lua"}) | 148 | add_flags(extras, "-l%s", {"lua"}) |
| 162 | end | 149 | end |
| 163 | return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) | 150 | return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 8706bd60..261411b7 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | ||
| 2 | local rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type = | 2 | local rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type, assert = |
| 3 | rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type | 3 | rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type, assert |
| 4 | 4 | ||
| 5 | --- Configuration for LuaRocks. | 5 | --- Configuration for LuaRocks. |
| 6 | -- Tries to load the user's configuration file and | 6 | -- Tries to load the user's configuration file and |
| @@ -318,7 +318,6 @@ local cfg_mt = { | |||
| 318 | } | 318 | } |
| 319 | setmetatable(_M, cfg_mt) | 319 | setmetatable(_M, cfg_mt) |
| 320 | 320 | ||
| 321 | |||
| 322 | for _,tree in ipairs(rocks_trees) do | 321 | for _,tree in ipairs(rocks_trees) do |
| 323 | if type(tree) == "string" then | 322 | if type(tree) == "string" then |
| 324 | package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path | 323 | package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path |
| @@ -330,3 +329,15 @@ for _,tree in ipairs(rocks_trees) do | |||
| 330 | end | 329 | end |
| 331 | end | 330 | end |
| 332 | 331 | ||
| 332 | --- Check if platform was detected | ||
| 333 | -- @param query string: The platform name to check. | ||
| 334 | -- @return boolean: true if LuaRocks is currently running on queried platform. | ||
| 335 | function is_platform(query) | ||
| 336 | assert(type(query) == "string") | ||
| 337 | |||
| 338 | for _, platform in ipairs(platforms) do | ||
| 339 | if platform == query then | ||
| 340 | return true | ||
| 341 | end | ||
| 342 | end | ||
| 343 | end | ||
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index d07c244e..3ff0db8a 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
| @@ -7,6 +7,14 @@ module("luarocks.path", package.seeall) | |||
| 7 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
| 8 | local cfg = require("luarocks.cfg") | 8 | local cfg = require("luarocks.cfg") |
| 9 | 9 | ||
| 10 | help_summary = "Return the currently configured package path." | ||
| 11 | help_arguments = "" | ||
| 12 | help = [[ | ||
| 13 | Returns the package path currently configured for this installation | ||
| 14 | of LuaRocks, formatted as shell commands to update LUA_PATH and | ||
| 15 | LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`) | ||
| 16 | ]] | ||
| 17 | |||
| 10 | --- Infer rockspec filename from a rock filename. | 18 | --- Infer rockspec filename from a rock filename. |
| 11 | -- @param rock_name string: Pathname of a rock file. | 19 | -- @param rock_name string: Pathname of a rock file. |
| 12 | -- @return string: Filename of the rockspec, without path. | 20 | -- @return string: Filename of the rockspec, without path. |
| @@ -291,3 +299,17 @@ function versioned_name(file, prefix, name, version) | |||
| 291 | local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") | 299 | local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") |
| 292 | return dir.path(prefix, name_version.."-"..rest) | 300 | return dir.path(prefix, name_version.."-"..rest) |
| 293 | end | 301 | end |
| 302 | |||
| 303 | --- Driver function for "path" command. | ||
| 304 | -- @return boolean This function always succeeds. | ||
| 305 | function run(...) | ||
| 306 | if cfg.is_platform("unix") then | ||
| 307 | print("export LUA_PATH='"..package.path.."'") | ||
| 308 | print("export LUA_CPATH='"..package.cpath.."'") | ||
| 309 | elseif cfg.is_platform("windows") then | ||
| 310 | print("SET LUA_PATH="..package.path) | ||
| 311 | print("SET LUA_CPATH="..package.cpath) | ||
| 312 | end | ||
| 313 | return true | ||
| 314 | end | ||
| 315 | |||
