diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2013-07-02 23:21:15 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-07-02 23:21:15 -0300 |
commit | 8ff6a5b55b199fbb056b0e11cff86d8192cef61e (patch) | |
tree | f5047e7a08938b00df62071cc7d9df2ed485fc46 | |
parent | 12e7f99eddd5c4bfe2e69607b53af186bc10fb02 (diff) | |
download | luarocks-8ff6a5b55b199fbb056b0e11cff86d8192cef61e.tar.gz luarocks-8ff6a5b55b199fbb056b0e11cff86d8192cef61e.tar.bz2 luarocks-8ff6a5b55b199fbb056b0e11cff86d8192cef61e.zip |
Make sure a wrapper script finds modules from its own version.
-rw-r--r-- | src/luarocks/fs/unix.lua | 6 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 6 | ||||
-rw-r--r-- | src/luarocks/repos.lua | 15 |
3 files changed, 16 insertions, 11 deletions
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index cfd20c70..cccbbd33 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -43,9 +43,11 @@ end | |||
43 | --- Create a wrapper to make a script executable from the command-line. | 43 | --- Create a wrapper to make a script executable from the command-line. |
44 | -- @param file string: Pathname of script to be made executable. | 44 | -- @param file string: Pathname of script to be made executable. |
45 | -- @param dest string: Directory where to put the wrapper. | 45 | -- @param dest string: Directory where to put the wrapper. |
46 | -- @param name string: rock name to be used in loader context. | ||
47 | -- @param version string: rock version to be used in loader context. | ||
46 | -- @return boolean or (nil, string): True if succeeded, or nil and | 48 | -- @return boolean or (nil, string): True if succeeded, or nil and |
47 | -- an error message. | 49 | -- an error message. |
48 | function wrap_script(file, dest) | 50 | function wrap_script(file, dest, name, version) |
49 | assert(type(file) == "string") | 51 | assert(type(file) == "string") |
50 | assert(type(dest) == "string") | 52 | assert(type(dest) == "string") |
51 | 53 | ||
@@ -59,7 +61,7 @@ function wrap_script(file, dest) | |||
59 | wrapper:write('LUA_PATH="'..package.path..';$LUA_PATH"\n') | 61 | wrapper:write('LUA_PATH="'..package.path..';$LUA_PATH"\n') |
60 | wrapper:write('LUA_CPATH="'..package.cpath..';$LUA_CPATH"\n') | 62 | wrapper:write('LUA_CPATH="'..package.cpath..';$LUA_CPATH"\n') |
61 | wrapper:write('export LUA_PATH LUA_CPATH\n') | 63 | wrapper:write('export LUA_PATH LUA_CPATH\n') |
62 | wrapper:write('exec "'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader "'..file..'" "$@"\n') | 64 | wrapper:write('exec "'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader -e\'luarocks.loader.add_context([['..name..']],[['..version..']])\' "'..file..'" "$@"\n') |
63 | wrapper:close() | 65 | wrapper:close() |
64 | if fs.chmod(wrapname, "0755") then | 66 | if fs.chmod(wrapname, "0755") then |
65 | return true | 67 | return true |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 2c78d9b6..2b5bb955 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
@@ -52,9 +52,11 @@ end | |||
52 | --- Create a wrapper to make a script executable from the command-line. | 52 | --- Create a wrapper to make a script executable from the command-line. |
53 | -- @param file string: Pathname of script to be made executable. | 53 | -- @param file string: Pathname of script to be made executable. |
54 | -- @param dest string: Directory where to put the wrapper. | 54 | -- @param dest string: Directory where to put the wrapper. |
55 | -- @param name string: rock name to be used in loader context. | ||
56 | -- @param version string: rock version to be used in loader context. | ||
55 | -- @return boolean or (nil, string): True if succeeded, or nil and | 57 | -- @return boolean or (nil, string): True if succeeded, or nil and |
56 | -- an error message. | 58 | -- an error message. |
57 | function wrap_script(file, dest) | 59 | function wrap_script(file, dest, name, version) |
58 | assert(type(file) == "string") | 60 | assert(type(file) == "string") |
59 | assert(type(dest) == "string") | 61 | assert(type(dest) == "string") |
60 | 62 | ||
@@ -69,7 +71,7 @@ function wrap_script(file, dest) | |||
69 | wrapper:write("setlocal\n") | 71 | wrapper:write("setlocal\n") |
70 | wrapper:write('set LUA_PATH='..package.path..";%LUA_PATH%\n") | 72 | wrapper:write('set LUA_PATH='..package.path..";%LUA_PATH%\n") |
71 | wrapper:write('set LUA_CPATH='..package.cpath..";%LUA_CPATH%\n") | 73 | wrapper:write('set LUA_CPATH='..package.cpath..";%LUA_CPATH%\n") |
72 | wrapper:write('"'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader "'..file..'" %*\n') | 74 | wrapper:write('"'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader -e\'luarocks.loader.add_context([['..name..']],[['..version..']])\' "'..file..'" %*\n') |
73 | wrapper:write("endlocal\n") | 75 | wrapper:write("endlocal\n") |
74 | wrapper:close() | 76 | wrapper:close() |
75 | return true | 77 | return true |
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 5e87afe3..b7e64d42 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
@@ -150,7 +150,7 @@ function run_hook(rockspec, hook_name) | |||
150 | return true | 150 | return true |
151 | end | 151 | end |
152 | 152 | ||
153 | local function install_binary(source, target) | 153 | local function install_binary(source, target, name, version) |
154 | assert(type(source) == "string") | 154 | assert(type(source) == "string") |
155 | assert(type(target) == "string") | 155 | assert(type(target) == "string") |
156 | 156 | ||
@@ -160,7 +160,7 @@ local function install_binary(source, target) | |||
160 | file = io.open(source) | 160 | file = io.open(source) |
161 | end | 161 | end |
162 | if match or (file and file:read():match("^#!.*lua.*")) then | 162 | if match or (file and file:read():match("^#!.*lua.*")) then |
163 | ok, err = fs.wrap_script(source, target) | 163 | ok, err = fs.wrap_script(source, target, name, version) |
164 | else | 164 | else |
165 | ok, err = fs.copy_binary(source, target) | 165 | ok, err = fs.copy_binary(source, target) |
166 | end | 166 | end |
@@ -200,7 +200,8 @@ function deploy_files(name, version, wrap_bin_scripts) | |||
200 | assert(type(version) == "string") | 200 | assert(type(version) == "string") |
201 | assert(type(wrap_bin_scripts) == "boolean") | 201 | assert(type(wrap_bin_scripts) == "boolean") |
202 | 202 | ||
203 | local function deploy_file_tree(file_tree, source_dir, deploy_dir, move_fn) | 203 | local function deploy_file_tree(file_tree, path_fn, deploy_dir, move_fn) |
204 | local source_dir = path_fn(name, version) | ||
204 | if not move_fn then | 205 | if not move_fn then |
205 | move_fn = fs.move | 206 | move_fn = fs.move |
206 | end | 207 | end |
@@ -220,7 +221,7 @@ function deploy_files(name, version, wrap_bin_scripts) | |||
220 | end | 221 | end |
221 | end | 222 | end |
222 | fs.make_dir(dir.dir_name(target)) | 223 | fs.make_dir(dir.dir_name(target)) |
223 | ok, err = move_fn(source, target) | 224 | ok, err = move_fn(source, target, name, version) |
224 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) | 225 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) |
225 | if not ok then return nil, err end | 226 | if not ok then return nil, err end |
226 | return true | 227 | return true |
@@ -233,13 +234,13 @@ function deploy_files(name, version, wrap_bin_scripts) | |||
233 | local ok, err = true | 234 | local ok, err = true |
234 | if rock_manifest.bin then | 235 | if rock_manifest.bin then |
235 | local move_bin_fn = wrap_bin_scripts and install_binary or fs.copy_binary | 236 | local move_bin_fn = wrap_bin_scripts and install_binary or fs.copy_binary |
236 | ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir(name, version), cfg.deploy_bin_dir, move_bin_fn) | 237 | ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir, cfg.deploy_bin_dir, move_bin_fn) |
237 | end | 238 | end |
238 | if ok and rock_manifest.lua then | 239 | if ok and rock_manifest.lua then |
239 | ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir(name, version), cfg.deploy_lua_dir) | 240 | ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir, cfg.deploy_lua_dir) |
240 | end | 241 | end |
241 | if ok and rock_manifest.lib then | 242 | if ok and rock_manifest.lib then |
242 | ok, err = deploy_file_tree(rock_manifest.lib, path.lib_dir(name, version), cfg.deploy_lib_dir) | 243 | ok, err = deploy_file_tree(rock_manifest.lib, path.lib_dir, cfg.deploy_lib_dir) |
243 | end | 244 | end |
244 | return ok, err | 245 | return ok, err |
245 | end | 246 | end |