diff options
-rw-r--r-- | src/luarocks/fs/unix.lua | 24 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 21 |
2 files changed, 21 insertions, 24 deletions
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 0126dad5..50bfba9c 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -59,24 +59,22 @@ function unix.root_of(_) | |||
59 | end | 59 | end |
60 | 60 | ||
61 | --- Create a wrapper to make a script executable from the command-line. | 61 | --- Create a wrapper to make a script executable from the command-line. |
62 | -- @param file string: Pathname of script to be made executable. | 62 | -- @param script string: Pathname of script to be made executable. |
63 | -- @param dest string: Directory where to put the wrapper. | 63 | -- @param target string: wrapper target pathname (without wrapper suffix). |
64 | -- @param name string: rock name to be used in loader context. | 64 | -- @param name string: rock name to be used in loader context. |
65 | -- @param version string: rock version to be used in loader context. | 65 | -- @param version string: rock version to be used in loader context. |
66 | -- @return boolean or (nil, string): True if succeeded, or nil and | 66 | -- @return boolean or (nil, string): True if succeeded, or nil and |
67 | -- an error message. | 67 | -- an error message. |
68 | function unix.wrap_script(file, dest, deps_mode, name, version, ...) | 68 | function unix.wrap_script(script, target, deps_mode, name, version, ...) |
69 | assert(type(file) == "string" or not file) | 69 | assert(type(script) == "string" or not script) |
70 | assert(type(dest) == "string") | 70 | assert(type(target) == "string") |
71 | assert(type(deps_mode) == "string") | 71 | assert(type(deps_mode) == "string") |
72 | assert(type(name) == "string" or not name) | 72 | assert(type(name) == "string" or not name) |
73 | assert(type(version) == "string" or not version) | 73 | assert(type(version) == "string" or not version) |
74 | 74 | ||
75 | local wrapname = fs.is_dir(dest) and dest.."/"..dir.base_name(file) or dest | 75 | local wrapper = io.open(target, "w") |
76 | |||
77 | local wrapper = io.open(wrapname, "w") | ||
78 | if not wrapper then | 76 | if not wrapper then |
79 | return nil, "Could not open "..wrapname.." for writing." | 77 | return nil, "Could not open "..target.." for writing." |
80 | end | 78 | end |
81 | 79 | ||
82 | local lpath, lcpath = path.package_paths(deps_mode) | 80 | local lpath, lcpath = path.package_paths(deps_mode) |
@@ -85,7 +83,7 @@ function unix.wrap_script(file, dest, deps_mode, name, version, ...) | |||
85 | "package.path="..util.LQ(lpath..";").."..package.path", | 83 | "package.path="..util.LQ(lpath..";").."..package.path", |
86 | "package.cpath="..util.LQ(lcpath..";").."..package.cpath", | 84 | "package.cpath="..util.LQ(lcpath..";").."..package.cpath", |
87 | } | 85 | } |
88 | if dest == "luarocks" or dest == "luarocks-admin" then | 86 | if target == "luarocks" or target == "luarocks-admin" then |
89 | luainit = { | 87 | luainit = { |
90 | "package.path="..util.LQ(package.path), | 88 | "package.path="..util.LQ(package.path), |
91 | "package.cpath="..util.LQ(package.cpath), | 89 | "package.cpath="..util.LQ(package.cpath), |
@@ -99,7 +97,7 @@ function unix.wrap_script(file, dest, deps_mode, name, version, ...) | |||
99 | 97 | ||
100 | local argv = { | 98 | local argv = { |
101 | fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), | 99 | fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), |
102 | file and fs.Q(file) or "", | 100 | script and fs.Q(script) or "", |
103 | ... | 101 | ... |
104 | } | 102 | } |
105 | 103 | ||
@@ -109,10 +107,10 @@ function unix.wrap_script(file, dest, deps_mode, name, version, ...) | |||
109 | wrapper:write("exec "..table.concat(argv, " ")..' "$@"\n') | 107 | wrapper:write("exec "..table.concat(argv, " ")..' "$@"\n') |
110 | wrapper:close() | 108 | wrapper:close() |
111 | 109 | ||
112 | if fs.set_permissions(wrapname, "exec", "all") then | 110 | if fs.set_permissions(target, "exec", "all") then |
113 | return true | 111 | return true |
114 | else | 112 | else |
115 | return nil, "Could not make "..wrapname.." executable." | 113 | return nil, "Could not make "..target.." executable." |
116 | end | 114 | end |
117 | end | 115 | end |
118 | 116 | ||
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index f76f5f6e..54a02abd 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
@@ -126,24 +126,23 @@ function win32.root_of(pathname) | |||
126 | end | 126 | end |
127 | 127 | ||
128 | --- Create a wrapper to make a script executable from the command-line. | 128 | --- Create a wrapper to make a script executable from the command-line. |
129 | -- @param file string: Pathname of script to be made executable. | 129 | -- @param script string: Pathname of script to be made executable. |
130 | -- @param dest string: Directory where to put the wrapper. | 130 | -- @param target string: wrapper target pathname (without wrapper suffix). |
131 | -- @param name string: rock name to be used in loader context. | 131 | -- @param name string: rock name to be used in loader context. |
132 | -- @param version string: rock version to be used in loader context. | 132 | -- @param version string: rock version to be used in loader context. |
133 | -- @return boolean or (nil, string): True if succeeded, or nil and | 133 | -- @return boolean or (nil, string): True if succeeded, or nil and |
134 | -- an error message. | 134 | -- an error message. |
135 | function win32.wrap_script(file, dest, deps_mode, name, version, ...) | 135 | function win32.wrap_script(script, target, deps_mode, name, version, ...) |
136 | assert(type(file) == "string" or not file) | 136 | assert(type(script) == "string" or not script) |
137 | assert(type(dest) == "string") | 137 | assert(type(target) == "string") |
138 | assert(type(deps_mode) == "string") | 138 | assert(type(deps_mode) == "string") |
139 | assert(type(name) == "string" or not name) | 139 | assert(type(name) == "string" or not name) |
140 | assert(type(version) == "string" or not version) | 140 | assert(type(version) == "string" or not version) |
141 | 141 | ||
142 | local batname = (file or dest) .. ".bat" | 142 | local batname = target .. ".bat" |
143 | local wrapname = fs.is_dir(dest) and dest.."/"..batname or batname | 143 | local wrapper = io.open(batname, "wb") |
144 | local wrapper = io.open(wrapname, "w") | ||
145 | if not wrapper then | 144 | if not wrapper then |
146 | return nil, "Could not open "..wrapname.." for writing." | 145 | return nil, "Could not open "..batname.." for writing." |
147 | end | 146 | end |
148 | 147 | ||
149 | local lpath, lcpath = path.package_paths(deps_mode) | 148 | local lpath, lcpath = path.package_paths(deps_mode) |
@@ -157,13 +156,13 @@ function win32.wrap_script(file, dest, deps_mode, name, version, ...) | |||
157 | 156 | ||
158 | local argv = { | 157 | local argv = { |
159 | fs.Qb(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), | 158 | fs.Qb(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), |
160 | file and fs.Qb(file) or "", | 159 | script and fs.Qb(script) or "", |
161 | ... | 160 | ... |
162 | } | 161 | } |
163 | 162 | ||
164 | wrapper:write("@echo off\r\n") | 163 | wrapper:write("@echo off\r\n") |
165 | wrapper:write("set "..fs.Qb("LUAROCKS_SYSCONFDIR="..cfg.sysconfdir) .. "\r\n") | 164 | wrapper:write("set "..fs.Qb("LUAROCKS_SYSCONFDIR="..cfg.sysconfdir) .. "\r\n") |
166 | if dest == "luarocks" then | 165 | if target == "luarocks" or target == "luarocks-admin" then |
167 | wrapper:write("set "..fs.Qb(lpath_var.."="..package.path) .. "\r\n") | 166 | wrapper:write("set "..fs.Qb(lpath_var.."="..package.path) .. "\r\n") |
168 | wrapper:write("set "..fs.Qb(lcpath_var.."="..package.cpath) .. "\r\n") | 167 | wrapper:write("set "..fs.Qb(lcpath_var.."="..package.cpath) .. "\r\n") |
169 | else | 168 | else |