diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..675103d --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +build/*.* +build/CMakeFiles/2.8.12.2/CMakeASMCompiler.cmake +build/CMakeFiles/2.8.12.2/CMakeCCompiler.cmake +build/CMakeFiles/2.8.12.2/CMakeCXXCompiler.cmake +build/CMakeFiles/2.8.12.2/CMakeDetermineCompilerABI_C.bin +build/CMakeFiles/2.8.12.2/CMakeDetermineCompilerABI_CXX.bin +build/CMakeFiles/2.8.12.2/CMakeRCCompiler.cmake +build/CMakeFiles/2.8.12.2/CMakeSystem.cmake +build/CMakeFiles/2.8.12.2/CompilerIdC/CMakeCCompilerId.c +build/CMakeFiles/2.8.12.2/CompilerIdC/CMakeCCompilerId.exe +build/CMakeFiles/2.8.12.2/CompilerIdC/CMakeCCompilerId.obj +build/CMakeFiles/2.8.12.2/CompilerIdCXX/CMakeCXXCompilerId.cpp +build/CMakeFiles/2.8.12.2/CompilerIdCXX/CMakeCXXCompilerId.exe +build/CMakeFiles/2.8.12.2/CompilerIdCXX/CMakeCXXCompilerId.obj +build/CMakeFiles/CheckTypeSize/SIZEOF_VOID_P.bin +build/CMakeFiles/CheckTypeSize/SIZEOF_VOID_P.c +build/CMakeFiles/cmake.check_cache +build/CMakeFiles/CMakeDirectoryInformation.cmake +build/CMakeFiles/CMakeError.log +build/CMakeFiles/CMakeOutput.log +build/CMakeFiles/CMakeRuleHashes.txt +build/CMakeFiles/Makefile.cmake +build/CMakeFiles/Makefile2 +build/CMakeFiles/progress.marks +build/CMakeFiles/TargetDirectories.txt +build/luarocks/cmake_install.cmake +build/luarocks/CMakeFiles/CMakeDirectoryInformation.cmake +build/luarocks/CMakeFiles/progress.marks +build/luarocks/Makefile +build/luarocks/src/bin/luarocks.bat +build/luarocks/src/bin/luarocks-admin.bat +build/luarocks/src/luarocks/config.lua +build/luarocks/src/luarocks/site_config.lua +build/Makefile +build/LUA_DEV +bld07/* +x86/* +x64/* diff --git a/README.md b/README.md index d9da318..24a64b3 100644 --- a/README.md +++ b/README.md @@ -33,24 +33,43 @@ is free, it has no GUI, but it is just fine with CMake. # Installation +On Windows - use command prompt with appropritate environment (e.g. VS2013 Native Tools Command Prompt) + ```sh -git clone https://github.com/torch/luajit-rocks.git +git clone https://github.com/diz-vara/luajit-rocks.git cd luajit-rocks mkdir build cd build -cmake .. -DCMAKE_INSTALL_PREFIX=/your/prefix ``` +Choose the destination - (e.g. d:/luainstall) - it will be '/your/prefix' Then under Unix systems: ```sh +cmake .. -DCMAKE_INSTALL_PREFIX=/your/prefix make install ``` Under Windows: ```sh -nmake install +cmake .. -DCMAKE_INSTALL_PREFIX=/your/prefix -DWITH_LUAJIT21=ON -G "NMake Makefiles" -DWIN32=1 +nmake +cmake -DCMAKE_INSTALL_PREFIX=/your/prefix -DWITH_LUAJIT21=ON -G "NMake Makefiles" -DWIN32=1 -P cmake_install.cmake +``` + +Under Windows - remember to update your environment variables. Assuming that your/prefix is d:/luainstall : +```sh +set LUA_CPATH=d:\luainstall?.DLL;d:\luainstall\LIB\?.DLL;?.DLL +set LUA_DEV=d:/luainstall +set LUA_PATH=;;d:\luainstall\?;d:\luainstall\lua\?\init.lua;d:\luainstall\?.lua ``` +Then install packages you need: +luarocks install torch +luarocks install nn +luarocks install nnx +etc... + + Note: we do not recommend (nor we support) installation under Cygwin. ## Additional CMake flags diff --git a/lua-5.1/src/lua.h b/lua-5.1/src/lua.h index a4b73e7..2883f4c 100644 --- a/lua-5.1/src/lua.h +++ b/lua-5.1/src/lua.h @@ -9,6 +9,16 @@ #ifndef lua_h #define lua_h +#ifdef WIN32 +# ifndef LUA_WIN +# define LUA_WIN +# endif +# ifndef _WIN32 +# define _WIN32 +# endif +#endif + + #include #include diff --git a/lua-5.2/src/lua.h b/lua-5.2/src/lua.h index 149a2c3..27e4c8b 100644 --- a/lua-5.2/src/lua.h +++ b/lua-5.2/src/lua.h @@ -9,6 +9,17 @@ #ifndef lua_h #define lua_h +#ifdef WIN32 +# ifndef LUA_WIN +# define LUA_WIN +# endif +# ifndef _WIN32 +# define _WIN32 +# endif +#endif + + + #include #include diff --git a/luajit-2.0/src/lua.h b/luajit-2.0/src/lua.h index c83fd3b..b42cc63 100644 --- a/luajit-2.0/src/lua.h +++ b/luajit-2.0/src/lua.h @@ -9,6 +9,21 @@ #ifndef lua_h #define lua_h +#ifdef WIN32 +# ifndef LUA_WIN +# define LUA_WIN +# endif +# ifndef _WIN32 +# define _WIN32 +# endif + +# if !defined LUA_LIB & !defined LUA_CORE & !defined luajit_c & !defined _LJ_ARCH_H & !defined _LJ_DEF_H & !defined _LJ_OBJ_H +# pragma comment( lib, "libluajit.lib") +# endif + +#endif + + #include #include diff --git a/luajit-2.1/src/lua.h b/luajit-2.1/src/lua.h index c83fd3b..067bb3a 100644 --- a/luajit-2.1/src/lua.h +++ b/luajit-2.1/src/lua.h @@ -9,6 +9,22 @@ #ifndef lua_h #define lua_h +#ifdef WIN32 +# ifndef LUA_WIN +# define LUA_WIN +# endif +# ifndef _WIN32 +# define _WIN32 +# endif + +# if !defined LUA_LIB & !defined LUA_CORE & !defined luajit_c & !defined _LJ_ARCH_H & !defined _LJ_DEF_H & !defined _LJ_OBJ_H +# pragma comment( lib, "libluajit.lib") +# endif + +#endif + + + #include #include diff --git a/luajit-2.1/src/luaconf.h b/luajit-2.1/src/luaconf.h index b2baf7b..757de1b 100644 --- a/luajit-2.1/src/luaconf.h +++ b/luajit-2.1/src/luaconf.h @@ -18,6 +18,9 @@ ** In Windows, any exclamation mark ('!') in the path is replaced by the ** path of the directory of the executable file of the current process. */ + +#define LUA_BUILD_AS_DLL 1 + #define LUA_LDIR "!\\lua\\" #define LUA_CDIR "!\\" #define LUA_PATH_DEFAULT \ @@ -135,7 +138,7 @@ #define LUA_API __declspec(dllimport) #endif #else -#define LUA_API extern +#define LUA_API extern "C" #endif #define LUALIB_API LUA_API diff --git a/luarocks/CMakeLists.txt b/luarocks/CMakeLists.txt index cdf223f..80b7f9e 100644 --- a/luarocks/CMakeLists.txt +++ b/luarocks/CMakeLists.txt @@ -33,6 +33,7 @@ IF(WIN32) INSTALL(FILES ${WINUTILS_DLL_FILES} DESTINATION "${INSTALL_BIN_SUBDIR}") SET(WINUTILS_EXE_FILES + win32/bin/cmake.cmd win32/bin/7z.exe win32/bin/chmod.exe win32/bin/cp.exe win32/bin/find.exe win32/bin/ls.exe win32/bin/md5sum.exe win32/bin/mkdir.exe win32/bin/mv.exe win32/bin/objdump.exe @@ -85,6 +86,7 @@ ENDIF() SET(LUAROCKS_FILES fs/unix/tools.lua fs/unix.lua fs/win32/tools.lua fs/win32.lua fs/lua.lua + fs/x64/tools.lua fs/x64.lua persist.lua list.lua require.lua repos.lua dir.lua make_manifest.lua command_line.lua install.lua build/command.lua build/cmake.lua build/make.lua build/builtin.lua fetch/cvs.lua fetch/git.lua diff --git a/luarocks/src/luarocks/build/builtin.lua b/luarocks/src/luarocks/build/builtin.lua index 47aa71f..45e5f40 100644 --- a/luarocks/src/luarocks/build/builtin.lua +++ b/luarocks/src/luarocks/build/builtin.lua @@ -99,7 +99,7 @@ function builtin.run(rockspec) "-l" .. (variables.MSVCRT or "m"), "-luser32") return ok, wrapname end - elseif cfg.is_platform("win32") then + elseif cfg.is_platform("win32") or cfg.is_platform('x64') then compile_object = function(object, source, defines, incdirs) local extras = {} add_flags(extras, "-D%s", defines) @@ -116,7 +116,8 @@ function builtin.run(rockspec) def:write("EXPORTS\n") def:write("luaopen_"..name:gsub("%.", "_").."\n") def:close() - local ok = execute(variables.LD, "-dll", "-def:"..deffile, "-out:"..library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), unpack(extras)) + -- diz --- local ok = execute(variables.LD, "-dll", "-def:"..deffile, "-out:"..library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), unpack(extras)) + local ok = execute(variables.LD, "-dll", "-out:"..library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), unpack(extras)) local basedir = "" if name:find("%.") ~= nil then basedir = name:gsub("%.%w+$", "\\") @@ -127,6 +128,7 @@ function builtin.run(rockspec) if ok and fs.exists(manifestfile) then ok = execute(variables.MT, "-manifest", manifestfile, "-outputresource:"..basedir..basename..".dll;2") end + --- diz --- io.read() return ok end compile_wrapper_binary = function(fullname, name) diff --git a/luarocks/src/luarocks/cfg.lua b/luarocks/src/luarocks/cfg.lua index 9a782c9..52cf496 100644 --- a/luarocks/src/luarocks/cfg.lua +++ b/luarocks/src/luarocks/cfg.lua @@ -293,13 +293,13 @@ local defaults = { } if detected.windows then - local full_prefix = site_config.LUAROCKS_PREFIX.."\\"..cfg.major_version + local full_prefix = site_config.LUAROCKS_PREFIX --.."\\"..cfg.major_version extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua" home_config_file = home_config_file and home_config_file:gsub("\\","/") defaults.fs_use_modules = false - defaults.arch = "win32-"..proc - defaults.platforms = {"win32", "windows" } + defaults.arch = "x64-"..proc + defaults.platforms = {"x64", "windows" } defaults.lib_extension = "dll" defaults.external_lib_extension = "dll" defaults.obj_extension = "obj" @@ -307,8 +307,8 @@ if detected.windows then defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/bin" defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/include" defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/lib" - defaults.cmake_generator = "MinGW Makefiles" - defaults.makefile = "Makefile.win" + defaults.cmake_generator = "NMake Makefiles" + defaults.makefile = "Makefile" defaults.variables.MAKE = "nmake" defaults.variables.CC = "cl" defaults.variables.RC = "rc" @@ -323,7 +323,7 @@ if detected.windows then "MKDIR", "MV", "PWD", "RMDIR", "TEST", "UNAME", "WGET" } for _, var in ipairs(bins) do if defaults.variables[var] then - defaults.variables[var] = full_prefix.."\\tools\\"..defaults.variables[var] + defaults.variables[var] = full_prefix..defaults.variables[var] end end diff --git a/luarocks/src/luarocks/config.lua.in b/luarocks/src/luarocks/config.lua.in index 2add348..cfc7689 100644 --- a/luarocks/src/luarocks/config.lua.in +++ b/luarocks/src/luarocks/config.lua.in @@ -12,6 +12,7 @@ rocks_trees = { } rocks_servers = { + [[https://raw.githubusercontent.com/diz-vara/rocks/master]], [[https://raw.githubusercontent.com/torch/rocks/master]], [[https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master]] } diff --git a/luarocks/src/luarocks/config.lua.win.in b/luarocks/src/luarocks/config.lua.win.in index ff3ec6c..84e8e8a 100644 --- a/luarocks/src/luarocks/config.lua.win.in +++ b/luarocks/src/luarocks/config.lua.win.in @@ -12,8 +12,9 @@ rocks_trees = { } rocks_servers = { - [[https://raw.githubusercontent.com/torch/rocks/master]], - [[https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master]] + [[https://raw.githubusercontent.com/diz-vara/rocks/master]], + [[https://raw.githubusercontent.com/torch/rocks/master]], + [[https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master]] } variables = { diff --git a/luarocks/src/luarocks/fs/x64.lua b/luarocks/src/luarocks/fs/x64.lua new file mode 100644 index 0000000..12d86d1 --- /dev/null +++ b/luarocks/src/luarocks/fs/x64.lua @@ -0,0 +1,221 @@ +--- Windows implementation of filesystem and platform abstractions. +-- Download http://unxutils.sourceforge.net/ for Windows GNU utilities +-- used by this module. +--module("luarocks.fs.win32", package.seeall) +local win32 = {} + +local fs = require("luarocks.fs") + +local cfg = require("luarocks.cfg") +local dir = require("luarocks.dir") +local util = require("luarocks.util") + +-- Monkey patch io.popen and os.execute to make sure quoting +-- works as expected. +-- See http://lua-users.org/lists/lua-l/2013-11/msg00367.html +local _prefix = "type NUL && " +local _popen, _execute = io.popen, os.execute +io.popen = function(cmd, ...) return _popen(_prefix..cmd, ...) end +os.execute = function(cmd, ...) return _execute(_prefix..cmd, ...) end + + +--- Annotate command string for quiet execution. +-- @param cmd string: A command-line string. +-- @return string: The command-line, with silencing annotation. +function win32.quiet(cmd) + return cmd.." 2> NUL 1> NUL" +end + + +local win_escape_chars = { + ["%"] = "%%", + ['"'] = '\\"', +} + +local function q_escaper(bs, q) + return ("\\"):rep(2*#bs-1) .. (q or "\\") +end + +local function p_escaper(bs) + return bs .. bs .. '"%"' +end + +--- Quote argument for shell processing. Fixes paths on Windows. +-- Adds double quotes and escapes. +-- @param arg string: Unquoted argument. +-- @return string: Quoted argument. +function win32.Q(arg) + assert(type(arg) == "string") + -- Quote DIR for Windows + if arg:match("^[%.a-zA-Z]?:?[\\/]") then + arg = arg:gsub("/", "\\") + end + if arg == "\\" then + return '\\' -- CHDIR needs special handling for root dir + end + -- URLs and anything else + arg = arg:gsub('(\\+)(")', q_escaper) + arg = arg:gsub('(\\+)$', q_escaper) + arg = arg:gsub('"', win_escape_chars) + arg = arg:gsub('(\\*)%%', p_escaper) + return '"' .. arg .. '"' +end + +--- Quote argument for shell processing in batch files. +-- Adds double quotes and escapes. +-- @param arg string: Unquoted argument. +-- @return string: Quoted argument. +function win32.Qb(arg) + assert(type(arg) == "string") + -- Quote DIR for Windows + if arg:match("^[%.a-zA-Z]?:?[\\/]") then + arg = arg:gsub("/", "\\") + end + if arg == "\\" then + return '\\' -- CHDIR needs special handling for root dir + end + -- URLs and anything else + arg = arg:gsub('(\\+)(")', q_escaper) + arg = arg:gsub('(\\+)$', q_escaper) + arg = arg:gsub('[%%"]', win_escape_chars) + return '"' .. arg .. '"' +end + +--- Return an absolute pathname from a potentially relative one. +-- @param pathname string: pathname to convert. +-- @param relative_to string or nil: path to prepend when making +-- pathname absolute, or the current dir in the dir stack if +-- not given. +-- @return string: The pathname converted to absolute. +function win32.absolute_name(pathname, relative_to) + assert(type(pathname) == "string") + assert(type(relative_to) == "string" or not relative_to) + + relative_to = relative_to or fs.current_dir() + -- FIXME I'm not sure this first \\ should be there at all. + -- What are the Windows rules for drive letters? + if pathname:match("^[\\.a-zA-Z]?:?[\\/]") then + return pathname + else + return relative_to .. "/" .. pathname + end +end + +--- Create a wrapper to make a script executable from the command-line. +-- @param file string: Pathname of script to be made executable. +-- @param dest string: Directory where to put the wrapper. +-- @param name string: rock name to be used in loader context. +-- @param version string: rock version to be used in loader context. +-- @return boolean or (nil, string): True if succeeded, or nil and +-- an error message. +function win32.wrap_script(file, dest, name, version) + assert(type(file) == "string") + assert(type(dest) == "string") + + local base = dir.base_name(file) + local wrapname = fs.is_dir(dest) and dest.."/"..base or dest + wrapname = wrapname..".bat" + local lpath, lcpath = cfg.package_paths() + local wrapper = io.open(wrapname, "w") + if not wrapper then + return nil, "Could not open "..wrapname.." for writing." + end + wrapper:write("@echo off\n") + local lua = dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter) + local ppaths = "package.path="..util.LQ(lpath..";").."..package.path; package.cpath="..util.LQ(lcpath..";").."..package.cpath" + local addctx = "local k,l,_=pcall(require,"..util.LQ("luarocks.loader")..") _=k and l.add_context("..util.LQ(name)..","..util.LQ(version)..")" + wrapper:write(fs.Qb(lua)..' -e '..fs.Qb(ppaths)..' -e '..fs.Qb(addctx)..' '..fs.Qb(file)..' %*\n') + wrapper:close() + return true +end + +function win32.is_actual_binary(name) + name = name:lower() + if name:match("%.bat$") or name:match("%.exe$") then + return true + end + return false +end + +function win32.copy_binary(filename, dest) + local ok, err = fs.copy(filename, dest) + if not ok then + return nil, err + end + local exe_pattern = "%.[Ee][Xx][Ee]$" + local base = dir.base_name(filename) + dest = dir.dir_name(dest) + if base:match(exe_pattern) then + base = base:gsub(exe_pattern, ".lua") + local helpname = dest.."/"..base + local helper = io.open(helpname, "w") + if not helper then + return nil, "Could not open "..helpname.." for writing." + end + helper:write('package.path=\"'..package.path:gsub("\\","\\\\")..';\"..package.path\n') + helper:write('package.cpath=\"'..package.path:gsub("\\","\\\\")..';\"..package.cpath\n') + helper:close() + end + return true +end + +function win32.chmod(filename, mode) + return true +end + +function win32.get_permissions(filename) + return "" +end + +--- Move a file on top of the other. +-- The new file ceases to exist under its original name, +-- and takes over the name of the old file. +-- On Windows this is done by removing the original file and +-- renaming the new file to its original name. +-- @param old_file The name of the original file, +-- which will be the new name of new_file. +-- @param new_file The name of the new file, +-- which will replace old_file. +-- @return boolean or (nil, string): True if succeeded, or nil and +-- an error message. +function win32.replace_file(old_file, new_file) + os.remove(old_file) + return os.rename(new_file, old_file) +end + +--- Test is file/dir is writable. +-- Warning: testing if a file/dir is writable does not guarantee +-- that it will remain writable and therefore it is no replacement +-- for checking the result of subsequent operations. +-- @param file string: filename to test +-- @return boolean: true if file exists, false otherwise. +function win32.is_writable(file) + assert(file) + file = dir.normalize(file) + local result + local tmpname = 'tmpluarockstestwritable.deleteme' + if fs.is_dir(file) then + local file2 = dir.path(file, tmpname) + local fh = io.open(file2, 'wb') + result = fh ~= nil + if fh then fh:close() end + if result then + -- the above test might give a false positive when writing to + -- c:\program files\ because of VirtualStore redirection on Vista and up + -- So check whether it's really there + result = fs.exists(file2) + end + os.remove(file2) + else + local fh = io.open(file, 'r+b') + result = fh ~= nil + if fh then fh:close() end + end + return result +end + +function win32.tmpname() + return os.getenv("TMP")..os.tmpname() +end + +return win32 diff --git a/luarocks/src/luarocks/fs/x64/tools.lua b/luarocks/src/luarocks/fs/x64/tools.lua new file mode 100644 index 0000000..0d4d710 --- /dev/null +++ b/luarocks/src/luarocks/fs/x64/tools.lua @@ -0,0 +1,370 @@ + +--- fs operations implemented with third-party tools for Windows platform abstractions. +-- Download http://unxutils.sourceforge.net/ for Windows GNU utilities +-- used by this module. +--module("luarocks.fs.win32.tools", package.seeall) +local tools = {} + +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") +local cfg = require("luarocks.cfg") + +local dir_stack = {} + +local vars = cfg.variables + +--- Strip the last extension of a filename. +-- Example: "foo.tar.gz" becomes "foo.tar". +-- If filename has no dots, returns it unchanged. +-- @param filename string: The file name to strip. +-- @return string: The stripped name. +local function strip_extension(filename) + assert(type(filename) == "string") + + return (filename:gsub("%.[^.]+$", "")) or filename +end + +local function command_at(directory, cmd) + --print(directory, cmd) + local drive = directory:match("^([A-Za-z]:)") + cmd = "cd " .. fs.Q(directory) .. " & " .. cmd + if drive then + cmd = drive .. " & " .. cmd + end + return cmd +end + +--- Obtain current directory. +-- Uses the module's internal directory stack. +-- @return string: the absolute pathname of the current directory. +function tools.current_dir() + local current = cfg.cache_pwd + if not current then + local pipe = io.popen(fs.Q(vars.PWD)) + current = pipe:read("*l") + pipe:close() + cfg.cache_pwd = current + end + for _, directory in ipairs(dir_stack) do + current = fs.absolute_name(directory, current) + end + return current +end + +--- Run the given command. +-- The command is executed in the current directory in the directory stack. +-- @param cmd string: No quoting/escaping is applied to the command. +-- @return boolean: true if command succeeds (status code 0), false +-- otherwise. +function tools.execute_string(cmd) + cmd = command_at(fs.current_dir(), cmd) + local code = os.execute(cmd) + if code == 0 or code == true then + return true + else + return false + end +end + +--- Change the current directory. +-- Uses the module's internal directory stack. This does not have exact +-- semantics of chdir, as it does not handle errors the same way, +-- but works well for our purposes for now. +-- @param directory string: The directory to switch to. +-- @return boolean or (nil, string): true if successful, (nil, error message) if failed. +function tools.change_dir(directory) + assert(type(directory) == "string") + if fs.is_dir(directory) then + table.insert(dir_stack, directory) + return true + end + return nil, "directory not found: "..directory +end + +--- Change directory to root. +-- Allows leaving a directory (e.g. for deleting it) in +-- a crossplatform way. +function tools.change_dir_to_root() + table.insert(dir_stack, "/") +end + +--- Change working directory to the previous in the directory stack. +function tools.pop_dir() + local directory = table.remove(dir_stack) + return directory ~= nil +end + +--- Create a directory if it does not already exist. +-- If any of the higher levels in the path name does not exist +-- too, they are created as well. +-- @param directory string: pathname of directory to create. +-- @return boolean: true on success, false on failure. +function tools.make_dir(directory) + assert(directory) + directory = dir.normalize(directory) + fs.execute_quiet(fs.Q(vars.MKDIR).." -p ", directory) + if not fs.is_dir(directory) then + return false, "failed making directory "..directory + end + return true +end + +--- Remove a directory if it is empty. +-- Does not return errors (for example, if directory is not empty or +-- if already does not exist) +-- @param directory string: pathname of directory to remove. +function tools.remove_dir_if_empty(directory) + assert(directory) + fs.execute_quiet(fs.Q(vars.RMDIR), directory) +end + +--- Remove a directory if it is empty. +-- Does not return errors (for example, if directory is not empty or +-- if already does not exist) +-- @param directory string: pathname of directory to remove. +function tools.remove_dir_tree_if_empty(directory) + assert(directory) + fs.execute_quiet(fs.Q(vars.RMDIR), directory) +end + +--- Copy a file. +-- @param src string: Pathname of source +-- @param dest string: Pathname of destination +-- @return boolean or (boolean, string): true on success, false on failure, +-- plus an error message. +function tools.copy(src, dest) + assert(src and dest) + if dest:match("[/\\]$") then dest = dest:sub(1, -2) end + local ok = fs.execute(fs.Q(vars.CP), src, dest) + if ok then + return true + else + return false, "Failed copying "..src.." to "..dest + end +end + +--- Recursively copy the contents of a directory. +-- @param src string: Pathname of source +-- @param dest string: Pathname of destination +-- @return boolean or (boolean, string): true on success, false on failure, +-- plus an error message. +function tools.copy_contents(src, dest) + assert(src and dest) + if fs.execute_quiet(fs.Q(vars.CP).." -dR "..src.."\\*.* "..fs.Q(dest)) then + return true + else + return false, "Failed copying "..src.." to "..dest + end +end + +--- Delete a file or a directory and all its contents. +-- For safety, this only accepts absolute paths. +-- @param arg string: Pathname of source +-- @return nil +function tools.delete(arg) + assert(arg) + assert(arg:match("^[a-zA-Z]?:?[\\/]")) + fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )") +end + +--- Internal implementation function for fs.dir. +-- Yields a filename on each iteration. +-- @param at string: directory to list +-- @return nil +function tools.dir_iterator(at) + local pipe = io.popen(command_at(at, fs.Q(vars.LS))) + for file in pipe:lines() do + if file ~= "." and file ~= ".." then + coroutine.yield(file) + end + end + pipe:close() +end + +--- Recursively scan the contents of a directory. +-- @param at string or nil: directory to scan (will be the current +-- directory if none is given). +-- @return table: an array of strings with the filenames representing +-- the contents of a directory. Paths are returned with forward slashes. +function tools.find(at) + assert(type(at) == "string" or not at) + if not at then + at = fs.current_dir() + end + if not fs.is_dir(at) then + return {} + end + local result = {} + local pipe = io.popen(command_at(at, fs.Q(vars.FIND).." 2> NUL")) + for file in pipe:lines() do + -- Windows find is a bit different + local first_two = file:sub(1,2) + if first_two == ".\\" or first_two == "./" then file=file:sub(3) end + if file ~= "." then + table.insert(result, (file:gsub("\\", "/"))) + end + end + pipe:close() + return result +end + +--- Compress files in a .zip archive. +-- @param zipfile string: pathname of .zip archive to be created. +-- @param ... Filenames to be stored in the archive are given as +-- additional arguments. +-- @return boolean: true on success, false on failure. +function tools.zip(zipfile, ...) + return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) +end + +--- Uncompress files from a .zip archive. +-- @param zipfile string: pathname of .zip archive to be extracted. +-- @return boolean: true on success, false on failure. +function tools.unzip(zipfile) + assert(zipfile) + return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) +end + +--- Test is pathname is a directory. +-- @param file string: pathname to test +-- @return boolean: true if it is a directory, false otherwise. +function tools.is_dir(file) + assert(file) + return fs.execute_quiet("if not exist " .. fs.Q(file.."\\").." invalidcommandname") +end + +--- Test is pathname is a regular file. +-- @param file string: pathname to test +-- @return boolean: true if it is a regular file, false otherwise. +function tools.is_file(file) + assert(file) + return fs.execute(fs.Q(vars.TEST).." -f", file) +end + +--- Download a remote file. +-- @param url string: URL to be fetched. +-- @param filename string or nil: this function attempts to detect the +-- resulting local filename of the remote file as the basename of the URL; +-- if that is not correct (due to a redirection, for example), the local +-- filename can be given explicitly as this second argument. +-- @return (boolean, string): true and the filename on success, +-- false and the error message on failure. +function tools.use_downloader(url, filename, cache) + assert(type(url) == "string") + assert(type(filename) == "string" or not filename) + + filename = fs.absolute_name(filename or dir.base_name(url)) + + local ok + if cfg.downloader == "wget" then + local wget_cmd = fs.Q(vars.WGET).." --no-check-certificate --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " + if cfg.connection_timeout and cfg.connection_timeout > 0 then + wget_cmd = wget_cmd .. "--timeout="..tonumber(cfg.connection_timeout).." --tries=1 " + end + if cache then + -- --timestamping is incompatible with --output-document, + -- but that's not a problem for our use cases. + fs.change_dir(dir.dir_name(filename)) + ok = fs.execute_quiet(wget_cmd.." --timestamping ", url) + fs.pop_dir() + elseif filename then + ok = fs.execute_quiet(wget_cmd.." --output-document ", filename, url) + else + ok = fs.execute_quiet(wget_cmd, url) + end + elseif cfg.downloader == "curl" then + local curl_cmd = vars.CURL.." -f -k -L --user-agent \""..cfg.user_agent.." via curl\" " + if cfg.connection_timeout and cfg.connection_timeout > 0 then + curl_cmd = curl_cmd .. "--connect-timeout "..tonumber(cfg.connection_timeout).." " + end + ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) + end + if ok then + return true, filename + else + return false + end +end + +--- Uncompress gzip file. +-- @param archive string: Filename of archive. +-- @return boolean : success status +local function gunzip(archive) + return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", archive) +end + +--- Unpack an archive. +-- Extract the contents of an archive, detecting its format by +-- filename extension. +-- @param archive string: Filename of archive. +-- @return boolean or (boolean, string): true on success, false and an error message on failure. +function tools.unpack_archive(archive) + assert(type(archive) == "string") + + local ok + local sevenzx = fs.Q(vars.SEVENZ).." -aoa x" + if archive:match("%.tar%.gz$") then + ok = gunzip(archive) + if ok then + ok = fs.execute_quiet(sevenzx, strip_extension(archive)) + end + elseif archive:match("%.tgz$") then + ok = gunzip(archive) + if ok then + ok = fs.execute_quiet(sevenzx, strip_extension(archive)..".tar") + end + elseif archive:match("%.tar%.bz2$") then + ok = fs.execute_quiet(sevenzx, archive) + if ok then + ok = fs.execute_quiet(sevenzx, strip_extension(archive)) + end + elseif archive:match("%.zip$") then + ok = fs.execute_quiet(sevenzx, archive) + elseif archive:match("%.lua$") or archive:match("%.c$") then + -- Ignore .lua and .c files; they don't need to be extracted. + return true + else + local ext = archive:match(".*(%..*)") + return false, "Unrecognized filename extension "..(ext or "") + end + if not ok then + return false, "Failed extracting "..archive + end + return true +end + +local md5_cmd = { + md5sum = fs.Q(vars.MD5SUM), + openssl = fs.Q(vars.OPENSSL).." md5", + md5 = fs.Q(vars.MD5), +} + +--- Get the MD5 checksum for a file. +-- @param file string: The file to be computed. +-- @return string: The MD5 checksum or nil + message +function tools.get_md5(file) + local cmd = md5_cmd[cfg.md5checker] + if not cmd then return nil, "no MD5 checker command configured" end + local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) + local computed = pipe:read("*a") + pipe:close() + if computed then + computed = computed:match("("..("%x"):rep(32)..")") + end + if computed then return computed end + return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) +end + +--- Test for existance of a file. +-- @param file string: filename to test +-- @return boolean: true if file exists, false otherwise. +function tools.exists(file) + assert(file) + return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname") +end + +function tools.browser(url) + return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) +end + +return tools diff --git a/luarocks/win32/tools/7z.dll b/luarocks/win32/bin/7z.dll similarity index 100% rename from luarocks/win32/tools/7z.dll rename to luarocks/win32/bin/7z.dll diff --git a/luarocks/win32/tools/7z.exe b/luarocks/win32/bin/7z.exe similarity index 100% rename from luarocks/win32/tools/7z.exe rename to luarocks/win32/bin/7z.exe diff --git a/luarocks/win32/bin/chmod.exe b/luarocks/win32/bin/chmod.exe new file mode 100644 index 0000000..43e9ea3 Binary files /dev/null and b/luarocks/win32/bin/chmod.exe differ diff --git a/luarocks/win32/bin/cmake.cmd b/luarocks/win32/bin/cmake.cmd new file mode 100644 index 0000000..2a3405e --- /dev/null +++ b/luarocks/win32/bin/cmake.cmd @@ -0,0 +1,6 @@ +if %1 == -E ( +cmake.exe %* +) else ( +cmake.exe -G "NMake Makefiles" -DWIN32=1 %* +) + \ No newline at end of file diff --git a/luarocks/win32/tools/cp.exe b/luarocks/win32/bin/cp.exe similarity index 100% rename from luarocks/win32/tools/cp.exe rename to luarocks/win32/bin/cp.exe diff --git a/luarocks/win32/tools/find.exe b/luarocks/win32/bin/find.exe similarity index 100% rename from luarocks/win32/tools/find.exe rename to luarocks/win32/bin/find.exe diff --git a/luarocks/win32/tools/libeay32.dll b/luarocks/win32/bin/libeay32.dll similarity index 100% rename from luarocks/win32/tools/libeay32.dll rename to luarocks/win32/bin/libeay32.dll diff --git a/luarocks/win32/tools/libiconv2.dll b/luarocks/win32/bin/libiconv2.dll similarity index 100% rename from luarocks/win32/tools/libiconv2.dll rename to luarocks/win32/bin/libiconv2.dll diff --git a/luarocks/win32/tools/libintl3.dll b/luarocks/win32/bin/libintl3.dll similarity index 100% rename from luarocks/win32/tools/libintl3.dll rename to luarocks/win32/bin/libintl3.dll diff --git a/luarocks/win32/tools/libssl32.dll b/luarocks/win32/bin/libssl32.dll similarity index 100% rename from luarocks/win32/tools/libssl32.dll rename to luarocks/win32/bin/libssl32.dll diff --git a/luarocks/win32/tools/ls.exe b/luarocks/win32/bin/ls.exe similarity index 100% rename from luarocks/win32/tools/ls.exe rename to luarocks/win32/bin/ls.exe diff --git a/luarocks/win32/tools/md5sum.exe b/luarocks/win32/bin/md5sum.exe similarity index 100% rename from luarocks/win32/tools/md5sum.exe rename to luarocks/win32/bin/md5sum.exe diff --git a/luarocks/win32/tools/mkdir.exe b/luarocks/win32/bin/mkdir.exe similarity index 100% rename from luarocks/win32/tools/mkdir.exe rename to luarocks/win32/bin/mkdir.exe diff --git a/luarocks/win32/tools/mv.exe b/luarocks/win32/bin/mv.exe similarity index 100% rename from luarocks/win32/tools/mv.exe rename to luarocks/win32/bin/mv.exe diff --git a/luarocks/win32/bin/objdump.exe b/luarocks/win32/bin/objdump.exe new file mode 100644 index 0000000..6d0c393 Binary files /dev/null and b/luarocks/win32/bin/objdump.exe differ diff --git a/luarocks/win32/tools/pwd.exe b/luarocks/win32/bin/pwd.exe similarity index 100% rename from luarocks/win32/tools/pwd.exe rename to luarocks/win32/bin/pwd.exe diff --git a/luarocks/win32/bin/rm.exe b/luarocks/win32/bin/rm.exe new file mode 100644 index 0000000..fc5b2a6 Binary files /dev/null and b/luarocks/win32/bin/rm.exe differ diff --git a/luarocks/win32/tools/rmdir.exe b/luarocks/win32/bin/rmdir.exe similarity index 100% rename from luarocks/win32/tools/rmdir.exe rename to luarocks/win32/bin/rmdir.exe diff --git a/luarocks/win32/tools/test.exe b/luarocks/win32/bin/test.exe similarity index 100% rename from luarocks/win32/tools/test.exe rename to luarocks/win32/bin/test.exe diff --git a/luarocks/win32/tools/uname.exe b/luarocks/win32/bin/uname.exe similarity index 100% rename from luarocks/win32/tools/uname.exe rename to luarocks/win32/bin/uname.exe diff --git a/luarocks/win32/tools/wget.exe b/luarocks/win32/bin/wget.exe similarity index 100% rename from luarocks/win32/tools/wget.exe rename to luarocks/win32/bin/wget.exe