aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appveyor.yml7
-rwxr-xr-xconfigure2
-rw-r--r--install.bat35
-rw-r--r--src/luarocks/cfg.lua230
-rw-r--r--src/luarocks/fetch.lua7
-rw-r--r--src/luarocks/fetch/git.lua2
-rw-r--r--src/luarocks/tools/zip.lua2
-rw-r--r--test/testing.lua12
-rwxr-xr-xtest/testing.sh13
-rw-r--r--win32/pe-parser.lua5
10 files changed, 196 insertions, 119 deletions
diff --git a/appveyor.yml b/appveyor.yml
index abf15af6..d7fc7cc2 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,8 +1,5 @@
1version: 2.2.1.{build}-test 1version: 2.2.1.{build}-test
2 2
3os:
4- Windows Server 2012 R2
5
6shallow_clone: true 3shallow_clone: true
7 4
8environment: 5environment:
@@ -17,8 +14,8 @@ environment:
17 14
18init: 15init:
19# Setup Lua development/build environment 16# Setup Lua development/build environment
20# Make VS 2013 command line tools available 17# Make VS 2015 command line tools available
21- call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" %platform% 18- call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %platform%
22 19
23install: 20install:
24# Setup Lua development/build environment 21# Setup Lua development/build environment
diff --git a/configure b/configure
index 7916749f..bd962edf 100755
--- a/configure
+++ b/configure
@@ -40,7 +40,7 @@ system's package manager.
40 Default is \$PREFIX 40 Default is \$PREFIX
41 41
42--lua-version=VERSION Use specific Lua version: 5.1, 5.2, or 5.3 42--lua-version=VERSION Use specific Lua version: 5.1, 5.2, or 5.3
43 Default is "$LUA_VERSION" 43 Default is auto-detected.
44--lua-suffix=SUFFIX Versioning suffix to use in Lua filenames. 44--lua-suffix=SUFFIX Versioning suffix to use in Lua filenames.
45 Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...) 45 Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...)
46--with-lua=PREFIX Use Lua from given prefix. 46--with-lua=PREFIX Use Lua from given prefix.
diff --git a/install.bat b/install.bat
index d83dfbf1..57e3611c 100644
--- a/install.bat
+++ b/install.bat
@@ -8,6 +8,8 @@ local vars = {}
8vars.PREFIX = nil 8vars.PREFIX = nil
9vars.VERSION = "2.2" 9vars.VERSION = "2.2"
10vars.SYSCONFDIR = nil 10vars.SYSCONFDIR = nil
11vars.SYSCONFFILENAME = nil
12vars.CONFIG_FILE = nil
11vars.TREE_ROOT = nil 13vars.TREE_ROOT = nil
12vars.TREE_BIN = nil 14vars.TREE_BIN = nil
13vars.TREE_LMODULE = nil 15vars.TREE_LMODULE = nil
@@ -360,7 +362,14 @@ local function look_for_headers (directory)
360 die(S"lua.h not found in $LUA_INCDIR") 362 die(S"lua.h not found in $LUA_INCDIR")
361 end 363 end
362 364
363 for _, e in ipairs{ [[\]], [[\include\]]} do 365 for _, e in ipairs{
366 S([[\include\lua\$LUA_VERSION]]),
367 S([[\include\lua$LUA_SHORTV]]),
368 S([[\include\lua$LUA_VERSION]]),
369 S([[\include\$LUA_VERSION]]),
370 [[\include\]],
371 [[\]],
372 } do
364 print(" checking for "..directory..e.."\\lua.h") 373 print(" checking for "..directory..e.."\\lua.h")
365 if exists(directory..e.."\\lua.h") then 374 if exists(directory..e.."\\lua.h") then
366 vars.LUA_INCDIR = directory..e 375 vars.LUA_INCDIR = directory..e
@@ -610,6 +619,8 @@ else
610 datapath = os.getenv("ProgramW6432") .. [[\LuaRocks]] 619 datapath = os.getenv("ProgramW6432") .. [[\LuaRocks]]
611end 620end
612vars.SYSCONFDIR = vars.SYSCONFDIR or vars.PREFIX 621vars.SYSCONFDIR = vars.SYSCONFDIR or vars.PREFIX
622vars.SYSCONFFILENAME = S"config-$LUA_VERSION.lua"
623vars.CONFIG_FILE = vars.SYSCONFDIR.."\\"..vars.SYSCONFFILENAME
613vars.TREE_ROOT = vars.TREE_ROOT or datapath..[[\systree]] 624vars.TREE_ROOT = vars.TREE_ROOT or datapath..[[\systree]]
614if SELFCONTAINED then 625if SELFCONTAINED then
615 vars.SYSCONFDIR = vars.PREFIX 626 vars.SYSCONFDIR = vars.PREFIX
@@ -625,7 +636,7 @@ print(S[[
625 636
626Will configure LuaRocks with the following paths: 637Will configure LuaRocks with the following paths:
627LuaRocks : $FULL_PREFIX 638LuaRocks : $FULL_PREFIX
628Config file : $SYSCONFDIR\config.lua 639Config file : $CONFIG_FILE
629Rocktree : $TREE_ROOT 640Rocktree : $TREE_ROOT
630 641
631Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER 642Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER
@@ -793,10 +804,11 @@ print()
793print("Configuring LuaRocks...") 804print("Configuring LuaRocks...")
794 805
795-- Create a site-config file 806-- Create a site-config file
796if exists(S[[$LUADIR\luarocks\site_config.lua]]) then 807local site_config = S("site_config_$LUA_VERSION"):gsub("%.","_")
797 exec(S[[RENAME "$LUADIR\luarocks\site_config.lua" site_config.lua.bak]]) 808if exists(S([[$LUADIR\luarocks\]]..site_config..[[.lua]])) then
809 exec(S([[RENAME "$LUADIR\luarocks\]]..site_config..[[.lua" site_config.lua.bak]]))
798end 810end
799local f = io.open(vars.LUADIR.."\\luarocks\\site_config.lua", "w") 811local f = io.open(vars.LUADIR.."\\luarocks\\"..site_config..".lua", "w")
800f:write(S[=[ 812f:write(S[=[
801local site_config = {} 813local site_config = {}
802site_config.LUA_INCDIR=[[$LUA_INCDIR]] 814site_config.LUA_INCDIR=[[$LUA_INCDIR]]
@@ -811,7 +823,7 @@ else
811end 823end
812f:write(S[=[ 824f:write(S[=[
813site_config.LUAROCKS_UNAME_M=[[$UNAME_M]] 825site_config.LUAROCKS_UNAME_M=[[$UNAME_M]]
814site_config.LUAROCKS_SYSCONFIG=[[$SYSCONFDIR\config.lua]] 826site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]
815site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]] 827site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]]
816site_config.LUAROCKS_PREFIX=[[$PREFIX]] 828site_config.LUAROCKS_PREFIX=[[$PREFIX]]
817site_config.LUAROCKS_DOWNLOADER=[[wget]] 829site_config.LUAROCKS_DOWNLOADER=[[wget]]
@@ -820,24 +832,23 @@ site_config.LUAROCKS_MD5CHECKER=[[md5sum]]
820if FORCE_CONFIG then 832if FORCE_CONFIG then
821 f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") 833 f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n")
822end 834end
823if exists(vars.LUADIR.."\\luarocks\\site_config.lua.bak") then 835if exists(vars.LUADIR.."\\luarocks\\"..site_config..".lua.bak") then
824 for line in io.lines(vars.LUADIR.."\\luarocks\\site_config.lua.bak", "r") do 836 for line in io.lines(vars.LUADIR.."\\luarocks\\"..site_config..".lua.bak", "r") do
825 f:write(line) 837 f:write(line)
826 f:write("\n") 838 f:write("\n")
827 end 839 end
828 exec(S[[DEL /F /Q "$LUADIR\luarocks\site_config.lua.bak"]]) 840 exec(S([[DEL /F /Q "$LUADIR\luarocks\]]..site_config..[[.lua.bak"]]))
829end 841end
830f:write("return site_config\n") 842f:write("return site_config\n")
831f:close() 843f:close()
832print(S[[Created LuaRocks site-config file: $LUADIR\luarocks\site_config.lua]]) 844print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]]))
833 845
834-- create config file 846-- create config file
835vars.CONFIG_FILE = vars.SYSCONFDIR.."\\config.lua"
836if not exists(vars.SYSCONFDIR) then 847if not exists(vars.SYSCONFDIR) then
837 mkdir(vars.SYSCONFDIR) 848 mkdir(vars.SYSCONFDIR)
838end 849end
839if exists(vars.CONFIG_FILE) then 850if exists(vars.CONFIG_FILE) then
840 local nname = backup(vars.CONFIG_FILE, "config.bak") 851 local nname = backup(vars.CONFIG_FILE, vars.SYSCONFFILENAME..".bak")
841 print("***************") 852 print("***************")
842 print(S"*** WARNING *** LuaRocks config file already exists: '$CONFIG_FILE'. The old file has been renamed to '"..nname.."'") 853 print(S"*** WARNING *** LuaRocks config file already exists: '$CONFIG_FILE'. The old file has been renamed to '"..nname.."'")
843 print("***************") 854 print("***************")
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 8321e9b9..31b3211a 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -35,6 +35,9 @@ end
35cfg.program_version = "scm" 35cfg.program_version = "scm"
36cfg.program_series = "2.2" 36cfg.program_series = "2.2"
37cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series 37cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series
38cfg.variables = {}
39cfg.rocks_trees = {}
40cfg.platforms = {}
38 41
39local persist = require("luarocks.persist") 42local persist = require("luarocks.persist")
40 43
@@ -68,68 +71,86 @@ end
68 71
69-- System detection: 72-- System detection:
70 73
71local detected = {}
72local system,proc
73
74-- A proper installation of LuaRocks will hardcode the system 74-- A proper installation of LuaRocks will hardcode the system
75-- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M, 75-- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M,
76-- so that this detection does not run every time. When it is 76-- so that this detection does not run every time. When it is
77-- performed, we use the Unix way to identify the system, 77-- performed, we use the Unix way to identify the system,
78-- even on Windows (assuming UnxUtils or Cygwin). 78-- even on Windows (assuming UnxUtils or Cygwin).
79system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") 79local system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l")
80proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") 80local proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l")
81if proc:match("i[%d]86") then 81if proc:match("i[%d]86") then
82 proc = "x86" 82 cfg.target_cpu = "x86"
83elseif proc:match("amd64") or proc:match("x86_64") then 83elseif proc:match("amd64") or proc:match("x86_64") then
84 proc = "x86_64" 84 cfg.target_cpu = "x86_64"
85elseif proc:match("Power Macintosh") then 85elseif proc:match("Power Macintosh") then
86 proc = "powerpc" 86 cfg.target_cpu = "powerpc"
87 else
88 cfg.target_cpu = proc
87end 89end
88cfg.target_cpu = proc
89 90
90if system == "FreeBSD" then 91if system == "FreeBSD" then
91 detected.unix = true 92 cfg.platforms.unix = true
92 detected.freebsd = true 93 cfg.platforms.freebsd = true
93 detected.bsd = true 94 cfg.platforms.bsd = true
94elseif system == "OpenBSD" then 95elseif system == "OpenBSD" then
95 detected.unix = true 96 cfg.platforms.unix = true
96 detected.openbsd = true 97 cfg.platforms.openbsd = true
97 detected.bsd = true 98 cfg.platforms.bsd = true
98elseif system == "NetBSD" then 99elseif system == "NetBSD" then
99 detected.unix = true 100 cfg.platforms.unix = true
100 detected.netbsd = true 101 cfg.platforms.netbsd = true
101 detected.bsd = true 102 cfg.platforms.bsd = true
102elseif system == "Darwin" then 103elseif system == "Darwin" then
103 detected.unix = true 104 cfg.platforms.unix = true
104 detected.macosx = true 105 cfg.platforms.macosx = true
105 detected.bsd = true 106 cfg.platforms.bsd = true
106elseif system == "Linux" then 107elseif system == "Linux" then
107 detected.unix = true 108 cfg.platforms.unix = true
108 detected.linux = true 109 cfg.platforms.linux = true
109elseif system == "SunOS" then 110elseif system == "SunOS" then
110 detected.unix = true 111 cfg.platforms.unix = true
111 detected.solaris = true 112 cfg.platforms.solaris = true
112elseif system and system:match("^CYGWIN") then 113elseif system and system:match("^CYGWIN") then
113 detected.unix = true 114 cfg.platforms.unix = true
114 detected.cygwin = true 115 cfg.platforms.cygwin = true
115elseif system and system:match("^Windows") then 116elseif system and system:match("^Windows") then
116 detected.windows = true 117 cfg.platforms.windows = true
118 cfg.platforms.win32 = true
117elseif system and system:match("^MINGW") then 119elseif system and system:match("^MINGW") then
118 detected.windows = true 120 cfg.platforms.windows = true
119 detected.mingw32 = true 121 cfg.platforms.mingw32 = true
122 cfg.platforms.win32 = true
120else 123else
121 detected.unix = true 124 cfg.platforms.unix = true
122 -- Fall back to Unix in unknown systems. 125 -- Fall back to Unix in unknown systems.
123end 126end
124 127
125-- Path configuration: 128-- Set order for platform overrides
129local platform_order = {
130 -- Unixes
131 unix = 1,
132 bsd = 2,
133 solaris = 3,
134 netbsd = 4,
135 openbsd = 5,
136 freebsd = 6,
137 linux = 7,
138 macosx = 8,
139 cygwin = 9,
140 -- Windows
141 win32 = 10,
142 mingw32 = 11,
143 windows = 12 }
144
126 145
146-- Path configuration:
127local sys_config_file, home_config_file 147local sys_config_file, home_config_file
148local sys_config_file_default, home_config_file_default
128local sys_config_dir, home_config_dir 149local sys_config_dir, home_config_dir
129local sys_config_ok, home_config_ok = false, false 150local sys_config_ok, home_config_ok = false, false
130local extra_luarocks_module_dir 151local extra_luarocks_module_dir
131sys_config_dir = site_config.LUAROCKS_SYSCONFDIR 152sys_config_dir = site_config.LUAROCKS_SYSCONFDIR
132if detected.windows then 153if cfg.platforms.windows then
133 cfg.home = os.getenv("APPDATA") or "c:" 154 cfg.home = os.getenv("APPDATA") or "c:"
134 sys_config_dir = sys_config_dir or "c:/luarocks" 155 sys_config_dir = sys_config_dir or "c:/luarocks"
135 home_config_dir = cfg.home.."/luarocks" 156 home_config_dir = cfg.home.."/luarocks"
@@ -141,16 +162,13 @@ else
141 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/" 162 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/"
142end 163end
143 164
144cfg.variables = {}
145cfg.rocks_trees = {}
146
147-- Create global environment for the config files; 165-- Create global environment for the config files;
148local env_for_config_file = function() 166local env_for_config_file = function()
149 local e 167 local e
150 e = { 168 e = {
151 home = cfg.home, 169 home = cfg.home,
152 lua_version = cfg.lua_version, 170 lua_version = cfg.lua_version,
153 platform = util.make_shallow_copy(detected), 171 platforms = util.make_shallow_copy(cfg.platforms),
154 processor = cfg.target_cpu, -- remains for compat reasons 172 processor = cfg.target_cpu, -- remains for compat reasons
155 target_cpu = cfg.target_cpu, -- replaces `processor` 173 target_cpu = cfg.target_cpu, -- replaces `processor`
156 os_getenv = os.getenv, 174 os_getenv = os.getenv,
@@ -175,49 +193,55 @@ local merge_overrides = function(overrides)
175 util.deep_merge(cfg, overrides) 193 util.deep_merge(cfg, overrides)
176end 194end
177 195
178sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" 196-- load config file from a list until first succesful one. Info is
179do 197-- added to `cfg` module table, returns filepath of succesfully loaded
180 local err, errcode 198-- file or nil if it failed
181 sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file()) 199local load_config_file = function(list)
182 if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file 200 for _, filepath in ipairs(list) do
183 sys_config_file = sys_config_dir.."/config.lua" 201 local result, err, errcode = persist.load_into_table(filepath, env_for_config_file())
184 sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file()) 202 if (not result) and errcode ~= "open" then
185 end 203 -- errcode is either "load" or "run"; bad config file, so error out
186 if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error 204 io.stderr:write(err.."\n")
187 io.stderr:write(err.."\n") 205 os.exit(cfg.errorcodes.CONFIGFILE)
188 os.exit(cfg.errorcodes.CONFIGFILE) 206 end
189 end 207 if result then
190 if sys_config_ok then 208 -- succes in loading and running, merge contents and exit
191 merge_overrides(sys_config_ok) 209 merge_overrides(result)
210 return filepath
211 end
192 end 212 end
213 return nil -- nothing was loaded
214end
215
216
217-- Load system configuration file
218do
219 sys_config_file_default = sys_config_dir.."/config-"..cfg.lua_version..".lua"
220 sys_config_file = load_config_file({
221 site_config.LUAROCKS_SYSCONFIG or sys_config_file_default,
222 sys_config_dir.."/config.lua",
223 })
224 sys_config_ok = (sys_config_file ~= nil)
193end 225end
194 226
227-- Load user configuration file (if allowed)
195if not site_config.LUAROCKS_FORCE_CONFIG then 228if not site_config.LUAROCKS_FORCE_CONFIG then
229
230 home_config_file_default = home_config_dir.."/config-"..cfg.lua_version..".lua"
231 local list = {
232 os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG"),
233 home_config_file_default,
234 home_config_dir.."/config.lua",
235 }
236 -- first entry might be a silent nil, check and remove if so
237 if not list[1] then table.remove(list, 1) end
238
239 home_config_file = load_config_file(list)
240 home_config_ok = (home_config_file ~= nil)
196 241
197 local home_overrides, err, errcode
198 home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG")
199 if home_config_file then
200 home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file())
201 else
202 home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua"
203 home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file())
204 if (not home_overrides) and (not errcode == "run") then
205 home_config_file = home_config_dir.."/config.lua"
206 home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file())
207 end
208 end
209 if home_overrides then
210 home_config_ok = true
211 merge_overrides(home_overrides)
212 else
213 home_config_ok = home_overrides
214 if errcode ~= "open" then
215 io.stderr:write(err.."\n")
216 os.exit(cfg.errorcodes.CONFIGFILE)
217 end
218 end
219end 242end
220 243
244
221if not next(cfg.rocks_trees) then 245if not next(cfg.rocks_trees) then
222 if cfg.home_tree then 246 if cfg.home_tree then
223 table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } ) 247 table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } )
@@ -227,8 +251,29 @@ if not next(cfg.rocks_trees) then
227 end 251 end
228end 252end
229 253
230-- Configure defaults:
231 254
255-- update platforms list; keyed -> array
256do
257 local lst = {} -- use temp array to not confuse `pairs` in loop
258 for plat in pairs(cfg.platforms) do
259 if cfg.platforms[plat] then -- entries set to 'false' skipped
260 if not platform_order[plat] then
261 local pl = ""
262 for k,_ in pairs(platform_order) do pl = pl .. ", " .. k end
263 io.stderr:write("Bad platform given; "..tostring(plat)..". Valid entries are: "..pl:sub(3,-1) ..".\n")
264 os.exit(cfg.errorcodes.CONFIGFILE)
265 end
266 table.insert(lst, plat)
267 else
268 cfg.platforms[plat] = nil
269 end
270 end
271 -- platform overrides depent on the order, so set priorities
272 table.sort(lst, function(key1, key2) return platform_order[key1] < platform_order[key2] end)
273 util.deep_merge(cfg.platforms, lst)
274end
275
276-- Configure defaults:
232local defaults = { 277local defaults = {
233 278
234 local_by_default = false, 279 local_by_default = false,
@@ -328,14 +373,13 @@ local defaults = {
328 rocks_provided = {} 373 rocks_provided = {}
329} 374}
330 375
331if detected.windows then 376if cfg.platforms.windows then
332 local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])).."\\"..cfg.major_version 377 local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])).."\\"..cfg.major_version
333 extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua" 378 extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua"
334 379
335 home_config_file = home_config_file and home_config_file:gsub("\\","/") 380 home_config_file = home_config_file and home_config_file:gsub("\\","/")
336 defaults.fs_use_modules = false 381 defaults.fs_use_modules = false
337 defaults.arch = "win32-"..cfg.target_cpu 382 defaults.arch = "win32-"..cfg.target_cpu
338 defaults.platforms = {"win32", "windows" }
339 defaults.lib_extension = "dll" 383 defaults.lib_extension = "dll"
340 defaults.external_lib_extension = "dll" 384 defaults.external_lib_extension = "dll"
341 defaults.obj_extension = "obj" 385 defaults.obj_extension = "obj"
@@ -388,8 +432,7 @@ if detected.windows then
388 defaults.web_browser = "start" 432 defaults.web_browser = "start"
389end 433end
390 434
391if detected.mingw32 then 435if cfg.platforms.mingw32 then
392 defaults.platforms = { "win32", "mingw32", "windows" }
393 defaults.obj_extension = "o" 436 defaults.obj_extension = "o"
394 defaults.cmake_generator = "MinGW Makefiles" 437 defaults.cmake_generator = "MinGW Makefiles"
395 defaults.variables.MAKE = "mingw32-make" 438 defaults.variables.MAKE = "mingw32-make"
@@ -413,7 +456,7 @@ if detected.mingw32 then
413 456
414end 457end
415 458
416if detected.unix then 459if cfg.platforms.unix then
417 defaults.lib_extension = "so" 460 defaults.lib_extension = "so"
418 defaults.external_lib_extension = "so" 461 defaults.external_lib_extension = "so"
419 defaults.obj_extension = "o" 462 defaults.obj_extension = "o"
@@ -423,7 +466,6 @@ if detected.unix then
423 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR or "/usr/local/lib" 466 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR or "/usr/local/lib"
424 defaults.variables.CFLAGS = "-O2" 467 defaults.variables.CFLAGS = "-O2"
425 defaults.cmake_generator = "Unix Makefiles" 468 defaults.cmake_generator = "Unix Makefiles"
426 defaults.platforms = { "unix" }
427 defaults.variables.CC = "gcc" 469 defaults.variables.CC = "gcc"
428 defaults.variables.LD = "gcc" 470 defaults.variables.LD = "gcc"
429 defaults.gcc_rpath = true 471 defaults.gcc_rpath = true
@@ -450,26 +492,24 @@ if detected.unix then
450 defaults.web_browser = "xdg-open" 492 defaults.web_browser = "xdg-open"
451end 493end
452 494
453if detected.cygwin then 495if cfg.platforms.cygwin then
454 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds 496 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds
455 defaults.arch = "cygwin-"..cfg.target_cpu 497 defaults.arch = "cygwin-"..cfg.target_cpu
456 defaults.platforms = {"unix", "cygwin"}
457 defaults.cmake_generator = "Unix Makefiles" 498 defaults.cmake_generator = "Unix Makefiles"
458 defaults.variables.CC = "echo -llua | xargs gcc" 499 defaults.variables.CC = "echo -llua | xargs gcc"
459 defaults.variables.LD = "echo -llua | xargs gcc" 500 defaults.variables.LD = "echo -llua | xargs gcc"
460 defaults.variables.LIBFLAG = "-shared" 501 defaults.variables.LIBFLAG = "-shared"
461end 502end
462 503
463if detected.bsd then 504if cfg.platforms.bsd then
464 defaults.variables.MAKE = "gmake" 505 defaults.variables.MAKE = "gmake"
465 defaults.variables.STATFLAG = "-f '%OLp'" 506 defaults.variables.STATFLAG = "-f '%OLp'"
466end 507end
467 508
468if detected.macosx then 509if cfg.platforms.macosx then
469 defaults.variables.MAKE = "make" 510 defaults.variables.MAKE = "make"
470 defaults.external_lib_extension = "dylib" 511 defaults.external_lib_extension = "dylib"
471 defaults.arch = "macosx-"..cfg.target_cpu 512 defaults.arch = "macosx-"..cfg.target_cpu
472 defaults.platforms = {"unix", "bsd", "macosx"}
473 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" 513 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load"
474 defaults.variables.STAT = "/usr/bin/stat" 514 defaults.variables.STAT = "/usr/bin/stat"
475 defaults.variables.STATFLAG = "-f '%A'" 515 defaults.variables.STATFLAG = "-f '%A'"
@@ -487,32 +527,28 @@ if detected.macosx then
487 defaults.web_browser = "open" 527 defaults.web_browser = "open"
488end 528end
489 529
490if detected.linux then 530if cfg.platforms.linux then
491 defaults.arch = "linux-"..cfg.target_cpu 531 defaults.arch = "linux-"..cfg.target_cpu
492 defaults.platforms = {"unix", "linux"}
493end 532end
494 533
495if detected.freebsd then 534if cfg.platforms.freebsd then
496 defaults.arch = "freebsd-"..cfg.target_cpu 535 defaults.arch = "freebsd-"..cfg.target_cpu
497 defaults.platforms = {"unix", "bsd", "freebsd"}
498 defaults.gcc_rpath = false 536 defaults.gcc_rpath = false
499 defaults.variables.CC = "cc" 537 defaults.variables.CC = "cc"
500 defaults.variables.LD = "cc" 538 defaults.variables.LD = "cc"
501end 539end
502 540
503if detected.openbsd then 541if cfg.platforms.openbsd then
504 defaults.arch = "openbsd-"..cfg.target_cpu 542 defaults.arch = "openbsd-"..cfg.target_cpu
505 defaults.platforms = {"unix", "bsd", "openbsd"}
506end 543end
507 544
508if detected.netbsd then 545if cfg.platforms.netbsd then
509 defaults.arch = "netbsd-"..cfg.target_cpu 546 defaults.arch = "netbsd-"..cfg.target_cpu
510 defaults.platforms = {"unix", "bsd", "netbsd"}
511end 547end
512 548
513if detected.solaris then 549if cfg.platforms.solaris then
514 defaults.arch = "solaris-"..cfg.target_cpu 550 defaults.arch = "solaris-"..cfg.target_cpu
515 defaults.platforms = {"unix", "solaris"} 551 --defaults.platforms = {"unix", "solaris"}
516 defaults.variables.MAKE = "gmake" 552 defaults.variables.MAKE = "gmake"
517end 553end
518 554
@@ -612,11 +648,11 @@ end
612function cfg.which_config() 648function cfg.which_config()
613 return { 649 return {
614 system = { 650 system = {
615 file = sys_config_file, 651 file = sys_config_file or sys_config_file_default,
616 ok = sys_config_ok, 652 ok = sys_config_ok,
617 }, 653 },
618 user = { 654 user = {
619 file = home_config_file, 655 file = home_config_file or home_config_file_default,
620 ok = home_config_ok, 656 ok = home_config_ok,
621 } 657 }
622 } 658 }
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua
index 686aadcd..e92aeddf 100644
--- a/src/luarocks/fetch.lua
+++ b/src/luarocks/fetch.lua
@@ -170,8 +170,13 @@ function fetch.fetch_and_unpack_rock(rock_file, dest)
170end 170end
171 171
172function fetch.url_to_base_dir(url) 172function fetch.url_to_base_dir(url)
173 -- for extensions like foo.tar.gz, "gz" is stripped first
174 local known_exts = {}
175 for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do
176 known_exts[ext] = ""
177 end
173 local base = dir.base_name(url) 178 local base = dir.base_name(url)
174 return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") 179 return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", ""))
175end 180end
176 181
177--- Back-end function that actually loads the local rockspec. 182--- Back-end function that actually loads the local rockspec.
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index ce41659b..aa735b3f 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -96,7 +96,7 @@ function git.get_sources(rockspec, extract, dest_dir, depth)
96 if git_can_clone_by_tag(git_cmd) then 96 if git_can_clone_by_tag(git_cmd) then
97 -- The argument to `--branch` can actually be a branch or a tag as of 97 -- The argument to `--branch` can actually be a branch or a tag as of
98 -- Git 1.7.10. 98 -- Git 1.7.10.
99 table.insert(command, 4, "--branch=" .. tag_or_branch) 99 table.insert(command, 3, "--branch=" .. tag_or_branch)
100 end 100 end
101 end 101 end
102 if not fs.execute(unpack(command)) then 102 if not fs.execute(unpack(command)) then
diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua
index 83a66434..101cae82 100644
--- a/src/luarocks/tools/zip.lua
+++ b/src/luarocks/tools/zip.lua
@@ -1,6 +1,6 @@
1 1
2--- A Lua implementation of .zip file archiving (used for creating .rock files), 2--- A Lua implementation of .zip file archiving (used for creating .rock files),
3-- using only lua-zlib. 3-- using only lzlib.
4--module("luarocks.tools.zip", package.seeall) 4--module("luarocks.tools.zip", package.seeall)
5local zip = {} 5local zip = {}
6 6
diff --git a/test/testing.lua b/test/testing.lua
index 50911fd4..63dead2b 100644
--- a/test/testing.lua
+++ b/test/testing.lua
@@ -441,5 +441,17 @@ local tests = {
441 return run "$luarocks install luarepl" 441 return run "$luarocks install luarepl"
442 and run "$luarocks doc luarepl" 442 and run "$luarocks doc luarepl"
443 end, 443 end,
444
445 -- Tests for https://github.com/keplerproject/luarocks/issues/375
446 test_fetch_base_dir = function()
447 local fetch = require "luarocks.fetch"
448
449 return assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip"))
450 and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip"))
451 and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz"))
452 and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2"))
453 and assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon"))
454 and assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3"))
455 end
444 456
445} 457}
diff --git a/test/testing.sh b/test/testing.sh
index 49aaa244..df1d301d 100755
--- a/test/testing.sh
+++ b/test/testing.sh
@@ -511,6 +511,19 @@ fail_config_user_config() { LUAROCKS_CONFIG="/missing_file.lua" $luarocks config
511test_config_rock_trees() { $luarocks config --rock-trees; } 511test_config_rock_trees() { $luarocks config --rock-trees; }
512test_config_help() { $luarocks help config; } 512test_config_help() { $luarocks help config; }
513 513
514# Tests for https://github.com/keplerproject/luarocks/issues/375
515test_fetch_base_dir() { $lua <<EOF
516 local fetch = require "luarocks.fetch"
517
518 assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip"))
519 assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip"))
520 assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz"))
521 assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2"))
522 assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon"))
523 assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3"))
524EOF
525}
526
514test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } 527test_doc() { $luarocks install luarepl; $luarocks doc luarepl; }
515 528
516# Driver ######################################### 529# Driver #########################################
diff --git a/win32/pe-parser.lua b/win32/pe-parser.lua
index 6b3a48c8..9cd36ffc 100644
--- a/win32/pe-parser.lua
+++ b/win32/pe-parser.lua
@@ -5,7 +5,7 @@
5-- case of 64 bit fields (bit/flag fields). Pointer arithmetic is still done numerically, so for 5-- case of 64 bit fields (bit/flag fields). Pointer arithmetic is still done numerically, so for
6-- very large files this could lead to undefined results. Use with care! 6-- very large files this could lead to undefined results. Use with care!
7-- 7--
8-- Version 0.3, [copyright (c) 2013-2015 Thijs Schreijer](http://www.thijsschreijer.nl) 8-- Version 0.4, [copyright (c) 2013-2015 Thijs Schreijer](http://www.thijsschreijer.nl)
9-- @name pe-parser 9-- @name pe-parser
10-- @class module 10-- @class module
11 11
@@ -532,6 +532,9 @@ function M.msvcrt(infile)
532 if not result then 532 if not result then
533 result = dll:match('(MSVCRTD?)%.DLL') 533 result = dll:match('(MSVCRTD?)%.DLL')
534 end 534 end
535 if not result then
536 result = dll:match('(VCRUNTIME%d*D?)%.DLL')
537 end
535 -- success, found it return name + binary where it was found 538 -- success, found it return name + binary where it was found
536 if result then return result, infile end 539 if result then return result, infile end
537 end 540 end