aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/build/builtin.lua25
-rw-r--r--src/luarocks/fs/lua.lua13
-rw-r--r--src/luarocks/repos.lua10
3 files changed, 27 insertions, 21 deletions
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index 5c58265a..5120c85c 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -19,6 +19,7 @@ end
19--- Makes an RC file with an embedded Lua script, for building .exes on Windows 19--- Makes an RC file with an embedded Lua script, for building .exes on Windows
20-- @return nil if could open files, error otherwise 20-- @return nil if could open files, error otherwise
21local function make_rc(luafilename, rcfilename) 21local function make_rc(luafilename, rcfilename)
22 --TODO EXEWRAPPER
22 local rcfile = io.open(rcfilename, "w") 23 local rcfile = io.open(rcfilename, "w")
23 if not rcfile then 24 if not rcfile then
24 error("Could not open "..rcfilename.." for writing.") 25 error("Could not open "..rcfilename.." for writing.")
@@ -46,7 +47,7 @@ end
46-- nil and an error message otherwise. 47-- nil and an error message otherwise.
47function run(rockspec) 48function run(rockspec)
48 assert(type(rockspec) == "table") 49 assert(type(rockspec) == "table")
49 local compile_object, compile_library, compile_wrapper_binary 50 local compile_object, compile_library, compile_wrapper_binary --TODO EXEWRAPPER
50 51
51 local build = rockspec.build 52 local build = rockspec.build
52 local variables = rockspec.variables 53 local variables = rockspec.variables
@@ -80,6 +81,7 @@ function run(rockspec)
80 return ok 81 return ok
81 end 82 end
82 compile_wrapper_binary = function(fullname, name) 83 compile_wrapper_binary = function(fullname, name)
84 --TODO EXEWRAPPER
83 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\") 85 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\")
84 local basename = name:gsub("%.lua$", ""):gsub("/", "\\") 86 local basename = name:gsub("%.lua$", ""):gsub("/", "\\")
85 local rcname = basename..".rc" 87 local rcname = basename..".rc"
@@ -125,6 +127,7 @@ function run(rockspec)
125 return ok 127 return ok
126 end 128 end
127 compile_wrapper_binary = function(fullname, name) 129 compile_wrapper_binary = function(fullname, name)
130 --TODO EXEWRAPPER
128 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\") 131 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\")
129 local basename = name:gsub("%.lua$", ""):gsub("/", "\\") 132 local basename = name:gsub("%.lua$", ""):gsub("/", "\\")
130 local object = basename..".obj" 133 local object = basename..".obj"
@@ -165,6 +168,7 @@ function run(rockspec)
165 return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) 168 return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras))
166 end 169 end
167 compile_wrapper_binary = function(fullname, name) return true, name end 170 compile_wrapper_binary = function(fullname, name) return true, name end
171 --TODO EXEWRAPPER
168 end 172 end
169 173
170 local ok = true 174 local ok = true
@@ -173,30 +177,25 @@ function run(rockspec)
173 local luadir = path.lua_dir(rockspec.name, rockspec.version) 177 local luadir = path.lua_dir(rockspec.name, rockspec.version)
174 local libdir = path.lib_dir(rockspec.name, rockspec.version) 178 local libdir = path.lib_dir(rockspec.name, rockspec.version)
175 local docdir = path.doc_dir(rockspec.name, rockspec.version) 179 local docdir = path.doc_dir(rockspec.name, rockspec.version)
180 --TODO EXEWRAPPER
176 -- On Windows, compiles an .exe for each Lua file in build.install.bin, and 181 -- On Windows, compiles an .exe for each Lua file in build.install.bin, and
177 -- replaces the filename with the .exe name. Strips the .lua extension if it exists, 182 -- replaces the filename with the .exe name. Strips the .lua extension if it exists,
178 -- otherwise just appends .exe to the name 183 -- otherwise just appends .exe to the name. Only if `cfg.exewrapper = true`
179 if build.install and build.install.bin then 184 if build.install and build.install.bin then
180 for i, name in ipairs(build.install.bin) do 185 for key, name in pairs(build.install.bin) do
181 local fullname = dir.path(fs.current_dir(), name) 186 local fullname = dir.path(fs.current_dir(), name)
182 local match = name:match("%.lua$") 187 if cfg.exewrapper and fs.is_lua(fullname) then
183 local basename = name:gsub("%.lua$", "")
184 local file
185 if not match then
186 file = io.open(fullname)
187 end
188 if match or (file and file:read():match("#!.*lua.*")) then
189 ok, name = compile_wrapper_binary(fullname, name) 188 ok, name = compile_wrapper_binary(fullname, name)
190 if ok then 189 if ok then
191 build.install.bin[i] = name 190 build.install.bin[key] = name
192 else 191 else
193 if file then file:close() end
194 return nil, "Build error in wrapper binaries" 192 return nil, "Build error in wrapper binaries"
195 end 193 end
196 end 194 end
197 if file then file:close() end
198 end 195 end
199 end 196 end
197
198
200 for name, info in pairs(build.modules) do 199 for name, info in pairs(build.modules) do
201 local moddir = path.module_to_path(name) 200 local moddir = path.module_to_path(name)
202 if type(info) == "string" then 201 if type(info) == "string" then
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 9806bb63..495327ea 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -800,4 +800,17 @@ function fs_lua.check_command_permissions(flags)
800 end 800 end
801end 801end
802 802
803--- Check whether a file is a Lua script
804-- When the file can be succesfully compiled by the configured
805-- Lua interpreter, it's considered to be a valid Lua file.
806-- @param name filename of file to check
807-- @return boolean true, if it is a Lua script, false otherwise
808function fs_lua.is_lua(name)
809 name = name:gsub([[%\]],"/") -- normalize on fw slash to prevent escaping issues
810 local lua = fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)) -- get lua interpreter configured
811 -- execute on configured interpreter, might not be the same as the interpreter LR is run on
812 local result = fs.execute_string(lua..[[ -e "if loadfile(']]..name..[[') then os.exit() else os.exit(1) end"]])
813 return (result == true)
814end
815
803return fs_lua 816return fs_lua
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua
index 4a9c2f7d..7ad75846 100644
--- a/src/luarocks/repos.lua
+++ b/src/luarocks/repos.lua
@@ -153,18 +153,12 @@ end
153local function install_binary(source, target, name, version) 153local 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
157 local match = source:match("%.lua$") 157 if fs.is_lua(source) then
158 local file, ok, err
159 if not match then
160 file = io.open(source)
161 end
162 if match or (file and file:read():match("^#!.*lua.*")) then
163 ok, err = fs.wrap_script(source, target, name, version) 158 ok, err = fs.wrap_script(source, target, name, version)
164 else 159 else
165 ok, err = fs.copy_binary(source, target) 160 ok, err = fs.copy_binary(source, target)
166 end 161 end
167 if file then file:close() end
168 return ok, err 162 return ok, err
169end 163end
170 164