diff options
author | Ronan Collobert <locronan@fb.com> | 2016-02-02 22:50:44 +0300 |
---|---|---|
committer | Ronan Collobert <locronan@fb.com> | 2016-02-02 22:50:44 +0300 |
commit | f52070e5743fa91a18538410a4f4a7037012bc35 (patch) | |
tree | 67e0d5c7e6e5deb5822e2cab0e9a8cebbfbdbd16 | |
parent | fbe7ffba6e8d6ec4375fb2fa85851ea595d2fb60 (diff) |
Squashed 'luarocks/' changes from 8d8e364..f29297f
f29297f Merge branch 'master' into 2.3.0
84067c2 Merge pull request #476 from Tieske/master
26b6f6c fix missing variable expansion when using a self contained configuration
fe0156e Merge pull request #471 from mpeterv/fix-travis
c85cca9 Install luabitop from src rock on travis
98fa937 Merge branch 'master' into 2.3.0
fbe0915 Merge branch 'master' of https://github.com/keplerproject/luarocks
d7a9e71 Stricter version consistency checks.
98175bd Update version number in appveyor.yml too
fd99e90 Update version number.
e559464 Merge remote-tracking branch 'origin/master' into 2.2.3
515db85 Fix find_program() in configure
3141fe3 Mark release in source.
bf12327 Improve writability checks. LuaRocks does `mkdir -p` (or equivalent), so we can check for the entire chain of parents for a writable directory. Closes #449.
0b4741a Merge pull request #464 from mpeterv/improve-ext-deps
f59f871 Process external deps in sorted order
5ff2408 Show candidate files when external deps are missing
90d0b9c Merge pull request #462 from Tieske/test_xpol
6c5f261 removed /debug /release switches for setting up the enviornment. it does NOT determine linking against a debug runtime or release runtime.
b2e0340 Merge branch 'test_xpol' of github.com:Tieske/luarocks into test_xpol
30028a3 added debug/release option for SDK detection
2b3fc7c Merge pull request #1 from ignacio/patch-1
9418019 Merge branch 'master' of https://github.com/keplerproject/luarocks
adec4bf Make sure --local always implies --tree=home.
334e8b5 Merge pull request #453 from Tieske/default_config_location
185ec5c Fix typo
fd88e36 updated; - output on checks done - commandline switch to disable the auto-search for ms tools - added debug libs to the SDK search
f00f9c9 Merge branch 'master' of github.com:xpol/luarocks into test_xpol
4bf9303 Merge pull request #455 from Tieske/fix_errormsg
60e536f fix: bad errormessage and missing quotes
9b24922 write config directory only if explictly given, use defaults otherwise
c845958 User assertion for required condition check.
c9ed3e1 Enable batch script delayed expansion and extensions.
2183981 Support Visual Studio Express Editions and cleanup code.
4c3b41e Add support for Windows SDK v7.1 and v6.1.
00184f3 Move mingw test out of get_msvc_env_setup_cmd().
04e4519 Don't setup msvc when user desires MinGW.
a5cec18 Add comments about Windows SDKs.
d4b2ec1 Better msvc compiler setup compatibility.
e5aa0e0 Better setup vc compiler, should compatible with Windows SDK.
7235ad9 Automatically setup MSVC command line tools for VC2008 or above.
git-subtree-dir: luarocks
git-subtree-split: f29297f6f3185158fc81d6137e21ea7e14e43b74
-rw-r--r-- | appveyor.yml | 4 | ||||
-rwxr-xr-x | configure | 6 | ||||
-rw-r--r-- | install.bat | 153 | ||||
-rwxr-xr-x | makedist | 31 | ||||
-rw-r--r-- | rockspec | 2 | ||||
-rw-r--r-- | src/luarocks/cfg.lua | 10 | ||||
-rw-r--r-- | src/luarocks/command_line.lua | 5 | ||||
-rw-r--r-- | src/luarocks/deps.lua | 53 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 23 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 8 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 18 | ||||
-rwxr-xr-x | test/testing.sh | 1 |
12 files changed, 266 insertions, 48 deletions
diff --git a/appveyor.yml b/appveyor.yml index d7fc7cc..3f54135 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,9 @@ -version: 2.2.1.{build}-test +version: 2.3.0.{build}-test shallow_clone: true environment: - LUAROCKS_VER: 2.2.1 + LUAROCKS_VER: 2.3.0 matrix: - LUA_VER: 5.1.5 @@ -71,7 +71,11 @@ EOF # Helper functions find_program() { - command -v "$1" 2>/dev/null + prog=`command -v "$1" 2>/dev/null` + if [ -n "$prog" ] + then + dirname "$prog" + fi } die() { diff --git a/install.bat b/install.bat index 42b01c4..8563f2d 100644 --- a/install.bat +++ b/install.bat @@ -6,8 +6,9 @@ local vars = {} vars.PREFIX = nil
-vars.VERSION = "2.2"
+vars.VERSION = "2.3"
vars.SYSCONFDIR = nil
+vars.SYSCONFFORCE = nil
vars.CONFBACKUPDIR = nil
vars.SYSCONFFILENAME = nil
vars.CONFIG_FILE = nil
@@ -29,11 +30,13 @@ vars.LUA_SHORTV = nil -- "51" vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a"
vars.LUA_RUNTIME = nil
vars.UNAME_M = nil
+vars.COMPILER_ENV_CMD = nil
local FORCE = false
local FORCE_CONFIG = false
local INSTALL_LUA = false
local USE_MINGW = false
+local USE_MSVC_MANUAL = false
local REGISTRY = true
local NOADMIN = false
local PROMPT = true
@@ -166,7 +169,14 @@ Configuring the Lua interpreter: (/LUA, /INC, /LIB, /BIN cannot be used with /L)
Compiler configuration:
-/MW Use mingw as build system instead of MSVC
+ By default the installer will try to determine the
+ Microsoft toolchain to use. And will automatically use
+ a setup command to initialize that toolchain when
+ LuaRocks is run. If it cannot find it, it will default
+ to the /MSVC switch.
+/MSVC Use MS toolchain, without a setup command (tools must
+ be in your path)
+/MW Use mingw as build system (tools must be in your path)
Other options:
/FORCECONFIG Use a single config location. Do not use the
@@ -199,6 +209,7 @@ local function parse_options(args) vars.PREFIX = option.value
elseif name == "/CONFIG" then
vars.SYSCONFDIR = option.value
+ vars.SYSCONFFORCE = true
elseif name == "/TREE" then
vars.TREE_ROOT = option.value
elseif name == "/SCRIPTS" then
@@ -213,6 +224,8 @@ local function parse_options(args) INSTALL_LUA = true
elseif name == "/MW" then
USE_MINGW = true
+ elseif name == "/MSVC" then
+ USE_MSVC_MANUAL = true
elseif name == "/LUA" then
vars.LUA_PREFIX = option.value
elseif name == "/LIB" then
@@ -266,6 +279,9 @@ local function check_flags() die("Bad argument: /LV must either be 5.1, 5.2, or 5.3")
end
end
+ if USE_MSVC_MANUAL and USE_MINGW then
+ die("Cannot combine option /MSVC and /MW")
+ end
end
-- ***********************************************************
@@ -408,6 +424,117 @@ local function get_architecture() return proc
end
+-- get a string value from windows registry.
+local function get_registry(key, value)
+ local keys = {key}
+ local key64, replaced = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1)
+
+ if replaced == 1 then
+ keys = {key64, key}
+ end
+
+ for _, k in ipairs(keys) do
+ local h = io.popen('reg query "'..k..'" /v '..value..' 2>NUL')
+ local output = h:read("*a")
+ h:close()
+
+ local v = output:match("REG_SZ%s+([^\n]+)")
+ if v then
+ return v
+ end
+ end
+ return nil
+end
+
+local function get_visual_studio_directory()
+ assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.")
+ local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR<x><y> or VCRUNTIME<x><y>
+ if not major then
+ print(S[[ Cannot auto-detect Visual Studio version from $LUA_RUNTIME]])
+ return nil
+ end
+ local keys = {
+ "HKLM\\Software\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC",
+ "HKLM\\Software\\Microsoft\\VCExpress\\%d.%d\\Setup\\VS"
+ }
+ for _, key in ipairs(keys) do
+ local versionedkey = key:format(major, minor)
+ local vcdir = get_registry(versionedkey, "ProductDir")
+ print(" checking: "..versionedkey)
+ if vcdir then
+ print(" Found: "..vcdir)
+ return vcdir
+ end
+ end
+ return nil
+end
+
+local function get_windows_sdk_directory()
+ assert(type(vars.LUA_RUNTIME) == "string", "requires vars.LUA_RUNTIME to be set before calling this function.")
+ -- Only v7.1 and v6.1 shipped with compilers
+ -- Other versions requires a separate installation of Visual Studio.
+ -- see https://github.com/keplerproject/luarocks/pull/443#issuecomment-152792516
+ local wsdks = {
+ ["MSVCR100"] = "v7.1", -- shipped with Visual Studio 2010 compilers.
+ ["MSVCR100D"] = "v7.1", -- shipped with Visual Studio 2010 compilers.
+ ["MSVCR90"] = "v6.1", -- shipped with Visual Studio 2008 compilers.
+ ["MSVCR90D"] = "v6.1", -- shipped with Visual Studio 2008 compilers.
+ }
+ local wsdkver = wsdks[vars.LUA_RUNTIME]
+ if not wsdkver then
+ print(S[[ Cannot auto-detect Windows SDK version from $LUA_RUNTIME]])
+ return nil
+ end
+
+ local key = "HKLM\\Software\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver
+ print(" checking: "..key)
+ local dir = get_registry(key, "InstallationFolder")
+ if dir then
+ print(" Found: "..dir)
+ return dir
+ end
+ print(" No SDK found")
+ return nil
+end
+
+-- returns the batch command to setup msvc compiler path.
+-- or an empty string (eg. "") if not found
+local function get_msvc_env_setup_cmd()
+ print(S[[Looking for Microsoft toolchain matching runtime $LUA_RUNTIME and architecture $UNAME_M]])
+
+ assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.")
+ local x64 = vars.UNAME_M=="x86_64"
+
+ -- 1. try visual studio command line tools
+ local vcdir = get_visual_studio_directory()
+ if vcdir then
+ -- 1.1. try vcvarsall.bat
+ local vcvarsall = vcdir .. 'vcvarsall.bat'
+ if exists(vcvarsall) then
+ return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '')
+ end
+
+ -- 1.2. try vcvars32.bat / vcvars64.bat
+ local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat"
+ local full_path = vcdir .. relative_path
+ if exists(full_path) then
+ return ('call "%s"'):format(full_path)
+ end
+ end
+
+ -- 2. try for Windows SDKs command line tools.
+ local wsdkdir = get_windows_sdk_directory()
+ if wsdkdir then
+ local setenv = wsdkdir.."Bin\\SetEnv.cmd"
+ if exists(setenv) then
+ return ('call "%s" /%s'):format(setenv, x64 and "x64" or "x86")
+ end
+ end
+
+ -- finally, we can't detect more, just don't setup the msvc compiler in luarocks.bat.
+ return ""
+end
+
local function look_for_lua_install ()
print("Looking for Lua interpreter")
local directories
@@ -650,9 +777,11 @@ vars.SYSCONFFILENAME = S"config-$LUA_VERSION.lua" vars.CONFIG_FILE = vars.SYSCONFDIR.."\\"..vars.SYSCONFFILENAME
if SELFCONTAINED then
vars.SYSCONFDIR = vars.PREFIX
+ vars.SYSCONFFORCE = true
vars.TREE_ROOT = vars.PREFIX..[[\systree]]
REGISTRY = false
end
+vars.COMPILER_ENV_CMD = (USE_MINGW and "") or (USE_MSVC_MANUAL and "") or get_msvc_env_setup_cmd()
print(S[[
@@ -671,11 +800,20 @@ Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER includes : $LUA_INCDIR
architecture: $UNAME_M
binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll
-
]])
+if USE_MINGW then
+ print("Compiler : MinGW (make sure it is in your path before using LuaRocks)")
+else
+ if vars.COMPILER_ENV_CMD == "" then
+ print("Compiler : Microsoft (make sure it is in your path before using LuaRocks)")
+ else
+ print(S[[Compiler : Microsoft, using; $COMPILER_ENV_CMD]])
+ end
+end
+
if PROMPT then
- print("Press <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.")
+ print("\nPress <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.")
io.read()
end
@@ -758,7 +896,8 @@ for _, c in ipairs{"luarocks", "luarocks-admin"} do local f = io.open(vars.BINDIR.."\\"..c..".bat", "w")
f:write(S[[
@ECHO OFF
-SETLOCAL
+SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
+$COMPILER_ENV_CMD
SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%"
IF NOT "%LUA_PATH_5_2%"=="" (
SET "LUA_PATH_5_2=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_2%"
@@ -835,7 +974,6 @@ else end
f:write(S[=[
site_config.LUAROCKS_UNAME_M=[[$UNAME_M]]
-site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]
site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]]
site_config.LUAROCKS_PREFIX=[[$PREFIX]]
site_config.LUAROCKS_DOWNLOADER=[[wget]]
@@ -844,6 +982,9 @@ site_config.LUAROCKS_MD5CHECKER=[[md5sum]] if FORCE_CONFIG then
f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n")
end
+if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults
+ f:write(S("site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]\n"))
+end
f:write("return site_config\n")
f:close()
print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]]))
@@ -16,13 +16,40 @@ make clean || exit 1 grep -q "\"$1\"" rockspec || { echo - echo "Version in rockspec is incorrect. Please fix it." + echo "version in rockspec is incorrect. Please fix it." exit 1 } grep -q "program_version = \"$1\"" src/luarocks/cfg.lua || { echo - echo "Version in src/luarocks/cfg.lua is incorrect. Please fix it." + echo "program_version in src/luarocks/cfg.lua is incorrect. Please fix it." + exit 1 +} + +grep -q "version: $1\\." appveyor.yml || { + echo + echo "version in appveyor.yml is incorrect. Please fix it." + exit 1 +} + +grep -q "LUAROCKS_VER: $1" appveyor.yml || { + echo + echo "LUAROCKS_VER in appveyor.yml is incorrect. Please fix it." + exit 1 +} + +# e.g. if $1 is "2.3.0", $program_series is "2.3" +program_series=${1%.*} + +grep -q "program_series = \"$program_series\"" src/luarocks/cfg.lua || { + echo + echo "program_series in src/luarocks/cfg.lua is incorrect. Please fix it." + exit 1 +} + +grep -q "vars.VERSION = \"$program_series\"" install.bat || { + echo + echo "vars.VERSION in install.bat is incorrect. Please fix it." exit 1 } @@ -1,5 +1,5 @@ package = "LuaRocks" -local VER = "scm" +local VER = "2.3.0" version = VER .. "-1" source = { diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index e3d6e74..48acd93 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -32,8 +32,8 @@ if not ok then site_config = {} end -cfg.program_version = "scm" -cfg.program_series = "2.2" +cfg.program_version = "2.3.0" +cfg.program_series = "2.3" cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series cfg.variables = {} cfg.rocks_trees = {} @@ -149,7 +149,7 @@ local sys_config_file_default, home_config_file_default local sys_config_dir, home_config_dir local sys_config_ok, home_config_ok = false, false local extra_luarocks_module_dir -sys_config_dir = site_config.LUAROCKS_SYSCONFDIR +sys_config_dir = site_config.LUAROCKS_SYSCONFDIR or site_config.LUAROCKS_PREFIX if cfg.platforms.windows then cfg.home = os.getenv("APPDATA") or "c:" sys_config_dir = sys_config_dir or "c:/luarocks" @@ -663,7 +663,7 @@ function cfg.init_package_paths() end function cfg.which_config() - return { + local ret = { system = { file = sys_config_file or sys_config_file_default, ok = sys_config_ok, @@ -673,6 +673,8 @@ function cfg.which_config() ok = home_config_ok, } } + ret.nearest = (ret.user.ok and ret.user.file) or ret.system.file + return ret end cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index dbf64b9..e1c9f49 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -31,12 +31,17 @@ end local function replace_tree(flags, args, tree) tree = dir.normalize(tree) flags["tree"] = tree + local added = false for i = 1, #args do if args[i]:match("%-%-tree=") then args[i] = "--tree="..tree + added = true break end end + if not added then + args[#args + 1] = "--tree="..tree + end path.use_tree(tree) end diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 0e3265b..eb01075 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -545,10 +545,11 @@ function deps.check_external_deps(rockspec, mode) subdirs = cfg.runtime_external_deps_subdirs end if rockspec.external_dependencies then - for name, files in pairs(rockspec.external_dependencies) do + for name, ext_files in util.sortedpairs(rockspec.external_dependencies) do local ok = true - local failed_file = nil - local failed_dirname = nil + local failed_files = {program = {}, header = {}, library = {}} + local failed_dirname + local failed_testfile for _, extdir in ipairs(cfg.external_deps_dirs) do ok = true local prefix = vars[name.."_DIR"] @@ -577,7 +578,7 @@ function deps.check_external_deps(rockspec, mode) end prefix = prefix.prefix end - for dirname, dirdata in pairs(dirs) do + for dirname, dirdata in util.sortedpairs(dirs) do local paths local path_var_value = vars[name.."_"..dirname] if path_var_value then @@ -591,7 +592,7 @@ function deps.check_external_deps(rockspec, mode) paths = { dir.path(prefix, dirdata.subdir) } end dirdata.dir = paths[1] - local file = files[dirdata.testfile] + local file = ext_files[dirdata.testfile] if file then local files = {} if not file:match("%.") then @@ -606,19 +607,23 @@ function deps.check_external_deps(rockspec, mode) table.insert(files, file) end local found = false - failed_file = nil - for _, f in pairs(files) do - + for _, f in ipairs(files) do + -- small convenience hack if f:match("%.so$") or f:match("%.dylib$") or f:match("%.dll$") then f = f:gsub("%.[^.]+$", "."..cfg.external_lib_extension) end - + + local pattern + if f:match("%*") then + pattern = f:gsub("%.", "%%."):gsub("%*", ".*") + f = "matching "..f + end + for _, d in ipairs(paths) do - if f:match("%*") then - local replaced = f:gsub("%.", "%%."):gsub("%*", ".*") + if pattern then for entry in fs.dir(d) do - if entry:match(replaced) then + if entry:match(pattern) then found = true break end @@ -629,21 +634,18 @@ function deps.check_external_deps(rockspec, mode) if found then dirdata.dir = d break + else + table.insert(failed_files[dirdata.testfile], f.." in "..d) end end if found then break - else - if failed_file then - failed_file = failed_file .. ", or " .. f - else - failed_file = f - end end end if not found then ok = false failed_dirname = dirname + failed_testfile = dirdata.testfile break end end @@ -657,7 +659,20 @@ function deps.check_external_deps(rockspec, mode) end end if not ok then - return nil, "Could not find expected file "..failed_file.." for "..name.." -- you may have to install "..name.." in your system and/or pass "..name.."_DIR or "..name.."_"..failed_dirname.." to the luarocks command. Example: luarocks install "..rockspec.name.." "..name.."_DIR=/usr/local", "dependency" + local lines = {"Could not find "..failed_testfile.." file for "..name} + + local failed_paths = {} + for _, failed_file in ipairs(failed_files[failed_testfile]) do + if not failed_paths[failed_file] then + failed_paths[failed_file] = true + table.insert(lines, " No file "..failed_file) + end + end + + table.insert(lines, "You may have to install "..name.." in your system and/or pass "..name.."_DIR or "..name.."_"..failed_dirname.." to the luarocks command.") + table.insert(lines, "Example: luarocks install "..rockspec.name.." "..name.."_DIR=/usr/local") + + return nil, table.concat(lines, "\n"), "dependency" end end end diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 73ae269..a444f01 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -134,10 +134,10 @@ function fs_lua.is_tool_available(tool_cmd, tool_name, arg) arg = arg or "--version" assert(type(arg) == "string") - if not fs.execute_quiet(tool_cmd, arg) then + if not fs.execute_quiet(fs.Q(tool_cmd), arg) then local msg = "'%s' program not found. Make sure %s is installed and is available in your PATH " .. - "(or you may want to edit the 'variables.%s' value in file 'config.lua')" - return nil, msg:format(tool_cmd, tool_name, tool_cmd:upper()) + "(or you may want to edit the 'variables.%s' value in file '%s')" + return nil, msg:format(tool_cmd, tool_name, tool_name:upper(), cfg.which_config().nearest) else return true end @@ -833,10 +833,19 @@ function fs_lua.check_command_permissions(flags) break end end - local root_parent = dir.dir_name(root_dir) - if ok and not fs.exists(root_dir) and not fs.is_writable(root_parent) then - ok = false - err = root_dir.." does not exist and your user does not have write permissions in " .. root_parent + if ok and not fs.exists(root_dir) then + local root = fs.root_of(root_dir) + local parent = root_dir + repeat + parent = dir.dir_name(parent) + if parent == "" then + parent = root + end + until parent == root or fs.exists(parent) + if not fs.is_writable(parent) then + ok = false + err = root_dir.." does not exist and your user does not have write permissions in " .. parent + end end if ok then return true diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 6ad5a67..8eb3386 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -36,6 +36,14 @@ function unix.absolute_name(pathname, relative_to) end end +--- Return the root directory for the given path. +-- In Unix, root is always "/". +-- @param pathname string: pathname to use. +-- @return string: The root of the given pathname. +function unix.root_of(_) + return "/" +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. diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 32766e5..0c8cc9e 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -18,7 +18,6 @@ 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. @@ -26,6 +25,7 @@ function win32.quiet(cmd) return cmd.." 2> NUL 1> NUL" end +local drive_letter = "[%.a-zA-Z]?:?[\\/]" local win_escape_chars = { ["%"] = "%%", @@ -47,7 +47,7 @@ end function win32.Q(arg) assert(type(arg) == "string") -- Quote DIR for Windows - if arg:match("^[%.a-zA-Z]?:?[\\/]") then + if arg:match("^"..drive_letter) then arg = arg:gsub("/", "\\") end if arg == "\\" then @@ -68,7 +68,7 @@ end function win32.Qb(arg) assert(type(arg) == "string") -- Quote DIR for Windows - if arg:match("^[%.a-zA-Z]?:?[\\/]") then + if arg:match("^"..drive_letter) then arg = arg:gsub("/", "\\") end if arg == "\\" then @@ -92,15 +92,21 @@ function win32.absolute_name(pathname, relative_to) 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 + if pathname:match("^"..drive_letter) then return pathname else return relative_to .. "/" .. pathname end end +--- Return the root directory for the given path. +-- For example, for "c:\hello", returns "c:\" +-- @param pathname string: pathname to use. +-- @return string: The root of the given pathname. +function win32.root_of(pathname) + return (fs.absolute_name(pathname):match("^("..drive_letter..")")) +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. diff --git a/test/testing.sh b/test/testing.sh index 26bdde5..70bd68b 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -244,6 +244,7 @@ mkdir -p "$testing_server" get "$luarocks_repo/validate-args-1.5.4-1.rockspec" get "$luarocks_repo/luasec-0.5-2.rockspec" get "$luarocks_repo/luabitop-1.0.2-1.rockspec" + get "$luarocks_repo/luabitop-1.0.2-1.src.rock" get "$luarocks_repo/lpty-1.0.1-1.src.rock" get "$luarocks_repo/cprint-${verrev_cprint}.src.rock" get "$luarocks_repo/cprint-${verrev_cprint}.rockspec" |