aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/cfg.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/cfg.lua')
-rw-r--r--src/luarocks/cfg.lua114
1 files changed, 80 insertions, 34 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 2b48d576..1147d725 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -1,7 +1,4 @@
1 1
2local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert =
3 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert
4
5--- Configuration for LuaRocks. 2--- Configuration for LuaRocks.
6-- Tries to load the user's configuration file and 3-- Tries to load the user's configuration file and
7-- defines defaults for unset values. See the 4-- defines defaults for unset values. See the
@@ -10,21 +7,26 @@ local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs,
10-- 7--
11-- End-users shouldn't edit this file. They can override any defaults 8-- End-users shouldn't edit this file. They can override any defaults
12-- set in this file using their system-wide $LUAROCKS_SYSCONFIG file 9-- set in this file using their system-wide $LUAROCKS_SYSCONFIG file
13-- (see luarocks.config) or their user-specific configuration file 10-- (see luarocks.site_config) or their user-specific configuration file
14-- (~/.luarocks/config.lua on Unix or %APPDATA%/luarocks/config.lua on 11-- (~/.luarocks/config.lua on Unix or %APPDATA%/luarocks/config.lua on
15-- Windows). 12-- Windows).
13
14local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert, _VERSION =
15 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert, _VERSION
16
16module("luarocks.cfg") 17module("luarocks.cfg")
17 18
18-- Load site-local global configurations 19-- Load site-local global configurations
19local ok, config = pcall(require, "luarocks.config") 20local ok, site_config = pcall(require, "luarocks.site_config")
20if not ok then 21if not ok then
21 io.stderr:write("Site-local luarocks/config.lua file not found. Incomplete installation?\n") 22 io.stderr:write("Site-local luarocks/site_config.lua file not found. Incomplete installation?\n")
22 config = {} 23 site_config = {}
23end 24end
24 25
25_M.config = config 26_M.site_config = site_config
26 27
27program_version = "2.0.5" 28lua_version = _VERSION:sub(5)
29program_version = "2.0.8"
28user_agent = "LuaRocks/"..program_version 30user_agent = "LuaRocks/"..program_version
29 31
30local persist = require("luarocks.persist") 32local persist = require("luarocks.persist")
@@ -46,12 +48,12 @@ local detected = {}
46local system,proc 48local system,proc
47 49
48-- A proper installation of LuaRocks will hardcode the system 50-- A proper installation of LuaRocks will hardcode the system
49-- and proc values with config.LUAROCKS_UNAME_S and config.LUAROCKS_UNAME_M, 51-- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M,
50-- so that this detection does not run every time. When it is 52-- so that this detection does not run every time. When it is
51-- performed, we use the Unix way to identify the system, 53-- performed, we use the Unix way to identify the system,
52-- even on Windows (assuming UnxUtils or Cygwin). 54-- even on Windows (assuming UnxUtils or Cygwin).
53system = config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") 55system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l")
54proc = config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") 56proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l")
55if proc:match("i[%d]86") then 57if proc:match("i[%d]86") then
56 proc = "x86" 58 proc = "x86"
57elseif proc:match("amd64") or proc:match("x86_64") then 59elseif proc:match("amd64") or proc:match("x86_64") then
@@ -75,6 +77,9 @@ elseif system == "Darwin" then
75elseif system == "Linux" then 77elseif system == "Linux" then
76 detected.unix = true 78 detected.unix = true
77 detected.linux = true 79 detected.linux = true
80elseif system == "SunOS" then
81 detected.unix = true
82 detected.solaris = true
78elseif system and system:match("^CYGWIN") then 83elseif system and system:match("^CYGWIN") then
79 detected.unix = true 84 detected.unix = true
80 detected.cygwin = true 85 detected.cygwin = true
@@ -90,6 +95,7 @@ end
90-- Path configuration: 95-- Path configuration:
91 96
92local sys_config_file, home_config_file 97local sys_config_file, home_config_file
98local sys_config_ok, home_config_ok = false, false
93if detected.windows or detected.mingw32 then 99if detected.windows or detected.mingw32 then
94 home = os.getenv("APPDATA") or "c:" 100 home = os.getenv("APPDATA") or "c:"
95 sys_config_file = "c:/luarocks/config.lua" 101 sys_config_file = "c:/luarocks/config.lua"
@@ -105,14 +111,34 @@ end
105variables = {} 111variables = {}
106rocks_trees = {} 112rocks_trees = {}
107 113
108persist.load_into_table(config.LUAROCKS_SYSCONFIG or sys_config_file, _M) 114local ok, err = persist.load_into_table(site_config.LUAROCKS_SYSCONFIG or sys_config_file, _M)
115if ok then
116 sys_config_ok = true
117else -- nil or false
118 sys_config_ok = ok
119 if err and ok == nil then
120 io.stderr:write(err.."\n")
121 end
122end
109 123
110if not config.LUAROCKS_FORCE_CONFIG then 124if not site_config.LUAROCKS_FORCE_CONFIG then
111 home_config_file = os.getenv("LUAROCKS_CONFIG") or home_config_file 125 home_config_file = os.getenv("LUAROCKS_CONFIG") or home_config_file
112 local home_overrides = persist.load_into_table(home_config_file, { home = home }) 126 local home_overrides, err = persist.load_into_table(home_config_file, { home = home })
113 if home_overrides then 127 if home_overrides then
128 home_config_ok = true
114 local util = require("luarocks.util") 129 local util = require("luarocks.util")
130 if home_overrides.rocks_trees then
131 _M.rocks_trees = nil
132 end
133 if home_overrides.rocks_servers then
134 _M.rocks_servers = nil
135 end
115 util.deep_merge(_M, home_overrides) 136 util.deep_merge(_M, home_overrides)
137 else -- nil or false
138 home_config_ok = home_overrides
139 if err and home_config_ok == nil then
140 io.stderr:write(err.."\n")
141 end
116 end 142 end
117end 143end
118 144
@@ -120,8 +146,8 @@ if not next(rocks_trees) then
120 if home_tree then 146 if home_tree then
121 table.insert(rocks_trees, home_tree) 147 table.insert(rocks_trees, home_tree)
122 end 148 end
123 if config.LUAROCKS_ROCKS_TREE then 149 if site_config.LUAROCKS_ROCKS_TREE then
124 table.insert(rocks_trees, config.LUAROCKS_ROCKS_TREE) 150 table.insert(rocks_trees, site_config.LUAROCKS_ROCKS_TREE)
125 end 151 end
126end 152end
127 153
@@ -129,8 +155,13 @@ end
129 155
130local root = rocks_trees[#rocks_trees] 156local root = rocks_trees[#rocks_trees]
131local defaults = { 157local defaults = {
132 lua_modules_path = "/share/lua/5.1/", 158
133 lib_modules_path = "/lib/lua/5.1/", 159 local_by_default = false,
160 use_extensions = false,
161 accept_unknown_fields = false,
162
163 lua_modules_path = "/share/lua/"..lua_version,
164 lib_modules_path = "/lib/lua/"..lua_version,
134 165
135 arch = "unknown", 166 arch = "unknown",
136 lib_extension = "unknown", 167 lib_extension = "unknown",
@@ -141,9 +172,9 @@ local defaults = {
141 }, 172 },
142 173
143 lua_extension = "lua", 174 lua_extension = "lua",
144 lua_interpreter = config.LUA_INTERPRETER or "lua", 175 lua_interpreter = site_config.LUA_INTERPRETER or "lua",
145 downloader = config.LUAROCKS_DOWNLOADER or "wget", 176 downloader = site_config.LUAROCKS_DOWNLOADER or "wget",
146 md5checker = config.LUAROCKS_MD5CHECKER or "md5sum", 177 md5checker = site_config.LUAROCKS_MD5CHECKER or "md5sum",
147 178
148 variables = { 179 variables = {
149 MAKE = "make", 180 MAKE = "make",
@@ -183,6 +214,7 @@ local defaults = {
183 MD5 = "md5", 214 MD5 = "md5",
184 STAT = "stat", 215 STAT = "stat",
185 216
217 CMAKE = "cmake",
186 SEVENZ = "7z", 218 SEVENZ = "7z",
187 219
188 STATFLAG = "-c '%a'", 220 STATFLAG = "-c '%a'",
@@ -208,19 +240,21 @@ if detected.windows then
208 defaults.external_lib_extension = "dll" 240 defaults.external_lib_extension = "dll"
209 defaults.obj_extension = "obj" 241 defaults.obj_extension = "obj"
210 defaults.external_deps_dirs = { "c:/external/" } 242 defaults.external_deps_dirs = { "c:/external/" }
211 defaults.variables.LUA_BINDIR = config.LUA_BINDIR and config.LUA_BINDIR:gsub("\\", "/") or "c:/lua5.1/bin" 243 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/bin"
212 defaults.variables.LUA_INCDIR = config.LUA_INCDIR and config.LUA_INCDIR:gsub("\\", "/") or "c:/lua5.1/include" 244 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/include"
213 defaults.variables.LUA_LIBDIR = config.LUA_LIBDIR and config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua5.1/lib" 245 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/lib"
214 defaults.cmake_generator = "MinGW Makefiles" 246 defaults.cmake_generator = "MinGW Makefiles"
215 defaults.makefile = "Makefile.win" 247 defaults.makefile = "Makefile.win"
216 defaults.variables.MAKE = "nmake" -- TODO: Split Windows flavors between mingw and msvc 248 defaults.variables.MAKE = "nmake" -- TODO: Split Windows flavors between mingw and msvc
217 defaults.variables.CC = "cl" 249 defaults.variables.CC = "cl"
218 defaults.variables.RC = "rc" 250 defaults.variables.RC = "rc"
219 defaults.variables.WRAPPER = config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.obj" 251 defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.obj"
220 defaults.variables.LD = "link" 252 defaults.variables.LD = "link"
221 defaults.variables.MT = "mt" 253 defaults.variables.MT = "mt"
254 defaults.variables.LUALIB = "lua"..lua_version..".lib"
222 defaults.variables.CFLAGS = "/MD /O2" 255 defaults.variables.CFLAGS = "/MD /O2"
223 defaults.variables.LIBFLAG = "/dll" 256 defaults.variables.LIBFLAG = "/dll"
257 defaults.variables.LUALIB = "lua"..lua_version..".lib"
224 defaults.external_deps_patterns = { 258 defaults.external_deps_patterns = {
225 bin = { "?.exe", "?.bat" }, 259 bin = { "?.exe", "?.bat" },
226 lib = { "?.lib", "?.dll", "lib?.dll" }, 260 lib = { "?.lib", "?.dll", "lib?.dll" },
@@ -244,15 +278,15 @@ if detected.mingw32 then
244 defaults.external_lib_extension = "dll" 278 defaults.external_lib_extension = "dll"
245 defaults.obj_extension = "o" 279 defaults.obj_extension = "o"
246 defaults.external_deps_dirs = { "c:/external/" } 280 defaults.external_deps_dirs = { "c:/external/" }
247 defaults.variables.LUA_BINDIR = config.LUA_BINDIR and config.LUA_BINDIR:gsub("\\", "/") or "c:/lua5.1/bin" 281 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/bin"
248 defaults.variables.LUA_INCDIR = config.LUA_INCDIR and config.LUA_INCDIR:gsub("\\", "/") or "c:/lua5.1/include" 282 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/include"
249 defaults.variables.LUA_LIBDIR = config.LUA_LIBDIR and config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua5.1/lib" 283 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/lib"
250 defaults.cmake_generator = "MinGW Makefiles" 284 defaults.cmake_generator = "MinGW Makefiles"
251 defaults.make = "mingw32-make" -- TODO: Split Windows flavors between mingw and msvc 285 defaults.make = "mingw32-make" -- TODO: Split Windows flavors between mingw and msvc
252 defaults.makefile = "Makefile.win" 286 defaults.makefile = "Makefile.win"
253 defaults.variables.CC = "mingw32-gcc" 287 defaults.variables.CC = "mingw32-gcc"
254 defaults.variables.RC = "windres" 288 defaults.variables.RC = "windres"
255 defaults.variables.WRAPPER = config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.o" 289 defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.o"
256 defaults.variables.LD = "mingw32-gcc" 290 defaults.variables.LD = "mingw32-gcc"
257 defaults.variables.CFLAGS = "-O2" 291 defaults.variables.CFLAGS = "-O2"
258 defaults.variables.LIBFLAG = "-shared" 292 defaults.variables.LIBFLAG = "-shared"
@@ -276,9 +310,9 @@ if detected.unix then
276 defaults.external_lib_extension = "so" 310 defaults.external_lib_extension = "so"
277 defaults.obj_extension = "o" 311 defaults.obj_extension = "o"
278 defaults.external_deps_dirs = { "/usr/local", "/usr" } 312 defaults.external_deps_dirs = { "/usr/local", "/usr" }
279 defaults.variables.LUA_BINDIR = config.LUA_BINDIR or "/usr/local/bin" 313 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR or "/usr/local/bin"
280 defaults.variables.LUA_INCDIR = config.LUA_INCDIR or "/usr/local/include" 314 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR or "/usr/local/include"
281 defaults.variables.LUA_LIBDIR = config.LUA_LIBDIR or "/usr/local/lib" 315 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR or "/usr/local/lib"
282 defaults.variables.CFLAGS = "-O2" 316 defaults.variables.CFLAGS = "-O2"
283 defaults.cmake_generator = "Unix Makefiles" 317 defaults.cmake_generator = "Unix Makefiles"
284 defaults.platforms = { "unix" } 318 defaults.platforms = { "unix" }
@@ -347,11 +381,19 @@ if detected.openbsd then
347 defaults.variables.STATFLAG = "-f '%Op'" 381 defaults.variables.STATFLAG = "-f '%Op'"
348end 382end
349 383
384if detected.solaris then
385 defaults.arch = "solaris-"..proc
386 defaults.platforms = {"unix", "solaris"}
387 defaults.variables.MAKE = "gmake"
388 defaults.variables.CC = "gcc"
389 defaults.variables.LD = "gcc"
390end
391
350-- Expose some more values detected by LuaRocks for use by rockspec authors. 392-- Expose some more values detected by LuaRocks for use by rockspec authors.
351defaults.variables.LUA = defaults.lua_interpreter 393defaults.variables.LUA = defaults.lua_interpreter
352defaults.variables.LIB_EXTENSION = defaults.lib_extension 394defaults.variables.LIB_EXTENSION = defaults.lib_extension
353defaults.variables.OBJ_EXTENSION = defaults.obj_extension 395defaults.variables.OBJ_EXTENSION = defaults.obj_extension
354defaults.variables.LUAROCKS_PREFIX = config.LUAROCKS_PREFIX 396defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX
355 397
356-- Use defaults: 398-- Use defaults:
357 399
@@ -389,6 +431,10 @@ for _,tree in ipairs(rocks_trees) do
389 end 431 end
390end 432end
391 433
434function which_config()
435 return sys_config_file, sys_config_ok, home_config_file, home_config_ok
436end
437
392--- Check if platform was detected 438--- Check if platform was detected
393-- @param query string: The platform name to check. 439-- @param query string: The platform name to check.
394-- @return boolean: true if LuaRocks is currently running on queried platform. 440-- @return boolean: true if LuaRocks is currently running on queried platform.