aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-06-20 10:28:49 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 15:51:13 -0300
commit4c1c170b9d344b6c069c8e6df5798f6e0bd63966 (patch)
tree21b0061a4c41434239320db45749ec5b4086be4c
parent50cd8ea8941d38678e8e6cf82065108dc3217d91 (diff)
downloadluarocks-4c1c170b9d344b6c069c8e6df5798f6e0bd63966.tar.gz
luarocks-4c1c170b9d344b6c069c8e6df5798f6e0bd63966.tar.bz2
luarocks-4c1c170b9d344b6c069c8e6df5798f6e0bd63966.zip
cfg, cmd: major reorganization
* `--lua-dir` flag, specifying a prefix for the Lua installation to be used. This reconfigures LuaRocks entirely, including allowing a LuaRocks which is itself running using one Lua 5.x version to manage packages for a different Lua 5.y version. The resulting configuration can be checked with `luarocks config --lua-dir=<path>`. * requiring `luarocks.core.cfg` no longer has side-effects * configuration now needs to be initialized with `cfg.init([lua_data])`, where `lua_data` is a table with the configuration of the VM: * `lua_version` - e.g. `"5.3"` * `luajit_version` - e.g. `"2.1.0-beta3"` * `lua_interpreter` - e.g. `"lua5.3"` * `lua_bindir` - e.g. `"/usr/local/bin"` * `lua_libdir` - e.g. `"/usr/local/lib"` * `lua_incdir` - e.g. `"/usr/local/include/lua-5.3"` * `cfg.init` can be called multiple times, reconfiguring the global state. This is important since `luarocks.loader` now calls it, and the `--lua-dir` command line can override the configuration and reconfigure LuaRocks. * `site_config_*` is no more: LuaRocks is no longer dependent on a properly-written site_config file. Instead, it can *optionally* use `luarocks.core.hardcoded` for hardcoded values, or detect its configuration at runtime, based on OS detection, arg[-1] or command-line flags. * reduction of moving parts in the configuration: * `cfg.platforms` is no longer a globally-visible table; instead, `cfg` provides an API of read-only functions: `is_platform`, `each_platform`, `print_platforms`. * `cfg.*_proxy` options are no longer configured via the config files, but rather via the standard `*_proxy` environment variables. * `"windows"` is now the more general platform name of the Windows family. This is technically a breaking change but I don't expect it to cause problems with real-world rockspecs. * internal code reorganization in `luarocks.cmd` module
-rw-r--r--spec/config_spec.lua16
-rw-r--r--spec/fetch_spec.lua2
-rw-r--r--spec/fs_spec.lua2
-rw-r--r--spec/tools_spec.lua2
-rw-r--r--spec/util/test_env.lua43
-rw-r--r--spec/util_spec.lua14
-rw-r--r--src/luarocks/cmd.lua427
-rw-r--r--src/luarocks/cmd/help.lua1
-rw-r--r--src/luarocks/core/cfg.lua1288
-rw-r--r--src/luarocks/deps.lua18
-rw-r--r--src/luarocks/fs/lua.lua8
-rw-r--r--src/luarocks/loader.lua5
-rw-r--r--src/luarocks/util.lua1
13 files changed, 1007 insertions, 820 deletions
diff --git a/spec/config_spec.lua b/spec/config_spec.lua
index 94757244..e78c3de0 100644
--- a/spec/config_spec.lua
+++ b/spec/config_spec.lua
@@ -3,7 +3,7 @@ local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
5local env_variables = test_env.env_variables 5local env_variables = test_env.env_variables
6local site_config 6local hardcoded
7 7
8test_env.unload_luarocks() 8test_env.unload_luarocks()
9 9
@@ -11,30 +11,30 @@ describe("LuaRocks config tests #integration", function()
11 11
12 before_each(function() 12 before_each(function()
13 test_env.setup_specs() 13 test_env.setup_specs()
14 test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs 14 test_env.unload_luarocks() -- need to be required here, because hardcoded is created after first loading of specs
15 site_config = require("luarocks.core.site_config_" .. test_env.lua_version:gsub("%.", "_")) 15 hardcoded = require("luarocks.core.hardcoded")
16 end) 16 end)
17 17
18 describe("LuaRocks config - basic tests", function() 18 describe("LuaRocks config - basic tests", function()
19 it("LuaRocks config with no flags/arguments", function() 19 it("LuaRocks config with no flags/arguments", function()
20 assert.is_false(run.luarocks_bool("config")) 20 assert.match("rocks_servers", run.luarocks("config"))
21 end) 21 end)
22 22
23 it("LuaRocks config include dir", function() 23 it("LuaRocks config include dir", function()
24 local output = run.luarocks("config --lua-incdir") 24 local output = run.luarocks("config --lua-incdir")
25 if test_env.TEST_TARGET_OS == "windows" then 25 if test_env.TEST_TARGET_OS == "windows" then
26 assert.are.same(output, site_config.LUA_INCDIR:gsub("\\","/")) 26 assert.are.same(output, hardcoded.LUA_INCDIR:gsub("\\","/"))
27 else 27 else
28 assert.are.same(output, site_config.LUA_INCDIR) 28 assert.are.same(output, hardcoded.LUA_INCDIR)
29 end 29 end
30 end) 30 end)
31 31
32 it("LuaRocks config library dir", function() 32 it("LuaRocks config library dir", function()
33 local output = run.luarocks("config --lua-libdir") 33 local output = run.luarocks("config --lua-libdir")
34 if test_env.TEST_TARGET_OS == "windows" then 34 if test_env.TEST_TARGET_OS == "windows" then
35 assert.are.same(output, site_config.LUA_LIBDIR:gsub("\\","/")) 35 assert.are.same(output, hardcoded.LUA_LIBDIR:gsub("\\","/"))
36 else 36 else
37 assert.are.same(output, site_config.LUA_LIBDIR) 37 assert.are.same(output, hardcoded.LUA_LIBDIR)
38 end 38 end
39 end) 39 end)
40 40
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua
index 6e00bc22..b878c1e6 100644
--- a/spec/fetch_spec.lua
+++ b/spec/fetch_spec.lua
@@ -3,6 +3,7 @@ local git_repo = require("spec.util.git_repo")
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5test_env.setup_specs() 5test_env.setup_specs()
6local cfg = require("luarocks.core.cfg")
6local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
7local fetch = require("luarocks.fetch") 8local fetch = require("luarocks.fetch")
8local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
@@ -21,6 +22,7 @@ describe("Luarocks fetch test #unit #mock", function()
21 local runner 22 local runner
22 23
23 setup(function() 24 setup(function()
25 cfg.init()
24 fs.init() 26 fs.init()
25 test_env.mock_server_init() 27 test_env.mock_server_init()
26 28
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua
index b8091f75..3f115df9 100644
--- a/spec/fs_spec.lua
+++ b/spec/fs_spec.lua
@@ -3,6 +3,7 @@ local test_env = require("spec.util.test_env")
3test_env.unload_luarocks() 3test_env.unload_luarocks()
4test_env.setup_specs() 4test_env.setup_specs()
5local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
6local cfg = require("luarocks.core.cfg")
6local lfs = require("lfs") 7local lfs = require("lfs")
7local is_win = test_env.TEST_TARGET_OS == "windows" 8local is_win = test_env.TEST_TARGET_OS == "windows"
8local posix_ok = pcall(require, "posix") 9local posix_ok = pcall(require, "posix")
@@ -55,6 +56,7 @@ describe("Luarocks fs test #unit", function()
55 local runner 56 local runner
56 57
57 setup(function() 58 setup(function()
59 cfg.init()
58 fs.init() 60 fs.init()
59 runner = require("luacov.runner") 61 runner = require("luacov.runner")
60 runner.init(testing_paths.testrun_dir .. "/luacov.config") 62 runner.init(testing_paths.testrun_dir .. "/luacov.config")
diff --git a/spec/tools_spec.lua b/spec/tools_spec.lua
index 10dafb0b..c84dbab3 100644
--- a/spec/tools_spec.lua
+++ b/spec/tools_spec.lua
@@ -5,6 +5,7 @@ local write_file = test_env.write_file
5 5
6test_env.unload_luarocks() 6test_env.unload_luarocks()
7local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
8local cfg = require("luarocks.core.cfg")
8local patch = require("luarocks.tools.patch") 9local patch = require("luarocks.tools.patch")
9 10
10local lao = 11local lao =
@@ -148,6 +149,7 @@ describe("Luarocks patch test #unit", function()
148 local runner 149 local runner
149 150
150 setup(function() 151 setup(function()
152 cfg.init()
151 fs.init() 153 fs.init()
152 runner = require("luacov.runner") 154 runner = require("luacov.runner")
153 runner.init(testing_paths.testrun_dir .. "/luacov.config") 155 runner.init(testing_paths.testrun_dir .. "/luacov.config")
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
index 6d8a962c..1d4e98d8 100644
--- a/spec/util/test_env.lua
+++ b/spec/util/test_env.lua
@@ -40,6 +40,10 @@ function test_env.exists(path)
40 return lfs.attributes(path, "mode") ~= nil 40 return lfs.attributes(path, "mode") ~= nil
41end 41end
42 42
43function test_env.file_if_exists(path)
44 return lfs.attributes(path, "mode") and path
45end
46
43--- Quote argument for shell processing. Fixes paths on Windows. 47--- Quote argument for shell processing. Fixes paths on Windows.
44-- Adds double quotes and escapes. Based on function in fs/win32.lua. 48-- Adds double quotes and escapes. Based on function in fs/win32.lua.
45-- @param arg string: Unquoted argument. 49-- @param arg string: Unquoted argument.
@@ -251,7 +255,15 @@ function test_env.set_args()
251 end 255 end
252 end 256 end
253 end 257 end
258 print(test_env.TEST_TARGET_OS)
259 end
260
261 if test_env.TEST_TARGET_OS == "windows" then
262 test_env.lib_extension = "dll"
263 else
264 test_env.lib_extension = "so"
254 end 265 end
266
255 return true 267 return true
256end 268end
257 269
@@ -394,12 +406,8 @@ local function create_env(testing_paths)
394 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" 406 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;"
395 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" 407 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;"
396 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" 408 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;"
397 local lib_extension = "so" 409 env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. test_env.lib_extension .. ";"
398 if test_env.TEST_TARGET_OS == "windows" then 410 .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. test_env.lib_extension .. ";"
399 lib_extension = "dll"
400 end
401 env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. lib_extension .. ";"
402 .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. lib_extension .. ";"
403 env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;" 411 env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;"
404 412
405 return env_variables 413 return env_variables
@@ -584,8 +592,7 @@ function test_env.setup_specs(extra_rocks)
584 592
585 package.path = test_env.env_variables.LUA_PATH 593 package.path = test_env.env_variables.LUA_PATH
586 594
587 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) 595 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"cfg = require('luarocks.core.cfg'); cfg.init(); print(cfg.arch)\"", false, test_env.env_variables)
588 test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').lib_extension)\"", false, test_env.env_variables)
589 test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" 596 test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or ""
590 test_env.md5sums = create_md5sums(test_env.testing_paths) 597 test_env.md5sums = create_md5sums(test_env.testing_paths)
591 test_env.setup_done = true 598 test_env.setup_done = true
@@ -737,11 +744,21 @@ local function install_luarocks(install_env_vars)
737 assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " " .. compiler_flag .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars)) 744 assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " " .. compiler_flag .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars))
738 assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/core/site_config* " .. testing_paths.src_dir .. "/luarocks/core")) 745 assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/core/site_config* " .. testing_paths.src_dir .. "/luarocks/core"))
739 else 746 else
740 local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix 747 local incfile = test_env.file_if_exists(testing_paths.luadir .. "/include/lua.h")
741 assert(execute_bool(configure_cmd, false, install_env_vars)) 748 or test_env.file_if_exists(testing_paths.luadir .. "/include/lua/" .. test_env.lua_version .. "/lua.h")
742 assert(execute_bool("make clean", false, install_env_vars)) 749 or test_env.file_if_exists(testing_paths.luadir .. "/include/lua" .. test_env.lua_version .. "/lua.h")
743 assert(execute_bool("make src/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua", false, install_env_vars)) 750 local incdir = assert(incfile):gsub("/lua.h$", "")
744 assert(execute_bool("make dev", false, install_env_vars)) 751
752 local lines = {
753 "return {",
754 ("SYSCONFDIR = %q,"):format(testing_paths.testing_lrprefix .. "/etc/luarocks"),
755 ("LUA_DIR = %q,"):format(testing_paths.luadir),
756 ("LUA_INCDIR = %q,"):format(incdir),
757 ("LUA_LIBDIR = %q,"):format(testing_paths.luadir .. "/lib"),
758 ("LUA_BINDIR = %q,"):format(testing_paths.luadir .. "/bin"),
759 "}",
760 }
761 test_env.write_file("src/luarocks/core/hardcoded.lua", table.concat(lines, "\n") .. "\n")
745 end 762 end
746 print("LuaRocks installed correctly!") 763 print("LuaRocks installed correctly!")
747end 764end
diff --git a/spec/util_spec.lua b/spec/util_spec.lua
index 26e93e14..cbdde095 100644
--- a/spec/util_spec.lua
+++ b/spec/util_spec.lua
@@ -53,20 +53,6 @@ describe("Basic tests #integration", function()
53 assert.is.truthy(run.luarocks("--only-server=testing")) 53 assert.is.truthy(run.luarocks("--only-server=testing"))
54 end) 54 end)
55 55
56 it("#only LuaRocks test site config", function()
57 local scname = testing_paths.src_dir .. "/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua"
58
59 assert.is.truthy(os.rename(scname, scname..".tmp"))
60 assert.is.falsy(lfs.attributes(scname))
61 assert.is.truthy(lfs.attributes(scname..".tmp"))
62
63 assert.is.truthy(run.luarocks(""))
64
65 assert.is.truthy(os.rename(scname..".tmp", scname))
66 assert.is.falsy(lfs.attributes(scname..".tmp"))
67 assert.is.truthy(lfs.attributes(scname))
68 end)
69
70end) 56end)
71 57
72test_env.unload_luarocks() 58test_env.unload_luarocks()
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index 51d22154..70d93670 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -4,13 +4,13 @@ local cmd = {}
4 4
5local unpack = unpack or table.unpack 5local unpack = unpack or table.unpack
6 6
7local util = require("luarocks.util")
8local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
8local util = require("luarocks.util")
9local path = require("luarocks.path") 9local path = require("luarocks.path")
10local dir = require("luarocks.dir")
11local deps = require("luarocks.deps") 10local deps = require("luarocks.deps")
12local fs = require("luarocks.fs") 11local dir = require("luarocks.dir")
13local fun = require("luarocks.fun") 12local fun = require("luarocks.fun")
13local fs = require("luarocks.fs")
14 14
15local program = util.this_program("luarocks") 15local program = util.this_program("luarocks")
16 16
@@ -22,12 +22,6 @@ cmd.errorcodes = {
22 CRASH = 99 22 CRASH = 99
23} 23}
24 24
25local function replace_tree(flags, tree)
26 tree = dir.normalize(tree)
27 flags["tree"] = tree
28 path.use_tree(tree)
29end
30
31local function is_ownership_ok(directory) 25local function is_ownership_ok(directory)
32 local me = fs.current_user() 26 local me = fs.current_user()
33 for _ = 1,3 do -- try up to grandparent 27 for _ = 1,3 do -- try up to grandparent
@@ -40,16 +34,240 @@ local function is_ownership_ok(directory)
40 return false 34 return false
41end 35end
42 36
43local function find_project_dir() 37do
44 local try = "." 38 local function check_lua_version(lua_exe, luaver)
45 for _ = 1, 10 do -- FIXME detect when root dir was hit instead 39 local luajitver
46 local abs = fs.absolute_name(try) 40 if not (luaver and luaver:match("^[0-9]")) then
47 if fs.is_dir(abs .. "/.luarocks") and fs.is_dir(abs .. "/lua_modules") then 41 luaver = util.popen_read(lua_exe .. ' -e "io.write(_VERSION:sub(5))"')
48 abs = abs:gsub("/.$", "") 42 end
49 return abs, abs .. "/lua_modules" 43 if luaver == "5.1" then
44 luajitver = util.popen_read(lua_exe .. ' -e "io.write(tostring(jit and jit.version:sub(8)))"')
45 if luajitver == "nil" then
46 luajitver = nil
47 end
48 end
49 return luaver, luajitver
50 end
51
52 local function exists(file)
53 local fd = io.open(file, "r")
54 if fd then
55 fd:close()
56 return true
57 end
58 return false
59 end
60
61 local find_lua_bindir
62 do
63 local exe_suffix = (package.config:sub(1, 1) == "\\" and ".exe" or "")
64
65 local function insert_lua_versions(names, luaver)
66 local variants = {
67 "lua" .. luaver .. exe_suffix,
68 "lua" .. luaver:gsub("%.", "") .. exe_suffix,
69 "lua-" .. luaver .. exe_suffix,
70 "lua-" .. luaver:gsub("%.", "") .. exe_suffix,
71 }
72 for _, name in ipairs(variants) do
73 names[name] = luaver
74 table.insert(names, name)
75 end
76 end
77
78 find_lua_bindir = function(prefix, luaver)
79 local names = {}
80 if luaver then
81 insert_lua_versions(names, luaver)
82 else
83 for v in util.lua_versions("descending") do
84 insert_lua_versions(names, v)
85 end
86 end
87 table.insert(names, "lua" .. exe_suffix)
88 table.insert(names, "luajit" .. exe_suffix)
89
90 local bindirs = { prefix .. "/bin", prefix }
91 local tried = {}
92 for _, d in ipairs(bindirs) do
93 for _, name in ipairs(names) do
94 local lua_exe = dir.path(d, name)
95 table.insert(tried, lua_exe)
96 if exists(lua_exe) then
97 return name, d, luaver
98 end
99 end
100 end
101 return nil, "Lua interpreter not found at " .. prefix .. "\n" ..
102 "Tried:\t" .. table.concat(tried, "\n\t")
103 end
104 end
105
106 local function find_lua_incdir(prefix, luaver, luajitver)
107 luajitver = luajitver and luajitver:gsub("%-.*", "")
108 local incdirs = {
109 prefix .. "/include",
110 prefix .. "/include/lua/" .. luaver,
111 prefix .. "/include/lua" .. luaver,
112 prefix,
113 luajitver and prefix .. "/include/luajit-" .. luajitver,
114 }
115
116 for _, d in ipairs(incdirs) do
117 local lua_h = dir.path(d, "lua.h")
118 if exists(lua_h) then
119 return d
120 end
121 end
122
123 -- fallback to a default, as it is not necessarily needed.
124 return incdirs[1]
125 end
126
127 find_lua = function(prefix, luaver)
128 local lua_interpreter, bindir
129 lua_interpreter, bindir, luaver = find_lua_bindir(prefix, luaver)
130 if not lua_interpreter then
131 return nil, bindir
132 end
133
134 local luajitver
135 local lua_exe = dir.path(bindir, lua_interpreter)
136 luaver, luajitver = check_lua_version(lua_exe, luaver)
137
138 return {
139 lua_version = luaver,
140 luajit_version = luajitver,
141 lua_interpreter = lua_interpreter,
142 lua_dir = prefix,
143 lua_bindir = bindir,
144 lua_incdir = find_lua_incdir(prefix, luaver, luajitver),
145 lua_libdir = prefix .. "/lib",
146 }
147 end
148end
149
150local function check_popen()
151 local popen_ok, popen_result = pcall(io.popen, "")
152 if popen_ok then
153 if popen_result then
154 popen_result:close()
155 end
156 else
157 io.stderr:write("Your version of Lua does not support io.popen,\n")
158 io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n")
159 os.exit(cmd.errorcodes.UNSPECIFIED)
160 end
161end
162
163local process_tree_flags
164do
165 local function replace_tree(flags, tree)
166 tree = dir.normalize(tree)
167 flags["tree"] = tree
168 path.use_tree(tree)
169 end
170
171 local function find_project_dir()
172 local try = "."
173 for _ = 1, 10 do -- FIXME detect when root dir was hit instead
174 local abs = fs.absolute_name(try)
175 if fs.is_dir(abs .. "/.luarocks") and fs.is_dir(abs .. "/lua_modules") then
176 abs = abs:gsub("/.$", "")
177 return abs, abs .. "/lua_modules"
178 end
179 try = try .. "/.."
180 end
181 end
182
183 local function strip_trailing_slashes()
184 if type(cfg.root_dir) == "string" then
185 cfg.root_dir = cfg.root_dir:gsub("/+$", "")
186 else
187 cfg.root_dir.root = cfg.root_dir.root:gsub("/+$", "")
188 end
189 cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "")
190 cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "")
191 cfg.deploy_lua_dir = cfg.deploy_lua_dir:gsub("/+$", "")
192 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "")
193 end
194
195 process_tree_flags = function(flags)
196
197 if cfg.local_by_default then
198 flags["local"] = true
199 end
200
201 if flags["tree"] then
202 local named = false
203 for _, tree in ipairs(cfg.rocks_trees) do
204 if type(tree) == "table" and flags["tree"] == tree.name then
205 if not tree.root then
206 return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field."
207 end
208 replace_tree(flags, tree.root)
209 named = true
210 break
211 end
212 end
213 if not named then
214 local root_dir = fs.absolute_name(flags["tree"])
215 replace_tree(flags, root_dir)
216 end
217 elseif flags["project-tree"] then
218 local tree = flags["project-tree"]
219 table.insert(cfg.rocks_trees, 1, { name = "project", root = tree } )
220 path.use_tree(tree)
221 elseif flags["local"] then
222 if not cfg.home_tree then
223 return nil, "The --local flag is meant for operating in a user's home directory.\n"..
224 "You are running as a superuser, which is intended for system-wide operation.\n"..
225 "To force using the superuser's home, use --tree explicitly."
226 end
227 replace_tree(flags, cfg.home_tree)
228 else
229 local project_dir, rocks_tree = find_project_dir()
230 if project_dir then
231 table.insert(cfg.rocks_trees, 1, { name = "project", root = rocks_tree } )
232 path.use_tree(rocks_tree)
233 else
234 local trees = cfg.rocks_trees
235 path.use_tree(trees[#trees])
236 end
237 end
238
239 strip_trailing_slashes()
240
241 cfg.variables.ROCKS_TREE = cfg.rocks_dir
242 cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir
243
244 return true
245 end
246end
247
248local function process_server_flags(flags)
249 if flags["server"] then
250 local protocol, pathname = dir.split_url(flags["server"])
251 table.insert(cfg.rocks_servers, 1, protocol.."://"..pathname)
252 end
253
254 if flags["dev"] then
255 local append_dev = function(s) return dir.path(s, "dev") end
256 local dev_servers = fun.traverse(cfg.rocks_servers, append_dev)
257 cfg.rocks_servers = fun.concat(dev_servers, cfg.rocks_servers)
258 end
259
260 if flags["only-server"] then
261 if flags["dev"] then
262 return nil, "--only-server cannot be used with --dev"
50 end 263 end
51 try = try .. "/.." 264 if flags["server"] then
265 return nil, "--only-server cannot be used with --server"
266 end
267 cfg.rocks_servers = { flags["only-server"] }
52 end 268 end
269
270 return true
53end 271end
54 272
55--- Main command-line processor. 273--- Main command-line processor.
@@ -58,9 +276,13 @@ end
58-- to it any additional arguments passed by the user. 276-- to it any additional arguments passed by the user.
59-- Uses the global table "commands", which contains 277-- Uses the global table "commands", which contains
60-- the loaded modules representing commands. 278-- the loaded modules representing commands.
279-- @param program_version string: The program version number as a string.
280-- @param description string: Short summary description of the program.
61-- @param ... string: Arguments given on the command-line. 281-- @param ... string: Arguments given on the command-line.
62function cmd.run_command(description, commands, ...) 282function cmd.run_command(description, commands, ...)
63 283
284 check_popen()
285
64 local function error_handler(err) 286 local function error_handler(err)
65 return debug.traceback("LuaRocks "..cfg.program_version.. 287 return debug.traceback("LuaRocks "..cfg.program_version..
66 " bug (please report at https://github.com/luarocks/luarocks/issues).\n"..err, 2) 288 " bug (please report at https://github.com/luarocks/luarocks/issues).\n"..err, 2)
@@ -82,45 +304,39 @@ function cmd.run_command(description, commands, ...)
82 os.exit(exitcode or cmd.errorcodes.UNSPECIFIED) 304 os.exit(exitcode or cmd.errorcodes.UNSPECIFIED)
83 end 305 end
84 306
85 local args = {...} 307 local function process_arguments(...)
86 local cmdline_vars = {} 308 local args = {...}
87 for i = #args, 1, -1 do 309 local cmdline_vars = {}
88 local arg = args[i] 310 for i = #args, 1, -1 do
89 if arg:match("^[^-][^=]*=") then 311 local arg = args[i]
90 local var, val = arg:match("^([A-Z_][A-Z0-9_]*)=(.*)") 312 if arg:match("^[^-][^=]*=") then
91 if val then 313 local var, val = arg:match("^([A-Z_][A-Z0-9_]*)=(.*)")
92 cmdline_vars[var] = val 314 if val then
93 table.remove(args, i) 315 cmdline_vars[var] = val
94 else 316 table.remove(args, i)
95 die("Invalid assignment: "..arg) 317 else
318 die("Invalid assignment: "..arg)
319 end
96 end 320 end
97 end 321 end
98 end 322 local nonflags = { util.parse_flags(unpack(args)) }
99 local nonflags = { util.parse_flags(unpack(args)) } 323 local flags = table.remove(nonflags, 1)
100 local flags = table.remove(nonflags, 1) 324 if flags.ERROR then
101 if flags.ERROR then 325 die(flags.ERROR.." See --help.")
102 die(flags.ERROR.." See --help.") 326 end
103 end
104
105 fs.init()
106 327
107 if flags["from"] then flags["server"] = flags["from"] end 328 -- Compatibility for old names of some flags
108 if flags["only-from"] then flags["only-server"] = flags["only-from"] end 329 if flags["to"] then flags["tree"] = flags["to"] end
109 if flags["only-sources-from"] then flags["only-sources"] = flags["only-sources-from"] end 330 if flags["from"] then flags["server"] = flags["from"] end
110 if flags["to"] then flags["tree"] = flags["to"] end 331 if flags["nodeps"] then flags["deps-mode"] = "none" end
111 if flags["nodeps"] then 332 if flags["only-from"] then flags["only-server"] = flags["only-from"] end
112 flags["deps-mode"] = "none" 333 if flags["only-sources-from"] then flags["only-sources"] = flags["only-sources-from"] end
113 end
114
115 cfg.flags = flags
116 334
117 local command 335 return flags, nonflags, cmdline_vars
118
119 if flags["verbose"] then -- setting it in the config file will kick-in earlier in the process
120 cfg.verbose = true
121 fs.verbose()
122 end 336 end
123 337
338 local flags, nonflags, cmdline_vars = process_arguments(...)
339
124 if flags["timeout"] then -- setting it in the config file will kick-in earlier in the process 340 if flags["timeout"] then -- setting it in the config file will kick-in earlier in the process
125 local timeout = tonumber(flags["timeout"]) 341 local timeout = tonumber(flags["timeout"])
126 if timeout then 342 if timeout then
@@ -130,6 +346,7 @@ function cmd.run_command(description, commands, ...)
130 end 346 end
131 end 347 end
132 348
349 local command
133 if flags["version"] then 350 if flags["version"] then
134 util.printout(program.." "..cfg.program_version) 351 util.printout(program.." "..cfg.program_version)
135 util.printout(description) 352 util.printout(description)
@@ -141,101 +358,55 @@ function cmd.run_command(description, commands, ...)
141 command = table.remove(nonflags, 1) 358 command = table.remove(nonflags, 1)
142 end 359 end
143 command = command:gsub("-", "_") 360 command = command:gsub("-", "_")
144
145 if cfg.local_by_default then
146 flags["local"] = true
147 end
148 361
149 if flags["deps-mode"] and not deps.check_deps_mode_flag(flags["deps-mode"]) then 362 if flags["deps-mode"] and not deps.check_deps_mode_flag(flags["deps-mode"]) then
150 die("Invalid entry for --deps-mode.") 363 die("Invalid entry for --deps-mode.")
151 end 364 end
152 365
153 if flags["tree"] then 366 local lua_data
154 local named = false 367 if flags["lua-dir"] then
155 for _, tree in ipairs(cfg.rocks_trees) do 368 lua_data = find_lua(flags["lua-dir"], flags["lua-version"])
156 if type(tree) == "table" and flags["tree"] == tree.name then
157 if not tree.root then
158 die("Configuration error: tree '"..tree.name.."' has no 'root' field.")
159 end
160 replace_tree(flags, tree.root)
161 named = true
162 break
163 end
164 end
165 if not named then
166 local root_dir = fs.absolute_name(flags["tree"])
167 replace_tree(flags, root_dir)
168 end
169 elseif flags["project-tree"] then
170 local tree = flags["project-tree"]
171 table.insert(cfg.rocks_trees, 1, { name = "project", root = tree } )
172 path.use_tree(tree)
173 elseif flags["local"] then
174 if not cfg.home_tree then
175 die("The --local flag is meant for operating in a user's home directory.\n"..
176 "You are running as a superuser, which is intended for system-wide operation.\n"..
177 "To force using the superuser's home, use --tree explicitly.")
178 end
179 replace_tree(flags, cfg.home_tree)
180 else
181 local project_dir, rocks_tree = find_project_dir()
182 if project_dir then
183 table.insert(cfg.rocks_trees, 1, { name = "project", root = rocks_tree } )
184 path.use_tree(rocks_tree)
185 else
186 local trees = cfg.rocks_trees
187 path.use_tree(trees[#trees])
188 end
189 end 369 end
190 370
191 if type(cfg.root_dir) == "string" then 371 -----------------------------------------------------------------------------
192 cfg.root_dir = cfg.root_dir:gsub("/+$", "") 372 local ok, err = cfg.init(lua_data, util.warning)
193 else 373 if not ok then
194 cfg.root_dir.root = cfg.root_dir.root:gsub("/+$", "") 374 die(err)
195 end 375 end
196 cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "") 376 -----------------------------------------------------------------------------
197 cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "")
198 cfg.deploy_lua_dir = cfg.deploy_lua_dir:gsub("/+$", "")
199 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "")
200
201 cfg.variables.ROCKS_TREE = cfg.rocks_dir
202 cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir
203 377
204 if flags["server"] then 378 fs.init()
205 local protocol, pathname = dir.split_url(flags["server"]) 379
206 table.insert(cfg.rocks_servers, 1, protocol.."://"..pathname) 380 if flags["verbose"] then
381 cfg.verbose = true
382 fs.verbose()
207 end 383 end
208 384
209 if flags["dev"] then 385 if (not fs.current_dir()) or fs.current_dir() == "" then
210 local append_dev = function(s) return dir.path(s, "dev") end 386 die("Current directory does not exist. Please run LuaRocks from an existing directory.")
211 local dev_servers = fun.traverse(cfg.rocks_servers, append_dev)
212 cfg.rocks_servers = fun.concat(dev_servers, cfg.rocks_servers)
213 end 387 end
214 388
215 if flags["only-server"] then 389 local ok, err
216 if flags["dev"] then 390 ok, err = process_tree_flags(flags)
217 die("--only-server cannot be used with --dev") 391 if not ok then
218 end 392 die(err)
219 if flags["server"] then 393 end
220 die("--only-server cannot be used with --server") 394
221 end 395 ok, err = process_server_flags(flags)
222 cfg.rocks_servers = { flags["only-server"] } 396 if not ok then
397 die(err)
223 end 398 end
224 399
225 if flags["only-sources"] then 400 if flags["only-sources"] then
226 cfg.only_sources_from = flags["only-sources"] 401 cfg.only_sources_from = flags["only-sources"]
227 end 402 end
228 403
229 if command ~= "help" then 404 if command ~= "help" then
230 for k, v in pairs(cmdline_vars) do 405 for k, v in pairs(cmdline_vars) do
231 cfg.variables[k] = v 406 cfg.variables[k] = v
232 end 407 end
233 end 408 end
234 409
235 if (not fs.current_dir()) or fs.current_dir() == "" then
236 die("Current directory does not exist. Please run LuaRocks from an existing directory.")
237 end
238
239 if not is_ownership_ok(cfg.local_cache) then 410 if not is_ownership_ok(cfg.local_cache) then
240 util.warning("The directory '" .. cfg.local_cache .. "' or its parent directory ".. 411 util.warning("The directory '" .. cfg.local_cache .. "' or its parent directory "..
241 "is not owned by the current user and the cache has been disabled. ".. 412 "is not owned by the current user and the cache has been disabled. "..
@@ -246,10 +417,16 @@ function cmd.run_command(description, commands, ...)
246 cfg.local_cache = fs.make_temp_dir("local_cache") 417 cfg.local_cache = fs.make_temp_dir("local_cache")
247 util.schedule_function(fs.delete, cfg.local_cache) 418 util.schedule_function(fs.delete, cfg.local_cache)
248 end 419 end
249 420
250 if commands[command] then 421 if commands[command] then
251 local cmd_mod = require(commands[command]) 422 local cmd_mod = require(commands[command])
252 local call_ok, ok, err, exitcode = xpcall(function() return cmd_mod.command(flags, unpack(nonflags)) end, error_handler) 423 local call_ok, ok, err, exitcode = xpcall(function()
424 if command == "help" then
425 return cmd_mod.command(description, commands, unpack(nonflags))
426 else
427 return cmd_mod.command(flags, unpack(nonflags))
428 end
429 end, error_handler)
253 if not call_ok then 430 if not call_ok then
254 die(ok, cmd.errorcodes.CRASH) 431 die(ok, cmd.errorcodes.CRASH)
255 elseif not ok then 432 elseif not ok then
diff --git a/src/luarocks/cmd/help.lua b/src/luarocks/cmd/help.lua
index 1e1d8676..3b13acc2 100644
--- a/src/luarocks/cmd/help.lua
+++ b/src/luarocks/cmd/help.lua
@@ -63,6 +63,7 @@ function help.command(description, commands, command)
63 (overrides any entries in the config file) 63 (overrides any entries in the config file)
64 --only-sources=<url> Restrict downloads to paths matching the 64 --only-sources=<url> Restrict downloads to paths matching the
65 given URL. 65 given URL.
66 --lua-dir=<prefix> Which Lua installation to use.
66 --tree=<tree> Which tree to operate on. 67 --tree=<tree> Which tree to operate on.
67 --local Use the tree in the user's home directory. 68 --local Use the tree in the user's home directory.
68 To enable it, see ']]..program..[[ help path'. 69 To enable it, see ']]..program..[[ help path'.
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 7c29e2dc..cd3aadbc 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -10,106 +10,19 @@
10-- files. Run `luarocks` with no arguments to see the locations of 10-- files. Run `luarocks` with no arguments to see the locations of
11-- these files in your platform. 11-- these files in your platform.
12 12
13local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION = 13local next, table, pairs, require, os, pcall, ipairs, package, tonumber, type, assert =
14 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION 14 next, table, pairs, require, os, pcall, ipairs, package, tonumber, type, assert
15
16local cfg = {}
17
18cfg.lua_version = _VERSION:match(" (5%.[1234])$") or "5.1"
19local version_suffix = cfg.lua_version:gsub("%.", "_")
20
21-- Load site-local global configurations
22local ok, site_config = pcall(require, "luarocks.core.site_config_"..version_suffix)
23if not ok then
24 io.stderr:write("Site-local luarocks/core/site_config_"..version_suffix..".lua file not found. Incomplete installation?\n")
25 site_config = {}
26end
27 15
28local util = require("luarocks.core.util") 16local util = require("luarocks.core.util")
29local persist = require("luarocks.core.persist") 17local persist = require("luarocks.core.persist")
30local require = nil
31--------------------------------------------------------------------------------
32 18
33cfg.program_version = "dev" 19--------------------------------------------------------------------------------
34cfg.program_series = "3.0"
35cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series
36cfg.variables = {}
37cfg.rocks_trees = {}
38cfg.platforms = {}
39
40local popen_ok, popen_result = pcall(io.popen, "")
41if popen_ok then
42 if popen_result then
43 popen_result:close()
44 end
45else
46 io.stderr:write("Your version of Lua does not support io.popen,\n")
47 io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n")
48 os.exit(1) -- FIXME
49end
50 20
51-- System detection: 21local program_version = "dev"
52 22local program_series = "3.0"
53-- A proper installation of LuaRocks will hardcode the system 23local major_version = (program_version:match("([^.]%.[^.])")) or program_series
54-- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M,
55-- so that this detection does not run every time. When it is
56-- performed, we use the Unix way to identify the system,
57-- even on Windows (assuming UnxUtils or Cygwin).
58local system = site_config.LUAROCKS_UNAME_S or util.popen_read("uname -s")
59local proc = site_config.LUAROCKS_UNAME_M or util.popen_read("uname -m")
60if proc:match("i[%d]86") then
61 cfg.target_cpu = "x86"
62elseif proc:match("amd64") or proc:match("x86_64") then
63 cfg.target_cpu = "x86_64"
64elseif proc:match("Power Macintosh") then
65 cfg.target_cpu = "powerpc"
66 else
67 cfg.target_cpu = proc
68end
69 24
70if system == "FreeBSD" then 25local is_windows = package.config:sub(1,1) == "\\"
71 cfg.platforms.unix = true
72 cfg.platforms.freebsd = true
73 cfg.platforms.bsd = true
74elseif system == "OpenBSD" then
75 cfg.platforms.unix = true
76 cfg.platforms.openbsd = true
77 cfg.platforms.bsd = true
78elseif system == "NetBSD" then
79 cfg.platforms.unix = true
80 cfg.platforms.netbsd = true
81 cfg.platforms.bsd = true
82elseif system == "Darwin" then
83 cfg.platforms.unix = true
84 cfg.platforms.macosx = true
85 cfg.platforms.bsd = true
86elseif system == "Linux" then
87 cfg.platforms.unix = true
88 cfg.platforms.linux = true
89elseif system == "SunOS" then
90 cfg.platforms.unix = true
91 cfg.platforms.solaris = true
92elseif system and system:match("^CYGWIN") then
93 cfg.platforms.unix = true
94 cfg.platforms.cygwin = true
95elseif system and system:match("^MSYS") then
96 cfg.platforms.unix = true
97 cfg.platforms.msys = true
98 cfg.platforms.cygwin = true
99elseif system and system:match("^Windows") then
100 cfg.platforms.windows = true
101 cfg.platforms.win32 = true
102elseif system and system:match("^MINGW") then
103 cfg.platforms.windows = true
104 cfg.platforms.mingw32 = true
105 cfg.platforms.win32 = true
106elseif system == "Haiku" then
107 cfg.platforms.unix = true
108 cfg.platforms.haiku = true
109else
110 cfg.platforms.unix = true
111 -- Fall back to Unix in unknown systems.
112end
113 26
114-- Set order for platform overrides. 27-- Set order for platform overrides.
115-- More general platform identifiers should be listed first, 28-- More general platform identifiers should be listed first,
@@ -128,630 +41,719 @@ local platform_order = {
128 "msys", 41 "msys",
129 "haiku", 42 "haiku",
130 -- Windows 43 -- Windows
44 "windows",
131 "win32", 45 "win32",
132 "mingw32", 46 "mingw32",
133 "windows",
134} 47}
135 48
136-- Path configuration: 49local load_config_file
137local sys_config_file, home_config_file 50do
138local sys_config_file_default, home_config_file_default 51 -- Create global environment for the config files;
139local sys_config_dir, home_config_dir 52 local function env_for_config_file(cfg, platforms)
140local sys_config_ok, home_config_ok = false, false 53 local e
141local extra_luarocks_module_dir 54 e = {
142sys_config_dir = site_config.LUAROCKS_SYSCONFDIR or site_config.LUAROCKS_PREFIX 55 home = cfg.home,
143if cfg.platforms.windows then 56 lua_version = cfg.lua_version,
144 cfg.home = os.getenv("APPDATA") or "c:" 57 platforms = util.make_shallow_copy(platforms),
145 sys_config_dir = sys_config_dir or "c:/luarocks" 58 processor = cfg.target_cpu, -- remains for compat reasons
146 home_config_dir = cfg.home.."/luarocks" 59 target_cpu = cfg.target_cpu, -- replaces `processor`
147 cfg.home_tree = cfg.home.."/luarocks/" 60 os_getenv = os.getenv,
148else 61 variables = cfg.variables or {},
149 cfg.home = os.getenv("HOME") or "" 62 dump_env = function()
150 sys_config_dir = sys_config_dir or "/etc/luarocks" 63 -- debug function, calling it from a config file will show all
151 home_config_dir = cfg.home.."/.luarocks" 64 -- available globals to that config file
152 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/" 65 print(util.show_table(e, "global environment"))
153end 66 end,
67 }
68 return e
69 end
154 70
155-- Create global environment for the config files; 71 -- Merge values from config files read into the `cfg` table
156local env_for_config_file = function() 72 local function merge_overrides(cfg, overrides)
157 local e 73 -- remove some stuff we do not want to integrate
158 e = { 74 overrides.os_getenv = nil
159 home = cfg.home, 75 overrides.dump_env = nil
160 lua_version = cfg.lua_version, 76 -- remove tables to be copied verbatim instead of deeply merged
161 platforms = util.make_shallow_copy(cfg.platforms), 77 if overrides.rocks_trees then cfg.rocks_trees = nil end
162 processor = cfg.target_cpu, -- remains for compat reasons 78 if overrides.rocks_servers then cfg.rocks_servers = nil end
163 target_cpu = cfg.target_cpu, -- replaces `processor` 79 -- perform actual merge
164 os_getenv = os.getenv, 80 util.deep_merge(cfg, overrides)
165 dump_env = function() 81 end
166 -- debug function, calling it from a config file will show all 82
167 -- available globals to that config file 83 local function update_platforms(platforms, overrides)
168 print(util.show_table(e, "global environment")) 84 if overrides[1] then
169 end, 85 for k, _ in pairs(platforms) do
170 } 86 platforms[k] = nil
171 return e 87 end
172end 88 for _, v in ipairs(overrides) do
89 platforms[v] = true
90 end
91 -- set some fallback default in case the user provides an incomplete configuration.
92 -- LuaRocks expects a set of defaults to be available.
93 if not (platforms.unix or platforms.windows) then
94 platforms[is_windows and "windows" or "unix"] = true
95 end
96 end
97 end
173 98
174-- Merge values from config files read into the `cfg` table 99 -- Load config file and merge its contents into the `cfg` module table.
175local merge_overrides = function(overrides) 100 -- @return filepath of succesfully loaded file or nil if it failed
176 -- remove some stuff we do not want to integrate 101 load_config_file = function(cfg, platforms, filepath)
177 overrides.os_getenv = nil 102 local result, err, errcode = persist.load_into_table(filepath, env_for_config_file(cfg, platforms))
178 overrides.dump_env = nil 103 if (not result) and errcode ~= "open" then
179 -- remove tables to be copied verbatim instead of deeply merged 104 -- errcode is either "load" or "run"; bad config file, so error out
180 if overrides.rocks_trees then cfg.rocks_trees = nil end 105 return nil, err, "config"
181 if overrides.rocks_servers then cfg.rocks_servers = nil end 106 end
182 -- perform actual merge 107 if result then
183 util.deep_merge(cfg, overrides) 108 -- success in loading and running, merge contents and exit
109 update_platforms(platforms, result.platforms)
110 result.platforms = nil
111 merge_overrides(cfg, result)
112 return filepath
113 end
114 return nil -- nothing was loaded
115 end
184end 116end
185 117
186-- Load config file and merge its contents into the `cfg` module table. 118local function make_platforms(system)
187-- @return filepath of succesfully loaded file or nil if it failed 119 if system then
188local load_config_file = function(filepath) 120 if system == "Linux" then return { unix = true, linux = true }
189 local result, err, errcode = persist.load_into_table(filepath, env_for_config_file()) 121 elseif system == "FreeBSD" then return { unix = true, bsd = true, freebsd = true }
190 if (not result) and errcode ~= "open" then 122 elseif system == "OpenBSD" then return { unix = true, bsd = true, openbsd = true }
191 -- errcode is either "load" or "run"; bad config file, so error out 123 elseif system == "NetBSD" then return { unix = true, bsd = true, netbsd = true }
192 io.stderr:write(err.."\n") 124 elseif system == "Darwin" then return { unix = true, bsd = true, macosx = true, macos = true }
193 os.exit(3) -- FIXME 125 elseif system == "SunOS" then return { unix = true, solaris = true }
194 end 126 elseif system == "Haiku" then return { unix = true, haiku = true }
195 if result then 127 elseif system:match("^CYGWIN") then return { unix = true, cygwin = true }
196 -- success in loading and running, merge contents and exit 128 elseif system:match("^MSYS") then return { unix = true, cygwin = true, msys = true }
197 merge_overrides(result) 129 elseif system:match("^Windows") then return { windows = true, win32 = true }
198 return filepath 130 elseif system:match("^MINGW") then return { windows = true, win32 = true, mingw32 = true, mingw = true }
199 end 131 end
200 return nil -- nothing was loaded 132 end
133 return { unix = true } -- fallback to Unix in unknown systems
201end 134end
202 135
136--------------------------------------------------------------------------------
203 137
204-- Load system configuration file 138local function make_defaults(lua_version, target_cpu, platforms, home)
205do 139
206 sys_config_file_default = sys_config_dir.."/config-"..cfg.lua_version..".lua" 140 -- Configure defaults:
207 sys_config_file = load_config_file( 141 local defaults = {
208 site_config.LUAROCKS_SYSCONFIG or sys_config_file_default 142
209 ) 143 lua_interpreter = "lua",
210 sys_config_ok = (sys_config_file ~= nil) 144 local_by_default = false,
211end 145 accept_unknown_fields = false,
146 fs_use_modules = true,
147 hooks_enabled = true,
148 deps_mode = "one",
149 check_certificates = false,
150
151 lua_modules_path = "/share/lua/"..lua_version,
152 lib_modules_path = "/lib/lua/"..lua_version,
153 rocks_subdir = "/lib/luarocks/rocks-"..lua_version,
154
155 arch = "unknown",
156 lib_extension = "unknown",
157 obj_extension = "unknown",
158 link_lua_explicitly = false,
159
160 rocks_servers = {
161 {
162 "https://luarocks.org",
163 "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/",
164 "http://luafr.org/moonrocks/",
165 "http://luarocks.logiceditor.com/rocks",
166 }
167 },
168 disabled_servers = {},
212 169
213-- Load user configuration file (if allowed) 170 upload = {
214if not site_config.LUAROCKS_FORCE_CONFIG then 171 server = "https://luarocks.org",
215 172 tool_version = "1.0.0",
216 home_config_file_default = home_config_dir.."/config-"..cfg.lua_version..".lua" 173 api_version = "1",
217 174 },
218 local config_env_var = "LUAROCKS_CONFIG_" .. version_suffix 175
219 local config_env_value = os.getenv(config_env_var) 176 lua_extension = "lua",
220 if not config_env_value then 177 connection_timeout = 30, -- 0 = no timeout
221 config_env_var = "LUAROCKS_CONFIG" 178
222 config_env_value = os.getenv(config_env_var) 179 variables = {
223 end 180 MAKE = "make",
224 181 CC = "cc",
225 -- first try environment provided file, so we can explicitly warn when it is missing 182 LD = "ld",
226 if config_env_value then 183 AR = "ar",
227 home_config_file = load_config_file(config_env_value) 184 RANLIB = "ranlib",
228 home_config_ok = (home_config_file ~= nil) 185
229 if not home_config_ok then 186 CVS = "cvs",
230 io.stderr:write("Warning: could not load configuration file `"..config_env_value.."` given in environment variable "..config_env_var.."\n") 187 GIT = "git",
188 SSCM = "sscm",
189 SVN = "svn",
190 HG = "hg",
191
192 RSYNC = "rsync",
193 WGET = "wget",
194 SCP = "scp",
195 CURL = "curl",
196
197 PWD = "pwd",
198 MKDIR = "mkdir",
199 RMDIR = "rmdir",
200 CP = "cp",
201 LS = "ls",
202 RM = "rm",
203 FIND = "find",
204 TEST = "test",
205 CHMOD = "chmod",
206 ICACLS = "icacls",
207 MKTEMP = "mktemp",
208
209 ZIP = "zip",
210 UNZIP = "unzip -n",
211 GUNZIP = "gunzip",
212 BUNZIP2 = "bunzip2",
213 TAR = "tar",
214
215 MD5SUM = "md5sum",
216 OPENSSL = "openssl",
217 MD5 = "md5",
218 STAT = "stat",
219 TOUCH = "touch",
220
221 CMAKE = "cmake",
222 SEVENZ = "7z",
223
224 RSYNCFLAGS = "--exclude=.git -Oavz",
225 STATPERMFLAG = "-c '%a'",
226 STATOWNERFLAG = "-c '%U'",
227 CURLNOCERTFLAG = "",
228 WGETNOCERTFLAG = "",
229 },
230
231 external_deps_subdirs = {
232 bin = "bin",
233 lib = "lib",
234 include = "include"
235 },
236 runtime_external_deps_subdirs = {
237 bin = "bin",
238 lib = "lib",
239 include = "include"
240 },
241 }
242
243 if platforms.windows then
244
245 defaults.arch = "win32-"..target_cpu
246 defaults.lib_extension = "dll"
247 defaults.external_lib_extension = "dll"
248 defaults.static_lib_extension = "lib"
249 defaults.obj_extension = "obj"
250 defaults.external_deps_dirs = { "c:/external/", "c:/windows/system32" }
251
252 defaults.makefile = "Makefile.win"
253 defaults.variables.MAKE = "nmake"
254 defaults.variables.CC = "cl"
255 defaults.variables.RC = "rc"
256 defaults.variables.LD = "link"
257 defaults.variables.MT = "mt"
258 defaults.variables.AR = "lib"
259 defaults.variables.LUALIB = "lua"..lua_version..".lib"
260 defaults.variables.CFLAGS = "/nologo /MD /O2"
261 defaults.variables.LIBFLAG = "/nologo /dll"
262
263 defaults.variables.LUA_DIR = "c:/lua"
264 defaults.variables.LUA_BINDIR = "c:/lua/bin"
265 defaults.variables.LUA_LIBDIR = "c:/lua/lib"
266 defaults.variables.LUA_INCDIR = "c:/lua/include"
267
268 defaults.external_deps_patterns = {
269 bin = { "?.exe", "?.bat" },
270 lib = { "?.lib", "?.dll", "lib?.dll" },
271 include = { "?.h" }
272 }
273 defaults.runtime_external_deps_patterns = {
274 bin = { "?.exe", "?.bat" },
275 lib = { "?.dll", "lib?.dll" },
276 include = { "?.h" }
277 }
278 defaults.export_path_separator = ";"
279 defaults.wrapper_suffix = ".bat"
280
281 local localappdata = os.getenv("LOCALAPPDATA")
282 if not localappdata then
283 -- for Windows versions below Vista
284 localappdata = os.getenv("USERPROFILE").."/Local Settings/Application Data"
231 end 285 end
286 defaults.local_cache = localappdata.."/LuaRocks/Cache"
287 defaults.web_browser = "start"
288
289 defaults.external_deps_subdirs.lib = { "", "lib" }
290 defaults.runtime_external_deps_subdirs.lib = { "", "lib" }
232 end 291 end
233 292
234 -- try the alternative defaults if there was no environment specified file or it didn't work 293 if platforms.mingw32 then
235 if not home_config_ok then 294 defaults.obj_extension = "o"
236 home_config_file = load_config_file(home_config_file_default) 295 defaults.static_lib_extension = "a"
237 home_config_ok = (home_config_file ~= nil) 296 defaults.external_deps_dirs = { "c:/external/", "c:/mingw", "c:/windows/system32" }
297 defaults.cmake_generator = "MinGW Makefiles"
298 defaults.variables.MAKE = "mingw32-make"
299 defaults.variables.CC = "mingw32-gcc"
300 defaults.variables.RC = "windres"
301 defaults.variables.LD = "mingw32-gcc"
302 defaults.variables.AR = "ar"
303 defaults.variables.RANLIB = "ranlib"
304 defaults.variables.CFLAGS = "-O2"
305 defaults.variables.LIBFLAG = "-shared"
306 defaults.makefile = "Makefile"
307 defaults.external_deps_patterns = {
308 bin = { "?.exe", "?.bat" },
309 -- mingw lookup list from http://stackoverflow.com/a/15853231/1793220
310 -- ...should we keep ?.lib at the end? It's not in the above list.
311 lib = { "lib?.dll.a", "?.dll.a", "lib?.a", "cyg?.dll", "lib?.dll", "?.dll", "?.lib" },
312 include = { "?.h" }
313 }
314 defaults.runtime_external_deps_patterns = {
315 bin = { "?.exe", "?.bat" },
316 lib = { "cyg?.dll", "?.dll", "lib?.dll" },
317 include = { "?.h" }
318 }
238 end 319 end
239end
240 320
321 if platforms.unix then
322 defaults.lib_extension = "so"
323 defaults.static_lib_extension = "a"
324 defaults.external_lib_extension = "so"
325 defaults.obj_extension = "o"
326 defaults.external_deps_dirs = { "/usr/local", "/usr" }
327 defaults.variables.CFLAGS = "-O2"
328 defaults.cmake_generator = "Unix Makefiles"
329 defaults.variables.CC = "gcc"
330 defaults.variables.LD = "gcc"
331 defaults.gcc_rpath = true
332 defaults.variables.LIBFLAG = "-shared"
333
334 defaults.variables.LUA_DIR = "/usr/local"
335 defaults.variables.LUA_BINDIR = "/usr/local/bin"
336 defaults.variables.LUA_LIBDIR = "/usr/local/lib"
337 defaults.variables.LUA_INCDIR = "/usr/local/include"
338
339 defaults.external_deps_patterns = {
340 bin = { "?" },
341 lib = { "lib?.a", "lib?.so", "lib?.so.*" },
342 include = { "?.h" }
343 }
344 defaults.runtime_external_deps_patterns = {
345 bin = { "?" },
346 lib = { "lib?.so", "lib?.so.*" },
347 include = { "?.h" }
348 }
349 defaults.export_path_separator = ":"
350 defaults.wrapper_suffix = ""
351 defaults.local_cache = home.."/.cache/luarocks"
352 if not defaults.variables.CFLAGS:match("-fPIC") then
353 defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC"
354 end
355 defaults.web_browser = "xdg-open"
356 end
241 357
242if not next(cfg.rocks_trees) then 358 if platforms.cygwin then
243 if cfg.home_tree then 359 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds
244 table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } ) 360 defaults.arch = "cygwin-"..target_cpu
361 defaults.cmake_generator = "Unix Makefiles"
362 defaults.variables.CC = "echo -llua | xargs gcc"
363 defaults.variables.LD = "echo -llua | xargs gcc"
364 defaults.variables.LIBFLAG = "-shared"
365 defaults.link_lua_explicitly = true
245 end 366 end
246 if site_config.LUAROCKS_ROCKS_TREE then 367
247 table.insert(cfg.rocks_trees, { name = "system", root = site_config.LUAROCKS_ROCKS_TREE } ) 368 if platforms.msys then
369 -- msys is basically cygwin made out of mingw, meaning the subsytem is unixish
370 -- enough, yet we can freely mix with native win32
371 defaults.external_deps_patterns = {
372 bin = { "?.exe", "?.bat", "?" },
373 lib = { "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a",
374 "lib?.a", "lib?.dll", "?.dll", "?.lib" },
375 include = { "?.h" }
376 }
377 defaults.runtime_external_deps_patterns = {
378 bin = { "?.exe", "?.bat" },
379 lib = { "lib?.so", "?.dll", "lib?.dll" },
380 include = { "?.h" }
381 }
248 end 382 end
249end
250 383
251-- update platforms list; keyed -> array 384 if platforms.bsd then
252do 385 defaults.variables.MAKE = "gmake"
253 -- if explicitly given by user, 386 defaults.variables.STATPERMFLAG = "-f '%OLp'"
254 if cfg.platforms[1] then 387 defaults.variables.STATOWNERFLAG = "-f '%Su'"
255 local is_windows = cfg.platforms.windows 388 end
256 -- Clear auto-detected values 389
257 for k, _ in pairs(cfg.platforms) do 390 if platforms.macosx then
258 if type(k) == "string" then 391 defaults.variables.MAKE = "make"
259 cfg.platforms[k] = nil 392 defaults.external_lib_extension = "dylib"
260 end 393 defaults.arch = "macosx-"..target_cpu
261 end 394 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load"
262 -- and set the ones given by the user. 395 defaults.variables.STAT = "/usr/bin/stat"
263 for _, plat in ipairs(cfg.platforms) do 396 defaults.variables.STATFLAG = "-f '%A'"
264 cfg.platforms[plat] = true 397 local version = util.popen_read("sw_vers -productVersion")
265 end 398 version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3
266 -- If no major platform family was set by the user, 399 if version >= 10 then
267 if not (cfg.platforms.unix or cfg.platforms.windows) then 400 version = 8
268 -- set some fallback defaults in case the user provides an incomplete configuration. 401 elseif version >= 5 then
269 -- LuaRocks expects a set of defaults to be available. 402 version = 5
270 -- This is used for setting defaults here only; the platform overrides 403 else
271 -- will use only the user's list. 404 defaults.gcc_rpath = false
272 if is_windows then
273 cfg.platforms.windows = true
274 table.insert(cfg.platforms, "windows")
275 else
276 cfg.platforms.unix = true
277 table.insert(cfg.platforms, "unix")
278 end
279 end
280 else
281 -- Sort detected platform defaults
282 local order = {}
283 for i, v in ipairs(platform_order) do
284 order[v] = i
285 end
286 local entries = {}
287 for k, v in pairs(cfg.platforms) do
288 if type(k) == "string" and v == true then
289 table.insert(entries, k)
290 end
291 end 405 end
292 table.sort(entries, function(a, b) return order[a] < order[b] end) 406 defaults.variables.CC = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc"
293 util.deep_merge(cfg.platforms, entries) 407 defaults.variables.LD = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc"
408 defaults.web_browser = "open"
294 end 409 end
295end
296 410
297-- Configure defaults: 411 if platforms.linux then
298local defaults = { 412 defaults.arch = "linux-"..target_cpu
299
300 local_by_default = false,
301 accept_unknown_fields = false,
302 fs_use_modules = true,
303 hooks_enabled = true,
304 deps_mode = "one",
305 check_certificates = false,
306
307 lua_modules_path = "/share/lua/"..cfg.lua_version,
308 lib_modules_path = "/lib/lua/"..cfg.lua_version,
309 rocks_subdir = "/lib/luarocks/rocks-"..cfg.lua_version,
310
311 arch = "unknown",
312 lib_extension = "unknown",
313 obj_extension = "unknown",
314 link_lua_explicitly = false,
315
316 rocks_servers = {
317 {
318 "https://luarocks.org",
319 "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/",
320 "http://luafr.org/moonrocks/",
321 "http://luarocks.logiceditor.com/rocks",
322 }
323 },
324 disabled_servers = {},
325
326 upload = {
327 server = "https://luarocks.org",
328 tool_version = "1.0.0",
329 api_version = "1",
330 },
331
332 lua_extension = "lua",
333 lua_interpreter = site_config.LUA_INTERPRETER or "lua",
334 downloader = site_config.LUAROCKS_DOWNLOADER or "wget",
335 md5checker = site_config.LUAROCKS_MD5CHECKER or "md5sum",
336 connection_timeout = 30, -- 0 = no timeout
337
338 variables = {
339 MAKE = "make",
340 CC = "cc",
341 LD = "ld",
342 AR = "ar",
343 RANLIB = "ranlib",
344
345 CVS = "cvs",
346 GIT = "git",
347 SSCM = "sscm",
348 SVN = "svn",
349 HG = "hg",
350
351 RSYNC = "rsync",
352 WGET = "wget",
353 SCP = "scp",
354 CURL = "curl",
355
356 PWD = "pwd",
357 MKDIR = "mkdir",
358 RMDIR = "rmdir",
359 CP = "cp",
360 LS = "ls",
361 RM = "rm",
362 FIND = "find",
363 TEST = "test",
364 CHMOD = "chmod",
365 ICACLS = "icacls",
366 MKTEMP = "mktemp",
367
368 ZIP = "zip",
369 UNZIP = "unzip -n",
370 GUNZIP = "gunzip",
371 BUNZIP2 = "bunzip2",
372 TAR = "tar",
373
374 MD5SUM = "md5sum",
375 OPENSSL = "openssl",
376 MD5 = "md5",
377 STAT = "stat",
378 TOUCH = "touch",
379
380 CMAKE = "cmake",
381 SEVENZ = "7z",
382
383 RSYNCFLAGS = "--exclude=.git -Oavz",
384 STATPERMFLAG = "-c '%a'",
385 STATOWNERFLAG = "-c '%U'",
386 CURLNOCERTFLAG = "",
387 WGETNOCERTFLAG = "",
388 },
389
390 external_deps_subdirs = site_config.LUAROCKS_EXTERNAL_DEPS_SUBDIRS or {
391 bin = "bin",
392 lib = "lib",
393 include = "include"
394 },
395 runtime_external_deps_subdirs = site_config.LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS or {
396 bin = "bin",
397 lib = "lib",
398 include = "include"
399 },
400
401 rocks_provided = {},
402 rocks_provided_3_0 = {},
403}
404 413
405if cfg.platforms.windows then 414 local gcc_arch = util.popen_read("gcc -print-multiarch 2>/dev/null")
406 local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])) 415 if gcc_arch and gcc_arch ~= "" then
407 extra_luarocks_module_dir = full_prefix.."/lua/?.lua" 416 defaults.external_deps_subdirs.lib = { "lib", "lib/" .. gcc_arch, "lib64" }
408 417 defaults.runtime_external_deps_subdirs.lib = { "lib", "lib/" .. gcc_arch, "lib64" }
409 home_config_file = home_config_file and home_config_file:gsub("\\","/") 418 else
410 defaults.fs_use_modules = false 419 defaults.external_deps_subdirs.lib = { "lib", "lib64" }
411 defaults.arch = "win32-"..cfg.target_cpu 420 defaults.runtime_external_deps_subdirs.lib = { "lib", "lib64" }
412 defaults.lib_extension = "dll"
413 defaults.external_lib_extension = "dll"
414 defaults.static_lib_extension = "lib"
415 defaults.obj_extension = "obj"
416 defaults.external_deps_dirs = { "c:/external", "c:/windows/system32" }
417 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/bin"
418 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/include"
419 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/lib"
420
421 defaults.makefile = "Makefile.win"
422 defaults.variables.MAKE = "nmake"
423 defaults.variables.CC = "cl"
424 defaults.variables.RC = "rc"
425 defaults.variables.WRAPPER = full_prefix.."\\rclauncher.c"
426 defaults.variables.LD = "link"
427 defaults.variables.MT = "mt"
428 defaults.variables.AR = "lib"
429 defaults.variables.LUALIB = "lua"..cfg.lua_version..".lib"
430 defaults.variables.CFLAGS = "/nologo /MD /O2"
431 defaults.variables.LIBFLAG = "/nologo /dll"
432
433 local bins = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM",
434 "MKDIR", "MV", "PWD", "RMDIR", "TEST", "UNAME", "WGET" }
435 for _, var in ipairs(bins) do
436 if defaults.variables[var] then
437 defaults.variables[var] = full_prefix.."\\tools\\"..defaults.variables[var]
438 end 421 end
439 end 422 end
440 423
441 defaults.external_deps_patterns = { 424 if platforms.freebsd then
442 bin = { "?.exe", "?.bat" }, 425 defaults.arch = "freebsd-"..target_cpu
443 lib = { "?.lib", "?.dll", "lib?.dll" }, 426 defaults.gcc_rpath = false
444 include = { "?.h" } 427 defaults.variables.CC = "cc"
445 } 428 defaults.variables.LD = "cc"
446 defaults.runtime_external_deps_patterns = {
447 bin = { "?.exe", "?.bat" },
448 lib = { "?.dll", "lib?.dll" },
449 include = { "?.h" }
450 }
451 defaults.export_path_separator = ";"
452 defaults.wrapper_suffix = ".bat"
453
454 local localappdata = os.getenv("LOCALAPPDATA")
455 if not localappdata then
456 -- for Windows versions below Vista
457 localappdata = os.getenv("USERPROFILE").."/Local Settings/Application Data"
458 end 429 end
459 defaults.local_cache = localappdata.."/LuaRocks/Cache"
460 defaults.web_browser = "start"
461 430
462 defaults.external_deps_subdirs = site_config.LUAROCKS_EXTERNAL_DEPS_SUBDIRS or { 431 if platforms.openbsd then
463 bin = {".", "bin"}, 432 defaults.arch = "openbsd-"..target_cpu
464 lib = {".", "lib"}, 433 end
465 include = {".", "include"},
466 }
467 defaults.runtime_external_deps_subdirs = site_config.LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS or {
468 bin = {".", "bin"},
469 lib = {".", "lib"},
470 include = {".", "include"},
471 }
472 434
473end 435 if platforms.netbsd then
436 defaults.arch = "netbsd-"..target_cpu
437 end
474 438
475if cfg.platforms.mingw32 then 439 if platforms.solaris then
476 defaults.obj_extension = "o" 440 defaults.arch = "solaris-"..target_cpu
477 defaults.static_lib_extension = "a" 441 --defaults.platforms = {"unix", "solaris"}
478 defaults.cmake_generator = "MinGW Makefiles" 442 defaults.variables.MAKE = "gmake"
479 defaults.variables.MAKE = "mingw32-make" 443 end
480 defaults.variables.CC = "mingw32-gcc"
481 defaults.variables.RC = "windres"
482 defaults.variables.LD = "mingw32-gcc"
483 defaults.variables.AR = "ar"
484 defaults.variables.RANLIB = "ranlib"
485 defaults.variables.CFLAGS = "-O2"
486 defaults.variables.LIBFLAG = "-shared"
487 defaults.makefile = "Makefile"
488 defaults.external_deps_dirs = { "c:/external", "c:/mingw", "c:/windows/system32" }
489 defaults.external_deps_patterns = {
490 bin = { "?.exe", "?.bat" },
491 -- mingw lookup list from http://stackoverflow.com/a/15853231/1793220
492 -- ...should we keep ?.lib at the end? It's not in the above list.
493 lib = { "lib?.dll.a", "?.dll.a", "lib?.a", "cyg?.dll", "lib?.dll", "?.dll", "?.lib" },
494 include = { "?.h" }
495 }
496 defaults.runtime_external_deps_patterns = {
497 bin = { "?.exe", "?.bat" },
498 lib = { "cyg?.dll", "?.dll", "lib?.dll" },
499 include = { "?.h" }
500 }
501 444
502end 445 -- Expose some more values detected by LuaRocks for use by rockspec authors.
446 defaults.variables.LIB_EXTENSION = defaults.lib_extension
447 defaults.variables.OBJ_EXTENSION = defaults.obj_extension
503 448
504if cfg.platforms.unix then 449 return defaults
505 defaults.lib_extension = "so"
506 defaults.static_lib_extension = "a"
507 defaults.external_lib_extension = "so"
508 defaults.obj_extension = "o"
509 defaults.external_deps_dirs = { "/usr/local", "/usr" }
510 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR or "/usr/local/bin"
511 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR or "/usr/local/include"
512 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR or "/usr/local/lib"
513 defaults.variables.CFLAGS = "-O2"
514 defaults.cmake_generator = "Unix Makefiles"
515 defaults.variables.CC = "gcc"
516 defaults.variables.LD = "gcc"
517 defaults.gcc_rpath = true
518 defaults.variables.LIBFLAG = "-shared"
519 defaults.external_deps_patterns = {
520 bin = { "?" },
521 lib = { "lib?.a", "lib?.so", "lib?.so.*" },
522 include = { "?.h" }
523 }
524 defaults.runtime_external_deps_patterns = {
525 bin = { "?" },
526 lib = { "lib?.so", "lib?.so.*" },
527 include = { "?.h" }
528 }
529 defaults.export_path_separator = ":"
530 defaults.wrapper_suffix = ""
531 defaults.local_cache = cfg.home.."/.cache/luarocks"
532 if not defaults.variables.CFLAGS:match("-fPIC") then
533 defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC"
534 end
535 defaults.web_browser = "xdg-open"
536end 450end
537 451
538if cfg.platforms.cygwin then 452local function make_rocks_provided(lua_version, luajit_version)
539 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds 453 local rocks_provided = {}
540 defaults.arch = "cygwin-"..cfg.target_cpu 454 local rocks_provided_3_0 = {}
541 defaults.cmake_generator = "Unix Makefiles"
542 defaults.variables.CC = "echo -llua | xargs gcc"
543 defaults.variables.LD = "echo -llua | xargs gcc"
544 defaults.variables.LIBFLAG = "-shared"
545 defaults.link_lua_explicitly = true
546end
547 455
548if cfg.platforms.msys then 456 rocks_provided["lua"] = lua_version.."-1"
549 -- msys is basically cygwin made out of mingw, meaning the subsytem is unixish
550 -- enough, yet we can freely mix with native win32
551 defaults.external_deps_patterns = {
552 bin = { "?.exe", "?.bat", "?" },
553 lib = { "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a",
554 "lib?.a", "lib?.dll", "?.dll", "?.lib" },
555 include = { "?.h" }
556 }
557 defaults.runtime_external_deps_patterns = {
558 bin = { "?.exe", "?.bat" },
559 lib = { "lib?.so", "?.dll", "lib?.dll" },
560 include = { "?.h" }
561 }
562end
563 457
458 if lua_version == "5.2" or lua_version == "5.3" then
459 rocks_provided["bit32"] = lua_version.."-1"
460 end
564 461
565if cfg.platforms.bsd then 462 if lua_version == "5.3" or lua_version == "5.4" then
566 defaults.variables.MAKE = "gmake" 463 rocks_provided["utf8"] = lua_version.."-1"
567 defaults.variables.STATPERMFLAG = "-f '%OLp'" 464 end
568 defaults.variables.STATOWNERFLAG = "-f '%Su'"
569end
570 465
571if cfg.platforms.macosx then 466 if luajit_version then
572 defaults.variables.MAKE = "make" 467 rocks_provided["luabitop"] = luajit_version.."-1"
573 defaults.external_lib_extension = "dylib" 468 rocks_provided_3_0["luajit"] = luajit_version.."-1"
574 defaults.arch = "macosx-"..cfg.target_cpu
575 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load"
576 defaults.variables.STAT = "/usr/bin/stat"
577 defaults.variables.STATFLAG = "-f '%A'"
578 local version = util.popen_read("sw_vers -productVersion")
579 version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3
580 if version >= 10 then
581 version = 8
582 elseif version >= 5 then
583 version = 5
584 else
585 defaults.gcc_rpath = false
586 end 469 end
587 defaults.variables.CC = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc"
588 defaults.variables.LD = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc"
589 defaults.web_browser = "open"
590end
591 470
592if cfg.platforms.linux then 471 return rocks_provided, rocks_provided_3_0
593 defaults.arch = "linux-"..cfg.target_cpu
594end 472end
595 473
596if cfg.platforms.freebsd then 474local function use_defaults(cfg, defaults)
597 defaults.arch = "freebsd-"..cfg.target_cpu
598 defaults.gcc_rpath = false
599 defaults.variables.CC = "cc"
600 defaults.variables.LD = "cc"
601end
602 475
603if cfg.platforms.openbsd then 476 -- Populate some arrays with values from their 'defaults' counterparts
604 defaults.arch = "openbsd-"..cfg.target_cpu 477 -- if they were not already set by user.
605end 478 for _, entry in ipairs({"variables", "rocks_provided"}) do
479 if not cfg[entry] then
480 cfg[entry] = {}
481 end
482 for k,v in pairs(defaults[entry]) do
483 if not cfg[entry][k] then
484 cfg[entry][k] = v
485 end
486 end
487 end
488 util.deep_merge_under(defaults.rocks_provided_3_0, cfg.rocks_provided)
606 489
607if cfg.platforms.netbsd then 490 util.deep_merge_under(cfg, defaults)
608 defaults.arch = "netbsd-"..cfg.target_cpu
609end
610 491
611if cfg.platforms.solaris then 492 -- FIXME get rid of this
612 defaults.arch = "solaris-"..cfg.target_cpu 493 if not cfg.check_certificates then
613 --defaults.platforms = {"unix", "solaris"} 494 cfg.variables.CURLNOCERTFLAG = "-k"
614 defaults.variables.MAKE = "gmake" 495 cfg.variables.WGETNOCERTFLAG = "--no-check-certificate"
496 end
615end 497end
616 498
617-- Expose some more values detected by LuaRocks for use by rockspec authors. 499--------------------------------------------------------------------------------
618defaults.variables.LIB_EXTENSION = defaults.lib_extension
619defaults.variables.OBJ_EXTENSION = defaults.obj_extension
620defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX
621defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter
622 500
623-- Add built-in modules to rocks_provided 501local cfg = {}
624defaults.rocks_provided["lua"] = cfg.lua_version.."-1"
625 502
626if bit32 then -- Lua 5.2+ 503function cfg.init(lua_data, warning)
627 defaults.rocks_provided["bit32"] = cfg.lua_version.."-1" 504 lua_data = lua_data or {}
628end
629 505
630if utf8 then -- Lua 5.3+ 506 local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded")
631 defaults.rocks_provided["utf8"] = cfg.lua_version.."-1" 507 if not hc_ok then
632end 508 hardcoded = {}
509 end
633 510
634if package.loaded.jit then 511 local lua_version = lua_data.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5)
635 -- LuaJIT 512 local luajit_version = lua_data.luajit_version or hardcoded.LUAJIT_VERSION or (jit and jit.version:sub(8))
636 local lj_version = package.loaded.jit.version:match("LuaJIT (.*)"):gsub("%-","") 513 local lua_interpreter = lua_data.lua_interpreter or hardcoded.LUA_INTERPRETER or (arg[-1] and arg[-1]:gsub(".*[\\/]", "")) or (is_windows and "lua.exe" or "lua")
637 defaults.rocks_provided["luabitop"] = lj_version.."-1" 514 local lua_bindir = lua_data.lua_bindir or hardcoded.LUA_BINDIR or (arg[-1] and arg[-1]:gsub("[\\/][^\\/]+$", ""))
638 defaults.rocks_provided_3_0["luajit"] = lj_version.."-1" 515 local lua_incdir = lua_data.lua_incdir or hardcoded.LUA_INCDIR
639end 516 local lua_libdir = lua_data.lua_libdir or hardcoded.LUA_LIBDIR
517 local lua_dir = lua_data.lua_dir or hardcoded.LUA_DIR
518
519 local init = cfg.init
640 520
641-- Use defaults: 521 ----------------------------------------
522 -- Reset the cfg table.
523 ----------------------------------------
642 524
643-- Populate some arrays with values from their 'defaults' counterparts 525 for k, _ in pairs(cfg) do
644-- if they were not already set by user. 526 cfg[k] = nil
645for _, entry in ipairs({"variables", "rocks_provided"}) do
646 if not cfg[entry] then
647 cfg[entry] = {}
648 end
649 for k,v in pairs(defaults[entry]) do
650 if not cfg[entry][k] then
651 cfg[entry][k] = v
652 end
653 end 527 end
654end
655setmetatable(defaults.rocks_provided_3_0, { __index = cfg.rocks_provided })
656
657-- For values not set in the config file, use values from the 'defaults' table.
658local cfg_mt = {
659 __index = function(t, k)
660 local default = defaults[k]
661 if default then
662 rawset(t, k, default)
663 end
664 return default
665 end
666}
667setmetatable(cfg, cfg_mt)
668 528
669if not cfg.check_certificates then 529 cfg.program_version = program_version
670 cfg.variables.CURLNOCERTFLAG = "-k" 530 cfg.program_series = program_series
671 cfg.variables.WGETNOCERTFLAG = "--no-check-certificate" 531 cfg.major_version = major_version
672end
673 532
674function cfg.make_paths_from_tree(tree) 533 cfg.lua_version = lua_version
675 local lua_path, lib_path, bin_path 534 cfg.luajit_version = luajit_version
676 if type(tree) == "string" then 535 cfg.lua_interpreter = lua_interpreter
677 lua_path = tree..cfg.lua_modules_path 536
678 lib_path = tree..cfg.lib_modules_path 537 cfg.variables = {
679 bin_path = tree.."/bin" 538 LUA_DIR = lua_dir,
539 LUA_BINDIR = lua_bindir,
540 LUA_INCDIR = lua_incdir,
541 LUA_LIBDIR = lua_libdir,
542 }
543
544 cfg.rocks_trees = {}
545
546 cfg.init = init
547
548 ----------------------------------------
549 -- System detection.
550 ----------------------------------------
551
552 -- A proper build of LuaRocks will hardcode the system
553 -- and proc values with hardcoded.SYSTEM and hardcoded.PROCESSOR.
554 -- If that is not available, we try to identify the system.
555 local system = hardcoded.SYSTEM
556 local processor = hardcoded.PROCESSOR
557 if is_windows then
558 system = system or "Windows"
559 if not processor then
560 local pe_parser = require("luarocks.fs.win32.pe-parser")
561 local err
562 local lua_exe = lua_bindir .. "\\" .. lua_interpreter
563 processor, err = pe_parser.get_architecture(lua_exe)
564 if err then
565 processor = "x86"
566 end
567 end
680 else 568 else
681 lua_path = tree.lua_dir or tree.root..cfg.lua_modules_path 569 system = system or util.popen_read("uname -s")
682 lib_path = tree.lib_dir or tree.root..cfg.lib_modules_path 570 processor = processor or util.popen_read("uname -m")
683 bin_path = tree.bin_dir or tree.root.."/bin"
684 end 571 end
685 return lua_path, lib_path, bin_path
686end
687 572
688function cfg.package_paths(current) 573 cfg.target_cpu = processor
689 local new_path, new_cpath, new_bin = {}, {}, {} 574
690 local function add_tree_to_paths(tree) 575 local platforms = make_platforms(system)
691 local lua_path, lib_path, bin_path = cfg.make_paths_from_tree(tree) 576
692 table.insert(new_path, lua_path.."/?.lua") 577 ----------------------------------------
693 table.insert(new_path, lua_path.."/?/init.lua") 578 -- Platform is determined.
694 table.insert(new_cpath, lib_path.."/?."..cfg.lib_extension) 579 -- Let's load the config files.
695 table.insert(new_bin, bin_path) 580 ----------------------------------------
696 end 581
697 if current then 582 local sys_config_file
698 add_tree_to_paths(current) 583 local home_config_file
584 do
585 local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR
586 local sdir, hdir
587 if platforms.windows then
588 cfg.home = os.getenv("APPDATA") or "c:"
589 sdir = sysconfdir or (os.getenv("PROGRAMFILES") or "c:") .. "/luarocks"
590 hdir = cfg.home.."/luarocks"
591 cfg.home_tree = cfg.home.."/luarocks"
592 else
593 cfg.home = os.getenv("HOME") or ""
594 sdir = sysconfdir or "/etc/luarocks"
595 hdir = cfg.home.."/.luarocks"
596 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/"
597 end
598 sys_config_file = sdir .. "/config-"..cfg.lua_version..".lua"
599 home_config_file = hdir .. "/config-"..cfg.lua_version..".lua"
600
601 sys_config_file = sys_config_file:gsub("\\", "/")
602 home_config_file = home_config_file:gsub("\\", "/")
699 end 603 end
700 for _,tree in ipairs(cfg.rocks_trees) do 604
701 add_tree_to_paths(tree) 605 -- Load system configuration file
606 local sys_config_ok, err = load_config_file(cfg, platforms, sys_config_file)
607 if err then
608 return nil, err, "config"
702 end 609 end
703 if extra_luarocks_module_dir then 610
704 table.insert(new_path, extra_luarocks_module_dir) 611 -- Load user configuration file (if allowed)
612 local home_config_ok
613 if not hardcoded.FORCE_CONFIG then
614 local env_var = "LUAROCKS_CONFIG_" .. lua_version:gsub("%.", "_")
615 local env_value = os.getenv(env_var)
616 if not env_value then
617 env_var = "LUAROCKS_CONFIG"
618 env_value = os.getenv(env_var)
619 end
620 -- first try environment provided file, so we can explicitly warn when it is missing
621 if env_value then
622 local env_ok, err = load_config_file(cfg, platforms, env_value)
623 if err then
624 return nil, err, "config"
625 elseif warning and not env_ok then
626 warning("Warning: could not load configuration file `"..env_value.."` given in environment variable "..env_var.."\n")
627 end
628 if env_ok then
629 home_config_ok = true
630 home_config_file = env_value
631 end
632 end
633
634 -- try the alternative defaults if there was no environment specified file or it didn't work
635 if not home_config_ok then
636 home_config_ok = load_config_file(cfg, platforms, home_config_file)
637 if err then
638 return nil, err, "config"
639 end
640 end
705 end 641 end
706 return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator)
707end
708 642
709function cfg.init_package_paths() 643 ----------------------------------------
710 local lr_path, lr_cpath, lr_bin = cfg.package_paths() 644 -- Config files are loaded.
711 package.path = util.cleanup_path(package.path .. ";" .. lr_path, ";", cfg.lua_version) 645 -- Let's finish up the cfg table.
712 package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", cfg.lua_version) 646 ----------------------------------------
713end 647
648 -- Settings given via lua_data (i.e. --lua-dir) take precedence over config files:
649 cfg.lua_version = lua_data.lua_version or cfg.lua_version
650 cfg.luajit_version = lua_data.luajit_version or cfg.luajit_version
651 cfg.lua_interpreter = lua_data.lua_interpreter or cfg.lua_interpreter
652 cfg.variables.LUA_BINDIR = lua_data.lua_bindir or cfg.variables.LUA_BINDIR
653 cfg.variables.LUA_INCDIR = lua_data.lua_incdir or cfg.variables.LUA_INCDIR
654 cfg.variables.LUA_LIBDIR = lua_data.lua_libdir or cfg.variables.LUA_LIBDIR
655
656 -- Build a default list of rocks trees if not given
657 if not next(cfg.rocks_trees) then
658 if cfg.home_tree then
659 table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } )
660 end
661 if hardcoded.PREFIX then
662 table.insert(cfg.rocks_trees, { name = "system", root = hardcoded.PREFIX } )
663 end
664 end
714 665
715function cfg.which_config() 666 local defaults = make_defaults(lua_version, processor, platforms, cfg.home)
716 local ret = { 667 defaults.rocks_provided, defaults.rocks_provided_3_0 = make_rocks_provided(lua_version, luajit_version)
717 system = { 668 use_defaults(cfg, defaults)
718 file = sys_config_file or sys_config_file_default, 669
719 ok = sys_config_ok, 670 cfg.variables.LUA = cfg.variables.LUA or cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter
720 }, 671 cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch
721 user = { 672
722 file = home_config_file or home_config_file_default, 673 ----------------------------------------
723 ok = home_config_ok, 674 -- Attributes of cfg are set.
675 -- Let's add some methods.
676 ----------------------------------------
677
678 function cfg.which_config()
679 return {
680 system = {
681 file = sys_config_file,
682 ok = sys_config_ok,
683 },
684 user = {
685 file = home_config_file,
686 ok = home_config_ok,
687 },
688 nearest = home_config_ok and home_config_file or sys_config_file,
724 } 689 }
725 } 690 end
726 ret.nearest = (ret.user.ok and ret.user.file) or ret.system.file 691
727 return ret 692 do
728end 693 local function make_paths_from_tree(tree)
694 local lua_path, lib_path, bin_path
695 if type(tree) == "string" then
696 lua_path = tree..cfg.lua_modules_path
697 lib_path = tree..cfg.lib_modules_path
698 bin_path = tree.."/bin"
699 else
700 lua_path = tree.lua_dir or tree.root..cfg.lua_modules_path
701 lib_path = tree.lib_dir or tree.root..cfg.lib_modules_path
702 bin_path = tree.bin_dir or tree.root.."/bin"
703 end
704 return lua_path, lib_path, bin_path
705 end
729 706
730cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch 707 function cfg.package_paths(current)
708 local new_path, new_cpath, new_bin = {}, {}, {}
709 local function add_tree_to_paths(tree)
710 local lua_path, lib_path, bin_path = make_paths_from_tree(tree)
711 table.insert(new_path, lua_path.."/?.lua")
712 table.insert(new_path, lua_path.."/?/init.lua")
713 table.insert(new_cpath, lib_path.."/?."..cfg.lib_extension)
714 table.insert(new_bin, bin_path)
715 end
716 if current then
717 add_tree_to_paths(current)
718 end
719 for _,tree in ipairs(cfg.rocks_trees) do
720 add_tree_to_paths(tree)
721 end
722 return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator)
723 end
724 end
731 725
732cfg.http_proxy = os.getenv("http_proxy") 726 function cfg.init_package_paths()
733cfg.https_proxy = os.getenv("https_proxy") 727 local lr_path, lr_cpath, lr_bin = cfg.package_paths()
734cfg.no_proxy = os.getenv("no_proxy") 728 package.path = util.cleanup_path(package.path .. ";" .. lr_path, ";", lua_version)
729 package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", lua_version)
730 end
735 731
736--- Check if platform was detected 732 --- Check if platform was detected
737-- @param query string: The platform name to check. 733 -- @param name string: The platform name to check.
738-- @return boolean: true if LuaRocks is currently running on queried platform. 734 -- @return boolean: true if LuaRocks is currently running on queried platform.
739function cfg.is_platform(query) 735 function cfg.is_platform(name)
740 assert(type(query) == "string") 736 assert(type(name) == "string")
737 return platforms[name]
738 end
741 739
742 for _, platform in ipairs(cfg.platforms) do 740 function cfg.each_platform()
743 if platform == query then 741 local i = 0
744 return true 742 return function()
743 local p
744 repeat
745 i = i + 1
746 p = platform_order[i]
747 until (not p) or platforms[p]
748 return p
745 end 749 end
746 end 750 end
747end
748 751
749function cfg.each_platform() 752 function cfg.print_platforms()
750 local i = 0 753 return table.concat(platforms, ", ")
751 return function()
752 i = i + 1
753 return cfg.platforms[i]
754 end 754 end
755
756 return true
755end 757end
756 758
757return cfg 759return cfg
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index bcd6ccf5..3217a18f 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -187,30 +187,24 @@ end
187-- nil and an error message if any test failed, followed by an optional 187-- nil and an error message if any test failed, followed by an optional
188-- error code. 188-- error code.
189function deps.fulfill_dependencies(rockspec, depskey, deps_mode) 189function deps.fulfill_dependencies(rockspec, depskey, deps_mode)
190 if rockspec.supported_platforms then 190 if rockspec.supported_platforms and next(rockspec.supported_platforms) then
191 if not deps.platforms_set then 191 local supported = false
192 deps.platforms_set = values_set(cfg.platforms)
193 end
194 local supported = nil
195 for _, plat in pairs(rockspec.supported_platforms) do 192 for _, plat in pairs(rockspec.supported_platforms) do
196 local neg 193 local neg
197 neg, plat = plat:match("^(!?)(.*)") 194 neg, plat = plat:match("^(!?)(.*)")
198 if neg == "!" then 195 if neg == "!" then
199 if deps.platforms_set[plat] then 196 if cfg.is_platform(plat) then
200 return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms." 197 return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms."
201 end 198 end
202 else 199 else
203 if deps.platforms_set[plat] then 200 if cfg.is_platform(plat) then
204 supported = true 201 supported = true
205 else 202 break
206 if supported == nil then
207 supported = false
208 end
209 end 203 end
210 end 204 end
211 end 205 end
212 if supported == false then 206 if supported == false then
213 local plats = table.concat(cfg.platforms, ", ") 207 local plats = cfg.print_platforms()
214 return nil, "This rockspec for "..rockspec.package.." does not support "..plats.." platforms." 208 return nil, "This rockspec for "..rockspec.package.." does not support "..plats.." platforms."
215 end 209 end
216 end 210 end
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index b53ef8cc..88fc31d9 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -557,7 +557,7 @@ local redirect_protocols = {
557local function request(url, method, http, loop_control) 557local function request(url, method, http, loop_control)
558 local result = {} 558 local result = {}
559 559
560 local proxy = cfg.http_proxy 560 local proxy = os.getenv("http_proxy")
561 if type(proxy) ~= "string" then proxy = nil end 561 if type(proxy) ~= "string" then proxy = nil end
562 -- LuaSocket's http.request crashes when given URLs missing the scheme part. 562 -- LuaSocket's http.request crashes when given URLs missing the scheme part.
563 if proxy and not proxy:find("://") then 563 if proxy and not proxy:find("://") then
@@ -691,7 +691,7 @@ function fs_lua.download(url, filename, cache)
691 filename = fs.absolute_name(filename or dir.base_name(url)) 691 filename = fs.absolute_name(filename or dir.base_name(url))
692 692
693 -- delegate to the configured downloader so we don't have to deal with whitelists 693 -- delegate to the configured downloader so we don't have to deal with whitelists
694 if cfg.no_proxy then 694 if os.getenv("no_proxy") then
695 return fs.use_downloader(url, filename, cache) 695 return fs.use_downloader(url, filename, cache)
696 end 696 end
697 697
@@ -702,7 +702,7 @@ function fs_lua.download(url, filename, cache)
702 ok, err = ftp_request(url, filename) 702 ok, err = ftp_request(url, filename)
703 elseif util.starts_with(url, "https:") then 703 elseif util.starts_with(url, "https:") then
704 -- skip LuaSec when proxy is enabled since it is not supported 704 -- skip LuaSec when proxy is enabled since it is not supported
705 if luasec_ok and not cfg.https_proxy then 705 if luasec_ok and not os.getenv("https_proxy") then
706 ok, err = http_request(url, filename, https, cache) 706 ok, err = http_request(url, filename, https, cache)
707 else 707 else
708 https_err = true 708 https_err = true
@@ -919,7 +919,7 @@ function fs_lua.is_lua(filename)
919 filename = filename:gsub([[%\]],"/") -- normalize on fw slash to prevent escaping issues 919 filename = filename:gsub([[%\]],"/") -- normalize on fw slash to prevent escaping issues
920 local lua = fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)) -- get lua interpreter configured 920 local lua = fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)) -- get lua interpreter configured
921 -- execute on configured interpreter, might not be the same as the interpreter LR is run on 921 -- execute on configured interpreter, might not be the same as the interpreter LR is run on
922 local result = fs.execute_string(lua..[[ -e "if loadfile(']]..filename..[[') then os.exit() else os.exit(1) end"]]) 922 local result = fs.execute_string(lua..[[ -e "if loadfile(']]..filename..[[') then os.exit(0) else os.exit(1) end"]])
923 return (result == true) 923 return (result == true)
924end 924end
925 925
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua
index 078e4068..537adf94 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -16,7 +16,10 @@ local is_clean = not package.loaded["luarocks.core.cfg"]
16 16
17-- This loader module depends only on core modules. 17-- This loader module depends only on core modules.
18local cfg = require("luarocks.core.cfg") 18local cfg = require("luarocks.core.cfg")
19cfg.init_package_paths() 19local cfg_ok, err = cfg.init()
20if cfg_ok then
21 cfg.init_package_paths()
22end
20 23
21local path = require("luarocks.core.path") 24local path = require("luarocks.core.path")
22local manif = require("luarocks.core.manif") 25local manif = require("luarocks.core.manif")
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 5a111dbb..fd2b7b42 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -115,6 +115,7 @@ local supported_flags = {
115 ["lr-bin"] = true, 115 ["lr-bin"] = true,
116 ["lr-cpath"] = true, 116 ["lr-cpath"] = true,
117 ["lr-path"] = true, 117 ["lr-path"] = true,
118 ["lua-dir"] = "<path>",
118 ["lua-version"] = "<vers>", 119 ["lua-version"] = "<vers>",
119 ["lua-ver"] = true, 120 ["lua-ver"] = true,
120 ["lua-incdir"] = true, 121 ["lua-incdir"] = true,