diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-06-09 22:39:28 +0200 |
|---|---|---|
| committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:49:17 +0300 |
| commit | b7defd249f11528024d73c3ed02474787ec4bb35 (patch) | |
| tree | 084fe70395f35f303652298c1421ecf6b8ad8e13 /src | |
| parent | 932fbc517f4cf8aaca54de8737d7b8220af1de4e (diff) | |
| download | luarocks-b7defd249f11528024d73c3ed02474787ec4bb35.tar.gz luarocks-b7defd249f11528024d73c3ed02474787ec4bb35.tar.bz2 luarocks-b7defd249f11528024d73c3ed02474787ec4bb35.zip | |
remove conflict
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/core/cfg.lua (renamed from src/luarocks/core/cfg (conflicted).tl) | 416 | ||||
| -rw-r--r-- | src/luarocks/core/cfg.tl | 53 |
2 files changed, 233 insertions, 236 deletions
diff --git a/src/luarocks/core/cfg (conflicted).tl b/src/luarocks/core/cfg.lua index f4c78ebf..4ae9bd6e 100644 --- a/src/luarocks/core/cfg (conflicted).tl +++ b/src/luarocks/core/cfg.lua | |||
| @@ -1,39 +1,39 @@ | |||
| 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local debug = _tl_compat and _tl_compat.debug or debug; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local os = _tl_compat and _tl_compat.os or os; local package = _tl_compat and _tl_compat.package or package; local pairs = _tl_compat and _tl_compat.pairs or pairs; local pcall = _tl_compat and _tl_compat.pcall or pcall; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table | ||
| 1 | 2 | ||
| 2 | --- Configuration for LuaRocks. | 3 | |
| 3 | -- Tries to load the user's configuration file and | 4 | |
| 4 | -- defines defaults for unset values. See the | 5 | |
| 5 | -- <a href="http://luarocks.org/en/Config_file_format">config | 6 | |
| 6 | -- file format documentation</a> for details. | 7 | |
| 7 | -- | 8 | |
| 8 | -- End-users shouldn't edit this file. They can override any defaults | 9 | |
| 9 | -- set in this file using their system-wide or user-specific configuration | 10 | |
| 10 | -- files. Run `luarocks` with no arguments to see the locations of | 11 | |
| 11 | -- these files in your platform. | 12 | |
| 12 | 13 | local table, pairs, require, os, pcall, ipairs, package, type, assert = | |
| 13 | local table, pairs, require, os, pcall, ipairs, package, type, assert = --! | 14 | table, pairs, require, os, pcall, ipairs, package, type, assert |
| 14 | table, pairs, require, os, pcall, ipairs, package, type, assert | 15 | |
| 15 | 16 | local dir = require("luarocks.core.dir") | |
| 16 | local dir = require("luarocks.core.dir") --! | ||
| 17 | local util = require("luarocks.core.util") | 17 | local util = require("luarocks.core.util") |
| 18 | local persist = require("luarocks.core.persist") | 18 | local persist = require("luarocks.core.persist") |
| 19 | local sysdetect = require("luarocks.core.sysdetect") | 19 | local sysdetect = require("luarocks.core.sysdetect") |
| 20 | local vers = require("luarocks.core.vers") | 20 | local vers = require("luarocks.core.vers") |
| 21 | 21 | ||
| 22 | local record cfg | 22 | local cfg = {} |
| 23 | |||
| 24 | |||
| 25 | |||
| 23 | 26 | ||
| 24 | end | ||
| 25 | 27 | ||
| 26 | -------------------------------------------------------------------------------- | 28 | local program_version = "dev" |
| 29 | |||
| 30 | local is_windows = package.config:sub(1, 1) == "\\" | ||
| 31 | |||
| 27 | 32 | ||
| 28 | local program_version = "dev" --! | ||
| 29 | 33 | ||
| 30 | local is_windows = package.config:sub(1,1) == "\\" --! | ||
| 31 | 34 | ||
| 32 | -- Set order for platform overrides. | ||
| 33 | -- More general platform identifiers should be listed first, | ||
| 34 | -- more specific ones later. | ||
| 35 | local platform_order = { | 35 | local platform_order = { |
| 36 | -- Unixes | 36 | |
| 37 | "unix", | 37 | "unix", |
| 38 | "bsd", | 38 | "bsd", |
| 39 | "solaris", | 39 | "solaris", |
| @@ -46,7 +46,7 @@ local platform_order = { | |||
| 46 | "cygwin", | 46 | "cygwin", |
| 47 | "msys", | 47 | "msys", |
| 48 | "haiku", | 48 | "haiku", |
| 49 | -- Windows | 49 | |
| 50 | "windows", | 50 | "windows", |
| 51 | "win32", | 51 | "win32", |
| 52 | "mingw", | 52 | "mingw", |
| @@ -54,16 +54,16 @@ local platform_order = { | |||
| 54 | "msys2_mingw_w64", | 54 | "msys2_mingw_w64", |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | local type Config = record --! | 57 | |
| 58 | home: any | 58 | |
| 59 | lua_version: any | 59 | |
| 60 | target_cpu: any | 60 | |
| 61 | variables: {any: any} | 61 | |
| 62 | os_getenv: any | 62 | |
| 63 | rocks_trees: any | 63 | |
| 64 | rocks_servers: any | 64 | |
| 65 | dump_env: function() | 65 | |
| 66 | end | 66 | |
| 67 | 67 | ||
| 68 | local function detect_sysconfdir() | 68 | local function detect_sysconfdir() |
| 69 | if not debug then | 69 | if not debug then |
| @@ -81,58 +81,58 @@ local function detect_sysconfdir() | |||
| 81 | if not basedir then | 81 | if not basedir then |
| 82 | return | 82 | return |
| 83 | end | 83 | end |
| 84 | -- If installed in a Unix-like tree, use a Unix-like sysconfdir | 84 | |
| 85 | local installdir = basedir:match("^(.*)[\\/]share[\\/]lua[\\/][^/]*$") | 85 | local installdir = basedir:match("^(.*)[\\/]share[\\/]lua[\\/][^/]*$") |
| 86 | if installdir then | 86 | if installdir then |
| 87 | if installdir == "/usr" then | 87 | if installdir == "/usr" then |
| 88 | return "/etc/luarocks" --! | 88 | return "/etc/luarocks" |
| 89 | end | 89 | end |
| 90 | return dir.path(installdir, "etc", "luarocks") | 90 | return dir.path(installdir, "etc", "luarocks") |
| 91 | end | 91 | end |
| 92 | -- Otherwise, use base directory of sources | 92 | |
| 93 | return basedir | 93 | return basedir |
| 94 | end | 94 | end |
| 95 | 95 | ||
| 96 | -- local load_config_file --! | 96 | |
| 97 | do | 97 | do |
| 98 | -- Create global environment for the config files; | 98 | |
| 99 | local function env_for_config_file(cfg: Config, platforms: {any: any}): {any: any} --! | 99 | local function env_for_config_file(cfg, platforms) |
| 100 | local platforms_copy = {} | 100 | local platforms_copy = {} |
| 101 | for k,v in pairs(platforms) do | 101 | for k, v in pairs(platforms) do |
| 102 | platforms_copy[k] = v | 102 | platforms_copy[k] = v |
| 103 | end | 103 | end |
| 104 | 104 | ||
| 105 | local e: {any: any} --! | 105 | local e |
| 106 | e = { | 106 | e = { |
| 107 | home = cfg.home, | 107 | home = cfg.home, |
| 108 | lua_version = cfg.lua_version, | 108 | lua_version = cfg.lua_version, |
| 109 | platforms = platforms_copy, | 109 | platforms = platforms_copy, |
| 110 | processor = cfg.target_cpu, -- remains for compat reasons | 110 | processor = cfg.target_cpu, |
| 111 | target_cpu = cfg.target_cpu, -- replaces `processor` | 111 | target_cpu = cfg.target_cpu, |
| 112 | os_getenv = os.getenv, | 112 | os_getenv = os.getenv, |
| 113 | variables = cfg.variables or {}, | 113 | variables = cfg.variables or {}, |
| 114 | dump_env = function() | 114 | dump_env = function() |
| 115 | -- debug function, calling it from a config file will show all | 115 | |
| 116 | -- available globals to that config file | 116 | |
| 117 | print(util.show_table(e, "global environment")) | 117 | print(util.show_table(e, "global environment")) |
| 118 | end, | 118 | end, |
| 119 | } | 119 | } |
| 120 | return e | 120 | return e |
| 121 | end | 121 | end |
| 122 | 122 | ||
| 123 | -- Merge values from config files read into the `cfg` table | 123 | |
| 124 | local function merge_overrides(cfg: Config, overrides: Config) | 124 | local function merge_overrides(cfg, overrides) |
| 125 | -- remove some stuff we do not want to integrate | 125 | |
| 126 | overrides.os_getenv = nil | 126 | overrides.os_getenv = nil |
| 127 | overrides.dump_env = nil | 127 | overrides.dump_env = nil |
| 128 | -- remove tables to be copied verbatim instead of deeply merged | 128 | |
| 129 | if overrides.rocks_trees then cfg.rocks_trees = nil end | 129 | if overrides.rocks_trees then cfg.rocks_trees = nil end |
| 130 | if overrides.rocks_servers then cfg.rocks_servers = nil end | 130 | if overrides.rocks_servers then cfg.rocks_servers = nil end |
| 131 | -- perform actual merge | 131 | |
| 132 | util.deep_merge(cfg, overrides) | 132 | util.deep_merge(cfg, overrides) |
| 133 | end | 133 | end |
| 134 | 134 | ||
| 135 | local function update_platforms(platforms: {any: any}, overrides: {any: any}) | 135 | local function update_platforms(platforms, overrides) |
| 136 | if overrides[1] then | 136 | if overrides[1] then |
| 137 | for k, _ in pairs(platforms) do | 137 | for k, _ in pairs(platforms) do |
| 138 | platforms[k] = nil | 138 | platforms[k] = nil |
| @@ -140,30 +140,30 @@ do | |||
| 140 | for _, v in ipairs(overrides) do | 140 | for _, v in ipairs(overrides) do |
| 141 | platforms[v] = true | 141 | platforms[v] = true |
| 142 | end | 142 | end |
| 143 | -- set some fallback default in case the user provides an incomplete configuration. | 143 | |
| 144 | -- LuaRocks expects a set of defaults to be available. | 144 | |
| 145 | if not (platforms.unix or platforms.windows) then | 145 | if not (platforms.unix or platforms.windows) then |
| 146 | platforms[is_windows and "windows" or "unix"] = true | 146 | platforms[is_windows and "windows" or "unix"] = true |
| 147 | end | 147 | end |
| 148 | end | 148 | end |
| 149 | end | 149 | end |
| 150 | 150 | ||
| 151 | -- Load config file and merge its contents into the `cfg` module table. | 151 | |
| 152 | -- @return filepath of successfully loaded file or nil if it failed | 152 | |
| 153 | local load_config_file = function(cfg: Config, platforms: {any: any}, filepath: string): string --! | 153 | local load_config_file = function(cfg, platforms, filepath) |
| 154 | local result, err, errcode = persist.load_into_table(filepath, env_for_config_file(cfg, platforms)) | 154 | local result, err, errcode = persist.load_into_table(filepath, env_for_config_file(cfg, platforms)) |
| 155 | if (not result) and errcode ~= "open" then | 155 | if (not result) and errcode ~= "open" then |
| 156 | -- errcode is either "load" or "run"; bad config file, so error out | 156 | |
| 157 | return nil, err, "config" | 157 | return nil, err, "config" |
| 158 | end | 158 | end |
| 159 | if result then | 159 | if result then |
| 160 | -- success in loading and running, merge contents and exit | 160 | |
| 161 | update_platforms(platforms, result.platforms) | 161 | update_platforms(platforms, result.platforms) |
| 162 | result.platforms = nil | 162 | result.platforms = nil |
| 163 | merge_overrides(cfg, result) | 163 | merge_overrides(cfg, result) |
| 164 | return filepath | 164 | return filepath |
| 165 | end | 165 | end |
| 166 | return nil -- nothing was loaded | 166 | return nil |
| 167 | end | 167 | end |
| 168 | end | 168 | end |
| 169 | 169 | ||
| @@ -183,16 +183,16 @@ local platform_sets = { | |||
| 183 | msys2_mingw_w64 = { windows = true, win32 = true, mingw32 = true, mingw = true, msys = true, msys2_mingw_w64 = true }, | 183 | msys2_mingw_w64 = { windows = true, win32 = true, mingw32 = true, mingw = true, msys = true, msys2_mingw_w64 = true }, |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | local function make_platforms(system: string): {any: boolean} --! :System | 186 | local function make_platforms(system) |
| 187 | -- fallback to Unix in unknown systems | 187 | |
| 188 | return platform_sets[system] or { unix = true } | 188 | return platform_sets[system] or { unix = true } |
| 189 | end | 189 | end |
| 190 | 190 | ||
| 191 | -------------------------------------------------------------------------------- | ||
| 192 | 191 | ||
| 193 | local function make_defaults(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any} --! | ||
| 194 | 192 | ||
| 195 | -- Configure defaults: | 193 | local function make_defaults(lua_version, target_cpu, platforms, home) |
| 194 | |||
| 195 | |||
| 196 | local defaults = { | 196 | local defaults = { |
| 197 | 197 | ||
| 198 | local_by_default = false, | 198 | local_by_default = false, |
| @@ -208,29 +208,29 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 208 | 208 | ||
| 209 | lua_modules_path = dir.path("share", "lua", lua_version), | 209 | lua_modules_path = dir.path("share", "lua", lua_version), |
| 210 | lib_modules_path = dir.path("lib", "lua", lua_version), | 210 | lib_modules_path = dir.path("lib", "lua", lua_version), |
| 211 | rocks_subdir = dir.path("lib", "luarocks", "rocks-"..lua_version), | 211 | rocks_subdir = dir.path("lib", "luarocks", "rocks-" .. lua_version), |
| 212 | 212 | ||
| 213 | arch = "unknown", | 213 | arch = "unknown", |
| 214 | lib_extension = "unknown", | 214 | lib_extension = "unknown", |
| 215 | external_lib_extension = "unknown", --? | 215 | external_lib_extension = "unknown", |
| 216 | static_lib_extension = "unknown", --? | 216 | static_lib_extension = "unknown", |
| 217 | obj_extension = "unknown", | 217 | obj_extension = "unknown", |
| 218 | link_lua_explicitly = false, | 218 | link_lua_explicitly = false, |
| 219 | 219 | ||
| 220 | external_deps_dirs = {}, --? | 220 | external_deps_dirs = {}, |
| 221 | external_deps_patterns = {}, --? | 221 | external_deps_patterns = {}, |
| 222 | runtime_external_deps_patterns = {}, --? | 222 | runtime_external_deps_patterns = {}, |
| 223 | 223 | ||
| 224 | export_path_separator = "", --? | 224 | export_path_separator = "", |
| 225 | wrapper_suffix = "", --? | 225 | wrapper_suffix = "", |
| 226 | 226 | ||
| 227 | 227 | ||
| 228 | rocks_servers = { | 228 | rocks_servers = { |
| 229 | { | 229 | { |
| 230 | "https://luarocks.org", | 230 | "https://luarocks.org", |
| 231 | "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/", | 231 | "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/", |
| 232 | "https://loadk.com/luarocks/", | 232 | "https://loadk.com/luarocks/", |
| 233 | } | 233 | }, |
| 234 | }, | 234 | }, |
| 235 | disabled_servers = {}, | 235 | disabled_servers = {}, |
| 236 | 236 | ||
| @@ -241,13 +241,13 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 241 | }, | 241 | }, |
| 242 | 242 | ||
| 243 | lua_extension = "lua", | 243 | lua_extension = "lua", |
| 244 | connection_timeout = 30, -- 0 = no timeout | 244 | connection_timeout = 30, |
| 245 | 245 | ||
| 246 | makefile = "", --? | 246 | makefile = "", |
| 247 | local_cache = "" , --? | 247 | local_cache = "", |
| 248 | web_browser = "", --? | 248 | web_browser = "", |
| 249 | cmake_generator = "", --? | 249 | cmake_generator = "", |
| 250 | gcc_rpath = false, --? | 250 | gcc_rpath = false, |
| 251 | 251 | ||
| 252 | variables = { | 252 | variables = { |
| 253 | MAKE = os.getenv("MAKE") or "make", | 253 | MAKE = os.getenv("MAKE") or "make", |
| @@ -299,29 +299,29 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 299 | CURLNOCERTFLAG = "", | 299 | CURLNOCERTFLAG = "", |
| 300 | WGETNOCERTFLAG = "", | 300 | WGETNOCERTFLAG = "", |
| 301 | 301 | ||
| 302 | RC = "", --? | 302 | RC = "", |
| 303 | MT = "", --? | 303 | MT = "", |
| 304 | CFLAGS = "", --? | 304 | CFLAGS = "", |
| 305 | LDFLAGS = "", --? | 305 | LDFLAGS = "", |
| 306 | LIBFLAG = "", --? | 306 | LIBFLAG = "", |
| 307 | TEST = "", --? | 307 | TEST = "", |
| 308 | }, | 308 | }, |
| 309 | 309 | ||
| 310 | external_deps_subdirs = { | 310 | external_deps_subdirs = { |
| 311 | bin = "bin", | 311 | bin = "bin", |
| 312 | lib = "lib", | 312 | lib = "lib", |
| 313 | include = "include" | 313 | include = "include", |
| 314 | }, | 314 | }, |
| 315 | runtime_external_deps_subdirs = { | 315 | runtime_external_deps_subdirs = { |
| 316 | bin = "bin", | 316 | bin = "bin", |
| 317 | lib = "lib", | 317 | lib = "lib", |
| 318 | include = "include" | 318 | include = "include", |
| 319 | }, | 319 | }, |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | if platforms.windows then | 322 | if platforms.windows then |
| 323 | 323 | ||
| 324 | defaults.arch = "win32-"..target_cpu | 324 | defaults.arch = "win32-" .. target_cpu |
| 325 | defaults.lib_extension = "dll" | 325 | defaults.lib_extension = "dll" |
| 326 | defaults.external_lib_extension = "dll" | 326 | defaults.external_lib_extension = "dll" |
| 327 | defaults.static_lib_extension = "lib" | 327 | defaults.static_lib_extension = "lib" |
| @@ -347,19 +347,19 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 347 | defaults.external_deps_patterns = { | 347 | defaults.external_deps_patterns = { |
| 348 | bin = { "?.exe", "?.bat" }, | 348 | bin = { "?.exe", "?.bat" }, |
| 349 | lib = { "?.lib", "lib?.lib", "?.dll", "lib?.dll" }, | 349 | lib = { "?.lib", "lib?.lib", "?.dll", "lib?.dll" }, |
| 350 | include = { "?.h" } | 350 | include = { "?.h" }, |
| 351 | } | 351 | } |
| 352 | defaults.runtime_external_deps_patterns = { | 352 | defaults.runtime_external_deps_patterns = { |
| 353 | bin = { "?.exe", "?.bat" }, | 353 | bin = { "?.exe", "?.bat" }, |
| 354 | lib = { "?.dll", "lib?.dll" }, | 354 | lib = { "?.dll", "lib?.dll" }, |
| 355 | include = { "?.h" } | 355 | include = { "?.h" }, |
| 356 | } | 356 | } |
| 357 | defaults.export_path_separator = ";" | 357 | defaults.export_path_separator = ";" |
| 358 | defaults.wrapper_suffix = ".bat" | 358 | defaults.wrapper_suffix = ".bat" |
| 359 | 359 | ||
| 360 | local localappdata = os.getenv("LOCALAPPDATA") | 360 | local localappdata = os.getenv("LOCALAPPDATA") |
| 361 | if not localappdata then | 361 | if not localappdata then |
| 362 | -- for Windows versions below Vista | 362 | |
| 363 | localappdata = dir.path((os.getenv("USERPROFILE") or dir.path("c:", "Users", "All Users")), "Local Settings", "Application Data") | 363 | localappdata = dir.path((os.getenv("USERPROFILE") or dir.path("c:", "Users", "All Users")), "Local Settings", "Application Data") |
| 364 | end | 364 | end |
| 365 | defaults.local_cache = dir.path(localappdata, "LuaRocks", "Cache") | 365 | defaults.local_cache = dir.path(localappdata, "LuaRocks", "Cache") |
| @@ -397,15 +397,15 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 397 | defaults.makefile = "Makefile" | 397 | defaults.makefile = "Makefile" |
| 398 | defaults.external_deps_patterns = { | 398 | defaults.external_deps_patterns = { |
| 399 | bin = { "?.exe", "?.bat" }, | 399 | bin = { "?.exe", "?.bat" }, |
| 400 | -- mingw lookup list from http://stackoverflow.com/a/15853231/1793220 | 400 | |
| 401 | -- ...should we keep ?.lib at the end? It's not in the above list. | 401 | |
| 402 | lib = { "lib?.dll.a", "?.dll.a", "lib?.a", "cyg?.dll", "lib?.dll", "?.dll", "?.lib" }, | 402 | lib = { "lib?.dll.a", "?.dll.a", "lib?.a", "cyg?.dll", "lib?.dll", "?.dll", "?.lib" }, |
| 403 | include = { "?.h" } | 403 | include = { "?.h" }, |
| 404 | } | 404 | } |
| 405 | defaults.runtime_external_deps_patterns = { | 405 | defaults.runtime_external_deps_patterns = { |
| 406 | bin = { "?.exe", "?.bat" }, | 406 | bin = { "?.exe", "?.bat" }, |
| 407 | lib = { "cyg?.dll", "?.dll", "lib?.dll" }, | 407 | lib = { "cyg?.dll", "?.dll", "lib?.dll" }, |
| 408 | include = { "?.h" } | 408 | include = { "?.h" }, |
| 409 | } | 409 | } |
| 410 | defaults.link_lua_explicitly = true | 410 | defaults.link_lua_explicitly = true |
| 411 | end | 411 | end |
| @@ -418,10 +418,10 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 418 | defaults.external_deps_dirs = { "/usr/local", "/usr", "/" } | 418 | defaults.external_deps_dirs = { "/usr/local", "/usr", "/" } |
| 419 | 419 | ||
| 420 | defaults.variables.CFLAGS = os.getenv("CFLAGS") or "-O2" | 420 | defaults.variables.CFLAGS = os.getenv("CFLAGS") or "-O2" |
| 421 | -- we pass -fPIC via CFLAGS because of old Makefile-based Lua projects | 421 | |
| 422 | -- which didn't have -fPIC in their Makefiles but which honor CFLAGS | 422 | |
| 423 | if not defaults.variables.CFLAGS:match("-fPIC") then | 423 | if not defaults.variables.CFLAGS:match("-fPIC") then |
| 424 | defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" | 424 | defaults.variables.CFLAGS = defaults.variables.CFLAGS .. " -fPIC" |
| 425 | end | 425 | end |
| 426 | 426 | ||
| 427 | defaults.variables.LDFLAGS = os.getenv("LDFLAGS") | 427 | defaults.variables.LDFLAGS = os.getenv("LDFLAGS") |
| @@ -436,23 +436,23 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 436 | defaults.external_deps_patterns = { | 436 | defaults.external_deps_patterns = { |
| 437 | bin = { "?" }, | 437 | bin = { "?" }, |
| 438 | lib = { "lib?.a", "lib?.so", "lib?.so.*" }, | 438 | lib = { "lib?.a", "lib?.so", "lib?.so.*" }, |
| 439 | include = { "?.h" } | 439 | include = { "?.h" }, |
| 440 | } | 440 | } |
| 441 | defaults.runtime_external_deps_patterns = { | 441 | defaults.runtime_external_deps_patterns = { |
| 442 | bin = { "?" }, | 442 | bin = { "?" }, |
| 443 | lib = { "lib?.so", "lib?.so.*" }, | 443 | lib = { "lib?.so", "lib?.so.*" }, |
| 444 | include = { "?.h" } | 444 | include = { "?.h" }, |
| 445 | } | 445 | } |
| 446 | defaults.export_path_separator = ":" | 446 | defaults.export_path_separator = ":" |
| 447 | defaults.wrapper_suffix = "" | 447 | defaults.wrapper_suffix = "" |
| 448 | local xdg_cache_home = os.getenv("XDG_CACHE_HOME") or home.."/.cache" | 448 | local xdg_cache_home = os.getenv("XDG_CACHE_HOME") or home .. "/.cache" |
| 449 | defaults.local_cache = xdg_cache_home.."/luarocks" | 449 | defaults.local_cache = xdg_cache_home .. "/luarocks" |
| 450 | defaults.web_browser = "xdg-open" | 450 | defaults.web_browser = "xdg-open" |
| 451 | end | 451 | end |
| 452 | 452 | ||
| 453 | if platforms.cygwin then | 453 | if platforms.cygwin then |
| 454 | defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds | 454 | defaults.lib_extension = "so" |
| 455 | defaults.arch = "cygwin-"..target_cpu | 455 | defaults.arch = "cygwin-" .. target_cpu |
| 456 | defaults.cmake_generator = "Unix Makefiles" | 456 | defaults.cmake_generator = "Unix Makefiles" |
| 457 | defaults.variables.CC = "echo -llua | xargs " .. (os.getenv("CC") or "gcc") | 457 | defaults.variables.CC = "echo -llua | xargs " .. (os.getenv("CC") or "gcc") |
| 458 | defaults.variables.LD = "echo -llua | xargs " .. (os.getenv("CC") or "gcc") | 458 | defaults.variables.LD = "echo -llua | xargs " .. (os.getenv("CC") or "gcc") |
| @@ -461,24 +461,24 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 461 | end | 461 | end |
| 462 | 462 | ||
| 463 | if platforms.msys then | 463 | if platforms.msys then |
| 464 | -- msys is basically cygwin made out of mingw, meaning the subsytem is unixish | 464 | |
| 465 | -- enough, yet we can freely mix with native win32 | 465 | |
| 466 | defaults.external_deps_patterns = { | 466 | defaults.external_deps_patterns = { |
| 467 | bin = { "?.exe", "?.bat", "?" }, | 467 | bin = { "?.exe", "?.bat", "?" }, |
| 468 | lib = { "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a", | 468 | lib = { "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a", |
| 469 | "lib?.a", "lib?.dll", "?.dll", "?.lib" }, | 469 | "lib?.a", "lib?.dll", "?.dll", "?.lib", }, |
| 470 | include = { "?.h" } | 470 | include = { "?.h" }, |
| 471 | } | 471 | } |
| 472 | defaults.runtime_external_deps_patterns = { | 472 | defaults.runtime_external_deps_patterns = { |
| 473 | bin = { "?.exe", "?.bat" }, | 473 | bin = { "?.exe", "?.bat" }, |
| 474 | lib = { "lib?.so", "?.dll", "lib?.dll" }, | 474 | lib = { "lib?.so", "?.dll", "lib?.dll" }, |
| 475 | include = { "?.h" } | 475 | include = { "?.h" }, |
| 476 | } | 476 | } |
| 477 | if platforms.mingw then | 477 | if platforms.mingw then |
| 478 | -- MSYS2 can build Windows programs that depend on | 478 | |
| 479 | -- msys-2.0.dll (based on Cygwin) but MSYS2 is also designed | 479 | |
| 480 | -- for building native Windows programs by MinGW. These | 480 | |
| 481 | -- programs don't depend on msys-2.0.dll. | 481 | |
| 482 | local pipe = io.popen("cygpath --windows %MINGW_PREFIX%") | 482 | local pipe = io.popen("cygpath --windows %MINGW_PREFIX%") |
| 483 | local mingw_prefix = pipe:read("*l") | 483 | local mingw_prefix = pipe:read("*l") |
| 484 | pipe:close() | 484 | pipe:close() |
| @@ -499,7 +499,7 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 499 | 499 | ||
| 500 | defaults.variables.CFLAGS = os.getenv("CFLAGS") or "-O2 -fPIC" | 500 | defaults.variables.CFLAGS = os.getenv("CFLAGS") or "-O2 -fPIC" |
| 501 | if not defaults.variables.CFLAGS:match("-fPIC") then | 501 | if not defaults.variables.CFLAGS:match("-fPIC") then |
| 502 | defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" | 502 | defaults.variables.CFLAGS = defaults.variables.CFLAGS .. " -fPIC" |
| 503 | end | 503 | end |
| 504 | 504 | ||
| 505 | defaults.variables.LIBFLAG = "-shared" | 505 | defaults.variables.LIBFLAG = "-shared" |
| @@ -516,7 +516,7 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 516 | if platforms.macosx then | 516 | if platforms.macosx then |
| 517 | defaults.variables.MAKE = os.getenv("MAKE") or "make" | 517 | defaults.variables.MAKE = os.getenv("MAKE") or "make" |
| 518 | defaults.external_lib_extension = "dylib" | 518 | defaults.external_lib_extension = "dylib" |
| 519 | defaults.arch = "macosx-"..target_cpu | 519 | defaults.arch = "macosx-" .. target_cpu |
| 520 | defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" | 520 | defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" |
| 521 | local version = util.popen_read("sw_vers -productVersion") | 521 | local version = util.popen_read("sw_vers -productVersion") |
| 522 | if not (version:match("^%d+%.%d+%.%d+$") or version:match("^%d+%.%d+$")) then | 522 | if not (version:match("^%d+%.%d+%.%d+$") or version:match("^%d+%.%d+$")) then |
| @@ -532,11 +532,11 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 532 | else | 532 | else |
| 533 | defaults.gcc_rpath = false | 533 | defaults.gcc_rpath = false |
| 534 | end | 534 | end |
| 535 | defaults.variables.CC = "env MACOSX_DEPLOYMENT_TARGET="..tostring(version).." gcc" | 535 | defaults.variables.CC = "env MACOSX_DEPLOYMENT_TARGET=" .. tostring(version) .. " gcc" |
| 536 | defaults.variables.LD = "env MACOSX_DEPLOYMENT_TARGET="..tostring(version).." gcc" | 536 | defaults.variables.LD = "env MACOSX_DEPLOYMENT_TARGET=" .. tostring(version) .. " gcc" |
| 537 | defaults.web_browser = "open" | 537 | defaults.web_browser = "open" |
| 538 | 538 | ||
| 539 | -- XCode SDK | 539 | |
| 540 | local sdk_path = util.popen_read("xcrun --show-sdk-path 2>/dev/null") | 540 | local sdk_path = util.popen_read("xcrun --show-sdk-path 2>/dev/null") |
| 541 | if sdk_path then | 541 | if sdk_path then |
| 542 | table.insert(defaults.external_deps_dirs, sdk_path .. "/usr") | 542 | table.insert(defaults.external_deps_dirs, sdk_path .. "/usr") |
| @@ -544,7 +544,7 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 544 | table.insert(defaults.runtime_external_deps_patterns.lib, 1, "lib?.tbd") | 544 | table.insert(defaults.runtime_external_deps_patterns.lib, 1, "lib?.tbd") |
| 545 | end | 545 | end |
| 546 | 546 | ||
| 547 | -- Homebrew | 547 | |
| 548 | table.insert(defaults.external_deps_dirs, "/usr/local/opt") | 548 | table.insert(defaults.external_deps_dirs, "/usr/local/opt") |
| 549 | defaults.external_deps_subdirs.lib = { "lib", "" } | 549 | defaults.external_deps_subdirs.lib = { "lib", "" } |
| 550 | defaults.runtime_external_deps_subdirs.lib = { "lib", "" } | 550 | defaults.runtime_external_deps_subdirs.lib = { "lib", "" } |
| @@ -553,7 +553,7 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 553 | end | 553 | end |
| 554 | 554 | ||
| 555 | if platforms.linux then | 555 | if platforms.linux then |
| 556 | defaults.arch = "linux-"..target_cpu | 556 | defaults.arch = "linux-" .. target_cpu |
| 557 | 557 | ||
| 558 | local gcc_arch = util.popen_read("gcc -print-multiarch 2>/dev/null") | 558 | local gcc_arch = util.popen_read("gcc -print-multiarch 2>/dev/null") |
| 559 | if gcc_arch and gcc_arch ~= "" then | 559 | if gcc_arch and gcc_arch ~= "" then |
| @@ -566,19 +566,19 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 566 | end | 566 | end |
| 567 | 567 | ||
| 568 | if platforms.freebsd then | 568 | if platforms.freebsd then |
| 569 | defaults.arch = "freebsd-"..target_cpu | 569 | defaults.arch = "freebsd-" .. target_cpu |
| 570 | elseif platforms.dragonfly then | 570 | elseif platforms.dragonfly then |
| 571 | defaults.arch = "dragonfly-"..target_cpu | 571 | defaults.arch = "dragonfly-" .. target_cpu |
| 572 | elseif platforms.openbsd then | 572 | elseif platforms.openbsd then |
| 573 | defaults.arch = "openbsd-"..target_cpu | 573 | defaults.arch = "openbsd-" .. target_cpu |
| 574 | elseif platforms.netbsd then | 574 | elseif platforms.netbsd then |
| 575 | defaults.arch = "netbsd-"..target_cpu | 575 | defaults.arch = "netbsd-" .. target_cpu |
| 576 | elseif platforms.solaris then | 576 | elseif platforms.solaris then |
| 577 | defaults.arch = "solaris-"..target_cpu | 577 | defaults.arch = "solaris-" .. target_cpu |
| 578 | defaults.variables.MAKE = "gmake" | 578 | defaults.variables.MAKE = "gmake" |
| 579 | end | 579 | end |
| 580 | 580 | ||
| 581 | -- Expose some more values detected by LuaRocks for use by rockspec authors. | 581 | |
| 582 | defaults.variables.LIB_EXTENSION = defaults.lib_extension | 582 | defaults.variables.LIB_EXTENSION = defaults.lib_extension |
| 583 | defaults.variables.OBJ_EXTENSION = defaults.obj_extension | 583 | defaults.variables.OBJ_EXTENSION = defaults.obj_extension |
| 584 | 584 | ||
| @@ -587,12 +587,12 @@ end | |||
| 587 | 587 | ||
| 588 | local function use_defaults(cfg, defaults) | 588 | local function use_defaults(cfg, defaults) |
| 589 | 589 | ||
| 590 | -- Populate variables with values from their 'defaults' counterparts | 590 | |
| 591 | -- if they were not already set by user. | 591 | |
| 592 | if not cfg.variables then | 592 | if not cfg.variables then |
| 593 | cfg.variables = {} | 593 | cfg.variables = {} |
| 594 | end | 594 | end |
| 595 | for k,v in pairs(defaults.variables) do | 595 | for k, v in pairs(defaults.variables) do |
| 596 | if not cfg.variables[k] then | 596 | if not cfg.variables[k] then |
| 597 | cfg.variables[k] = v | 597 | cfg.variables[k] = v |
| 598 | end | 598 | end |
| @@ -600,29 +600,29 @@ local function use_defaults(cfg, defaults) | |||
| 600 | 600 | ||
| 601 | util.deep_merge_under(cfg, defaults) | 601 | util.deep_merge_under(cfg, defaults) |
| 602 | 602 | ||
| 603 | -- FIXME get rid of this | 603 | |
| 604 | if not cfg.check_certificates then | 604 | if not cfg.check_certificates then |
| 605 | cfg.variables.CURLNOCERTFLAG = "-k" | 605 | cfg.variables.CURLNOCERTFLAG = "-k" |
| 606 | cfg.variables.WGETNOCERTFLAG = "--no-check-certificate" | 606 | cfg.variables.WGETNOCERTFLAG = "--no-check-certificate" |
| 607 | end | 607 | end |
| 608 | end | 608 | end |
| 609 | 609 | ||
| 610 | -------------------------------------------------------------------------------- | 610 | |
| 611 | 611 | ||
| 612 | local cfg = {} | 612 | local cfg = {} |
| 613 | 613 | ||
| 614 | --- Initializes the LuaRocks configuration for variables, paths | 614 | |
| 615 | -- and OS detection. | 615 | |
| 616 | -- @param detected table containing information detected about the | 616 | |
| 617 | -- environment. All fields below are optional: | 617 | |
| 618 | -- * lua_version (in x.y format, e.g. "5.3") | 618 | |
| 619 | -- * lua_bindir (e.g. "/usr/local/bin") | 619 | |
| 620 | -- * lua_dir (e.g. "/usr/local") | 620 | |
| 621 | -- * lua (e.g. "/usr/local/bin/lua-5.3") | 621 | |
| 622 | -- * project_dir (a string with the path of the project directory | 622 | |
| 623 | -- when using per-project environments, as created with `luarocks init`) | 623 | |
| 624 | -- @param warning a logging function for warnings that takes a string | 624 | |
| 625 | -- @return true on success; nil and an error message on failure. | 625 | |
| 626 | function cfg.init(detected, warning) | 626 | function cfg.init(detected, warning) |
| 627 | detected = detected or {} | 627 | detected = detected or {} |
| 628 | 628 | ||
| @@ -637,9 +637,9 @@ function cfg.init(detected, warning) | |||
| 637 | 637 | ||
| 638 | local init = cfg.init | 638 | local init = cfg.init |
| 639 | 639 | ||
| 640 | ---------------------------------------- | 640 | |
| 641 | -- Reset the cfg table. | 641 | |
| 642 | ---------------------------------------- | 642 | |
| 643 | 643 | ||
| 644 | for k, _ in pairs(cfg) do | 644 | for k, _ in pairs(cfg) do |
| 645 | cfg[k] = nil | 645 | cfg[k] = nil |
| @@ -651,7 +651,7 @@ function cfg.init(detected, warning) | |||
| 651 | cfg.is_binary = true | 651 | cfg.is_binary = true |
| 652 | end | 652 | end |
| 653 | 653 | ||
| 654 | -- Use detected values as defaults, overridable via config files or CLI args | 654 | |
| 655 | 655 | ||
| 656 | local hardcoded_lua = hardcoded.LUA | 656 | local hardcoded_lua = hardcoded.LUA |
| 657 | local hardcoded_lua_dir = hardcoded.LUA_DIR | 657 | local hardcoded_lua_dir = hardcoded.LUA_DIR |
| @@ -660,8 +660,8 @@ function cfg.init(detected, warning) | |||
| 660 | local hardcoded_lua_libdir = hardcoded.LUA_LIBDIR | 660 | local hardcoded_lua_libdir = hardcoded.LUA_LIBDIR |
| 661 | local hardcoded_lua_version = hardcoded.LUA_VERSION or _VERSION:sub(5) | 661 | local hardcoded_lua_version = hardcoded.LUA_VERSION or _VERSION:sub(5) |
| 662 | 662 | ||
| 663 | -- if --lua-version or --lua-dir are passed from the CLI, | 663 | |
| 664 | -- don't use the hardcoded paths at all | 664 | |
| 665 | if detected.given_lua_version or detected.given_lua_dir then | 665 | if detected.given_lua_version or detected.given_lua_dir then |
| 666 | hardcoded_lua = nil | 666 | hardcoded_lua = nil |
| 667 | hardcoded_lua_dir = nil | 667 | hardcoded_lua_dir = nil |
| @@ -689,13 +689,13 @@ function cfg.init(detected, warning) | |||
| 689 | 689 | ||
| 690 | cfg.init = init | 690 | cfg.init = init |
| 691 | 691 | ||
| 692 | ---------------------------------------- | ||
| 693 | -- System detection. | ||
| 694 | ---------------------------------------- | ||
| 695 | 692 | ||
| 696 | -- A proper build of LuaRocks will hardcode the system | 693 | |
| 697 | -- and proc values with hardcoded.SYSTEM and hardcoded.PROCESSOR. | 694 | |
| 698 | -- If that is not available, we try to identify the system. | 695 | |
| 696 | |||
| 697 | |||
| 698 | |||
| 699 | local system, processor = sysdetect.detect() | 699 | local system, processor = sysdetect.detect() |
| 700 | if hardcoded.SYSTEM then | 700 | if hardcoded.SYSTEM then |
| 701 | system = hardcoded.SYSTEM | 701 | system = hardcoded.SYSTEM |
| @@ -706,7 +706,7 @@ function cfg.init(detected, warning) | |||
| 706 | 706 | ||
| 707 | if system == "windows" then | 707 | if system == "windows" then |
| 708 | if os.getenv("VCINSTALLDIR") then | 708 | if os.getenv("VCINSTALLDIR") then |
| 709 | -- running from the Development Command prompt for VS 2017 | 709 | |
| 710 | system = "windows" | 710 | system = "windows" |
| 711 | else | 711 | else |
| 712 | local msystem = os.getenv("MSYSTEM") | 712 | local msystem = os.getenv("MSYSTEM") |
| @@ -715,7 +715,7 @@ function cfg.init(detected, warning) | |||
| 715 | elseif msystem == "MSYS" then | 715 | elseif msystem == "MSYS" then |
| 716 | system = "msys" | 716 | system = "msys" |
| 717 | else | 717 | else |
| 718 | -- MINGW32 or MINGW64 | 718 | |
| 719 | system = "msys2_mingw_w64" | 719 | system = "msys2_mingw_w64" |
| 720 | end | 720 | end |
| 721 | end | 721 | end |
| @@ -725,16 +725,16 @@ function cfg.init(detected, warning) | |||
| 725 | 725 | ||
| 726 | local platforms = make_platforms(system) | 726 | local platforms = make_platforms(system) |
| 727 | 727 | ||
| 728 | ---------------------------------------- | 728 | |
| 729 | -- Platform is determined. | 729 | |
| 730 | -- Let's load the config files. | 730 | |
| 731 | ---------------------------------------- | 731 | |
| 732 | 732 | ||
| 733 | local sys_config_file | 733 | local sys_config_file |
| 734 | local home_config_file | 734 | local home_config_file |
| 735 | local project_config_file | 735 | local project_config_file |
| 736 | 736 | ||
| 737 | local config_file_name = "config-"..cfg.lua_version..".lua" | 737 | local config_file_name = "config-" .. cfg.lua_version .. ".lua" |
| 738 | 738 | ||
| 739 | do | 739 | do |
| 740 | local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR | 740 | local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR |
| @@ -749,30 +749,30 @@ function cfg.init(detected, warning) | |||
| 749 | end | 749 | end |
| 750 | end | 750 | end |
| 751 | 751 | ||
| 752 | -- Load system configuration file | 752 | |
| 753 | sys_config_file = dir.path(cfg.sysconfdir, config_file_name) | 753 | sys_config_file = dir.path(cfg.sysconfdir, config_file_name) |
| 754 | local sys_config_ok, err = load_config_file(cfg, platforms, sys_config_file) | 754 | local sys_config_ok, err = load_config_file(cfg, platforms, sys_config_file) |
| 755 | if err then | 755 | if err then |
| 756 | exit_ok, exit_err, exit_what = nil, err, "config" | 756 | exit_ok, exit_err, exit_what = nil, err, "config" |
| 757 | end | 757 | end |
| 758 | 758 | ||
| 759 | -- Load user configuration file (if allowed) | 759 | |
| 760 | local home_config_ok | 760 | local home_config_ok |
| 761 | local project_config_ok | 761 | local project_config_ok |
| 762 | if not hardcoded.FORCE_CONFIG then | 762 | if not hardcoded.FORCE_CONFIG then |
| 763 | local env_var = "LUAROCKS_CONFIG_" .. cfg.lua_version:gsub("%.", "_") | 763 | local env_var = "LUAROCKS_CONFIG_" .. cfg.lua_version:gsub("%.", "_") |
| 764 | local env_value = os.getenv(env_var) | 764 | local env_value = os.getenv(env_var) |
| 765 | if not env_value then | 765 | if not env_value then |
| 766 | env_var = "LUAROCKS_CONFIG" | 766 | env_var = "LUAROCKS_CONFIG" |
| 767 | env_value = os.getenv(env_var) | 767 | env_value = os.getenv(env_var) |
| 768 | end | 768 | end |
| 769 | -- first try environment provided file, so we can explicitly warn when it is missing | 769 | |
| 770 | if env_value then | 770 | if env_value then |
| 771 | local env_ok, err = load_config_file(cfg, platforms, env_value) | 771 | local env_ok, err = load_config_file(cfg, platforms, env_value) |
| 772 | if err then | 772 | if err then |
| 773 | exit_ok, exit_err, exit_what = nil, err, "config" | 773 | exit_ok, exit_err, exit_what = nil, err, "config" |
| 774 | elseif warning and not env_ok then | 774 | elseif warning and not env_ok then |
| 775 | warning("Warning: could not load configuration file `"..env_value.."` given in environment variable "..env_var.."\n") | 775 | warning("Warning: could not load configuration file `" .. env_value .. "` given in environment variable " .. env_var .. "\n") |
| 776 | end | 776 | end |
| 777 | if env_ok then | 777 | if env_ok then |
| 778 | home_config_ok = true | 778 | home_config_ok = true |
| @@ -780,7 +780,7 @@ function cfg.init(detected, warning) | |||
| 780 | end | 780 | end |
| 781 | end | 781 | end |
| 782 | 782 | ||
| 783 | -- try XDG config home | 783 | |
| 784 | if platforms.unix and not home_config_ok then | 784 | if platforms.unix and not home_config_ok then |
| 785 | local xdg_config_home = os.getenv("XDG_CONFIG_HOME") or dir.path(cfg.home, ".config") | 785 | local xdg_config_home = os.getenv("XDG_CONFIG_HOME") or dir.path(cfg.home, ".config") |
| 786 | cfg.homeconfdir = dir.path(xdg_config_home, "luarocks") | 786 | cfg.homeconfdir = dir.path(xdg_config_home, "luarocks") |
| @@ -791,7 +791,7 @@ function cfg.init(detected, warning) | |||
| 791 | end | 791 | end |
| 792 | end | 792 | end |
| 793 | 793 | ||
| 794 | -- try the alternative defaults if there was no environment specified file or it didn't work | 794 | |
| 795 | if not home_config_ok then | 795 | if not home_config_ok then |
| 796 | cfg.homeconfdir = cfg.home_tree | 796 | cfg.homeconfdir = cfg.home_tree |
| 797 | home_config_file = dir.path(cfg.homeconfdir, config_file_name) | 797 | home_config_file = dir.path(cfg.homeconfdir, config_file_name) |
| @@ -801,7 +801,7 @@ function cfg.init(detected, warning) | |||
| 801 | end | 801 | end |
| 802 | end | 802 | end |
| 803 | 803 | ||
| 804 | -- finally, use the project-specific config file if any | 804 | |
| 805 | if cfg.project_dir then | 805 | if cfg.project_dir then |
| 806 | project_config_file = dir.path(cfg.project_dir, ".luarocks", config_file_name) | 806 | project_config_file = dir.path(cfg.project_dir, ".luarocks", config_file_name) |
| 807 | project_config_ok, err = load_config_file(cfg, platforms, project_config_file) | 807 | project_config_ok, err = load_config_file(cfg, platforms, project_config_file) |
| @@ -811,17 +811,17 @@ function cfg.init(detected, warning) | |||
| 811 | end | 811 | end |
| 812 | end | 812 | end |
| 813 | 813 | ||
| 814 | -- backwards compatibility: | 814 | |
| 815 | if cfg.lua_interpreter and cfg.variables.LUA_BINDIR and not cfg.variables.LUA then | 815 | if cfg.lua_interpreter and cfg.variables.LUA_BINDIR and not cfg.variables.LUA then |
| 816 | cfg.variables.LUA = dir.path(cfg.variables.LUA_BINDIR, cfg.lua_interpreter) | 816 | cfg.variables.LUA = dir.path(cfg.variables.LUA_BINDIR, cfg.lua_interpreter) |
| 817 | end | 817 | end |
| 818 | 818 | ||
| 819 | ---------------------------------------- | ||
| 820 | -- Config files are loaded. | ||
| 821 | -- Let's finish up the cfg table. | ||
| 822 | ---------------------------------------- | ||
| 823 | 819 | ||
| 824 | -- Settings given via the CLI (i.e. --lua-dir) take precedence over config files. | 820 | |
| 821 | |||
| 822 | |||
| 823 | |||
| 824 | |||
| 825 | cfg.project_dir = detected.given_project_dir or cfg.project_dir | 825 | cfg.project_dir = detected.given_project_dir or cfg.project_dir |
| 826 | cfg.lua_version = detected.given_lua_version or cfg.lua_version | 826 | cfg.lua_version = detected.given_lua_version or cfg.lua_version |
| 827 | if detected.given_lua_dir then | 827 | if detected.given_lua_dir then |
| @@ -832,21 +832,21 @@ function cfg.init(detected, warning) | |||
| 832 | cfg.variables.LUA_INCDIR = nil | 832 | cfg.variables.LUA_INCDIR = nil |
| 833 | end | 833 | end |
| 834 | 834 | ||
| 835 | -- Build a default list of rocks trees if not given | 835 | |
| 836 | if cfg.rocks_trees == nil then | 836 | if cfg.rocks_trees == nil then |
| 837 | cfg.rocks_trees = {} | 837 | cfg.rocks_trees = {} |
| 838 | if cfg.home_tree then | 838 | if cfg.home_tree then |
| 839 | table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } ) | 839 | table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree }) |
| 840 | end | 840 | end |
| 841 | if hardcoded.PREFIX and hardcoded.PREFIX ~= cfg.home_tree then | 841 | if hardcoded.PREFIX and hardcoded.PREFIX ~= cfg.home_tree then |
| 842 | table.insert(cfg.rocks_trees, { name = "system", root = hardcoded.PREFIX } ) | 842 | table.insert(cfg.rocks_trees, { name = "system", root = hardcoded.PREFIX }) |
| 843 | end | 843 | end |
| 844 | end | 844 | end |
| 845 | 845 | ||
| 846 | local defaults = make_defaults(cfg.lua_version, processor, platforms, cfg.home) | 846 | local defaults = make_defaults(cfg.lua_version, processor, platforms, cfg.home) |
| 847 | 847 | ||
| 848 | if platforms.windows and hardcoded.WIN_TOOLS then | 848 | if platforms.windows and hardcoded.WIN_TOOLS then |
| 849 | local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "WGET", } | 849 | local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "WGET" } |
| 850 | for _, tool in ipairs(tools) do | 850 | for _, tool in ipairs(tools) do |
| 851 | defaults.variables[tool] = '"' .. dir.path(hardcoded.WIN_TOOLS, defaults.variables[tool] .. '.exe') .. '"' | 851 | defaults.variables[tool] = '"' .. dir.path(hardcoded.WIN_TOOLS, defaults.variables[tool] .. '.exe') .. '"' |
| 852 | end | 852 | end |
| @@ -854,8 +854,8 @@ function cfg.init(detected, warning) | |||
| 854 | defaults.fs_use_modules = true | 854 | defaults.fs_use_modules = true |
| 855 | end | 855 | end |
| 856 | 856 | ||
| 857 | -- if only cfg.variables.LUA is given in config files, | 857 | |
| 858 | -- derive LUA_BINDIR and LUA_DIR from them. | 858 | |
| 859 | if cfg.variables.LUA and not cfg.variables.LUA_BINDIR then | 859 | if cfg.variables.LUA and not cfg.variables.LUA_BINDIR then |
| 860 | cfg.variables.LUA_BINDIR = cfg.variables.LUA:match("^(.*)[\\/][^\\/]*$") | 860 | cfg.variables.LUA_BINDIR = cfg.variables.LUA:match("^(.*)[\\/][^\\/]*$") |
| 861 | if not cfg.variables.LUA_DIR then | 861 | if not cfg.variables.LUA_DIR then |
| @@ -865,7 +865,7 @@ function cfg.init(detected, warning) | |||
| 865 | 865 | ||
| 866 | use_defaults(cfg, defaults) | 866 | use_defaults(cfg, defaults) |
| 867 | 867 | ||
| 868 | cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch | 868 | cfg.user_agent = "LuaRocks/" .. cfg.program_version .. " " .. cfg.arch |
| 869 | 869 | ||
| 870 | cfg.config_files = { | 870 | cfg.config_files = { |
| 871 | project = cfg.project_dir and { | 871 | project = cfg.project_dir and { |
| @@ -880,19 +880,19 @@ function cfg.init(detected, warning) | |||
| 880 | file = home_config_file, | 880 | file = home_config_file, |
| 881 | found = not not home_config_ok, | 881 | found = not not home_config_ok, |
| 882 | }, | 882 | }, |
| 883 | nearest = project_config_ok | 883 | nearest = project_config_ok and |
| 884 | and project_config_file | 884 | project_config_file or |
| 885 | or (home_config_ok | 885 | (home_config_ok and |
| 886 | and home_config_file | 886 | home_config_file or |
| 887 | or sys_config_file), | 887 | sys_config_file), |
| 888 | } | 888 | } |
| 889 | 889 | ||
| 890 | cfg.cache = {} | 890 | cfg.cache = {} |
| 891 | 891 | ||
| 892 | ---------------------------------------- | 892 | |
| 893 | -- Attributes of cfg are set. | 893 | |
| 894 | -- Let's add some methods. | 894 | |
| 895 | ---------------------------------------- | 895 | |
| 896 | 896 | ||
| 897 | do | 897 | do |
| 898 | local function make_paths_from_tree(tree) | 898 | local function make_paths_from_tree(tree) |
| @@ -913,15 +913,15 @@ function cfg.init(detected, warning) | |||
| 913 | local new_path, new_cpath, new_bin = {}, {}, {} | 913 | local new_path, new_cpath, new_bin = {}, {}, {} |
| 914 | local function add_tree_to_paths(tree) | 914 | local function add_tree_to_paths(tree) |
| 915 | local lua_path, lib_path, bin_path = make_paths_from_tree(tree) | 915 | local lua_path, lib_path, bin_path = make_paths_from_tree(tree) |
| 916 | table.insert(new_path, dir.path(lua_path, "?.lua")) | 916 | table.insert(new_path, dir.path(lua_path, "?.lua")) |
| 917 | table.insert(new_path, dir.path(lua_path, "?", "init.lua")) | 917 | table.insert(new_path, dir.path(lua_path, "?", "init.lua")) |
| 918 | table.insert(new_cpath, dir.path(lib_path, "?."..cfg.lib_extension)) | 918 | table.insert(new_cpath, dir.path(lib_path, "?." .. cfg.lib_extension)) |
| 919 | table.insert(new_bin, bin_path) | 919 | table.insert(new_bin, bin_path) |
| 920 | end | 920 | end |
| 921 | if current then | 921 | if current then |
| 922 | add_tree_to_paths(current) | 922 | add_tree_to_paths(current) |
| 923 | end | 923 | end |
| 924 | for _,tree in ipairs(cfg.rocks_trees) do | 924 | for _, tree in ipairs(cfg.rocks_trees) do |
| 925 | add_tree_to_paths(tree) | 925 | add_tree_to_paths(tree) |
| 926 | end | 926 | end |
| 927 | return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator) | 927 | return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator) |
| @@ -934,15 +934,15 @@ function cfg.init(detected, warning) | |||
| 934 | package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", cfg.lua_version, true) | 934 | package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", cfg.lua_version, true) |
| 935 | end | 935 | end |
| 936 | 936 | ||
| 937 | --- Check if platform was detected | 937 | |
| 938 | -- @param name string: The platform name to check. | 938 | |
| 939 | -- @return boolean: true if LuaRocks is currently running on queried platform. | 939 | |
| 940 | function cfg.is_platform(name) | 940 | function cfg.is_platform(name) |
| 941 | assert(type(name) == "string") | 941 | assert(type(name) == "string") |
| 942 | return platforms[name] | 942 | return platforms[name] |
| 943 | end | 943 | end |
| 944 | 944 | ||
| 945 | -- @param direction (optional) "least-specific-first" (default) or "most-specific-first" | 945 | |
| 946 | function cfg.each_platform(direction) | 946 | function cfg.each_platform(direction) |
| 947 | direction = direction or "least-specific-first" | 947 | direction = direction or "least-specific-first" |
| 948 | local i, delta | 948 | local i, delta |
| @@ -965,7 +965,7 @@ function cfg.init(detected, warning) | |||
| 965 | 965 | ||
| 966 | function cfg.print_platforms() | 966 | function cfg.print_platforms() |
| 967 | local platform_keys = {} | 967 | local platform_keys = {} |
| 968 | for k,_ in pairs(platforms) do | 968 | for k, _ in pairs(platforms) do |
| 969 | table.insert(platform_keys, k) | 969 | table.insert(platform_keys, k) |
| 970 | end | 970 | end |
| 971 | table.sort(platform_keys) | 971 | table.sort(platform_keys) |
diff --git a/src/luarocks/core/cfg.tl b/src/luarocks/core/cfg.tl index 77605554..f4c78ebf 100644 --- a/src/luarocks/core/cfg.tl +++ b/src/luarocks/core/cfg.tl | |||
| @@ -62,7 +62,6 @@ local type Config = record --! | |||
| 62 | os_getenv: any | 62 | os_getenv: any |
| 63 | rocks_trees: any | 63 | rocks_trees: any |
| 64 | rocks_servers: any | 64 | rocks_servers: any |
| 65 | check_certificates: any | ||
| 66 | dump_env: function() | 65 | dump_env: function() |
| 67 | end | 66 | end |
| 68 | 67 | ||
| @@ -219,8 +218,8 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 219 | link_lua_explicitly = false, | 218 | link_lua_explicitly = false, |
| 220 | 219 | ||
| 221 | external_deps_dirs = {}, --? | 220 | external_deps_dirs = {}, --? |
| 222 | external_deps_patterns: {string} = {}, --? | 221 | external_deps_patterns = {}, --? |
| 223 | runtime_external_deps_patterns: {string} = {}, --? | 222 | runtime_external_deps_patterns = {}, --? |
| 224 | 223 | ||
| 225 | export_path_separator = "", --? | 224 | export_path_separator = "", --? |
| 226 | wrapper_suffix = "", --? | 225 | wrapper_suffix = "", --? |
| @@ -245,8 +244,8 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 245 | connection_timeout = 30, -- 0 = no timeout | 244 | connection_timeout = 30, -- 0 = no timeout |
| 246 | 245 | ||
| 247 | makefile = "", --? | 246 | makefile = "", --? |
| 248 | local_cache = "", --? "" | {""} | 247 | local_cache = "" , --? |
| 249 | web_browser = "", --? "" | {""} | 248 | web_browser = "", --? |
| 250 | cmake_generator = "", --? | 249 | cmake_generator = "", --? |
| 251 | gcc_rpath = false, --? | 250 | gcc_rpath = false, --? |
| 252 | 251 | ||
| @@ -306,8 +305,6 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 306 | LDFLAGS = "", --? | 305 | LDFLAGS = "", --? |
| 307 | LIBFLAG = "", --? | 306 | LIBFLAG = "", --? |
| 308 | TEST = "", --? | 307 | TEST = "", --? |
| 309 | LIB_EXTENSION = "", --? | ||
| 310 | OBJ_EXTENSION = "", --? | ||
| 311 | }, | 308 | }, |
| 312 | 309 | ||
| 313 | external_deps_subdirs = { | 310 | external_deps_subdirs = { |
| @@ -588,7 +585,7 @@ local function make_defaults(lua_version: string, target_cpu: string, platforms: | |||
| 588 | return defaults | 585 | return defaults |
| 589 | end | 586 | end |
| 590 | 587 | ||
| 591 | local function use_defaults(cfg: Config, defaults: Config) --! | 588 | local function use_defaults(cfg, defaults) |
| 592 | 589 | ||
| 593 | -- Populate variables with values from their 'defaults' counterparts | 590 | -- Populate variables with values from their 'defaults' counterparts |
| 594 | -- if they were not already set by user. | 591 | -- if they were not already set by user. |
| @@ -626,7 +623,7 @@ local cfg = {} | |||
| 626 | -- when using per-project environments, as created with `luarocks init`) | 623 | -- when using per-project environments, as created with `luarocks init`) |
| 627 | -- @param warning a logging function for warnings that takes a string | 624 | -- @param warning a logging function for warnings that takes a string |
| 628 | -- @return true on success; nil and an error message on failure. | 625 | -- @return true on success; nil and an error message on failure. |
| 629 | function cfg.init(detected: {any: any}, warning: function(string)): nil, string, string --! | 626 | function cfg.init(detected, warning) |
| 630 | detected = detected or {} | 627 | detected = detected or {} |
| 631 | 628 | ||
| 632 | local exit_ok = true | 629 | local exit_ok = true |
| @@ -733,22 +730,22 @@ function cfg.init(detected: {any: any}, warning: function(string)): nil, string, | |||
| 733 | -- Let's load the config files. | 730 | -- Let's load the config files. |
| 734 | ---------------------------------------- | 731 | ---------------------------------------- |
| 735 | 732 | ||
| 736 | local sys_config_file: string --? | 733 | local sys_config_file |
| 737 | local home_config_file: string | 734 | local home_config_file |
| 738 | local project_config_file: string | 735 | local project_config_file |
| 739 | 736 | ||
| 740 | local config_file_name = "config-"..cfg.lua_version..".lua" | 737 | local config_file_name = "config-"..cfg.lua_version..".lua" |
| 741 | 738 | ||
| 742 | do | 739 | do |
| 743 | local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR | 740 | local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR |
| 744 | if platforms.windows and not platforms.msys2_mingw_w64 then | 741 | if platforms.windows and not platforms.msys2_mingw_w64 then |
| 745 | cfg.home = os.getenv("APPDATA") or "c:" --! | 742 | cfg.home = os.getenv("APPDATA") or "c:" |
| 746 | cfg.home_tree = dir.path(cfg.home, "luarocks") --! | 743 | cfg.home_tree = dir.path(cfg.home, "luarocks") |
| 747 | cfg.sysconfdir = sysconfdir or dir.path((os.getenv("PROGRAMFILES") or "c:"), "luarocks") --! | 744 | cfg.sysconfdir = sysconfdir or dir.path((os.getenv("PROGRAMFILES") or "c:"), "luarocks") |
| 748 | else | 745 | else |
| 749 | cfg.home = os.getenv("HOME") or "" --! | 746 | cfg.home = os.getenv("HOME") or "" |
| 750 | cfg.home_tree = dir.path(cfg.home, ".luarocks") --! | 747 | cfg.home_tree = dir.path(cfg.home, ".luarocks") |
| 751 | cfg.sysconfdir = sysconfdir or detect_sysconfdir() or "/etc/luarocks" --! | 748 | cfg.sysconfdir = sysconfdir or detect_sysconfdir() or "/etc/luarocks" |
| 752 | end | 749 | end |
| 753 | end | 750 | end |
| 754 | 751 | ||
| @@ -760,8 +757,8 @@ function cfg.init(detected: {any: any}, warning: function(string)): nil, string, | |||
| 760 | end | 757 | end |
| 761 | 758 | ||
| 762 | -- Load user configuration file (if allowed) | 759 | -- Load user configuration file (if allowed) |
| 763 | local home_config_ok: boolean | 760 | local home_config_ok |
| 764 | local project_config_ok: boolean | 761 | local project_config_ok |
| 765 | if not hardcoded.FORCE_CONFIG then | 762 | if not hardcoded.FORCE_CONFIG then |
| 766 | local env_var = "LUAROCKS_CONFIG_" .. cfg.lua_version:gsub("%.", "_") | 763 | local env_var = "LUAROCKS_CONFIG_" .. cfg.lua_version:gsub("%.", "_") |
| 767 | local env_value = os.getenv(env_var) | 764 | local env_value = os.getenv(env_var) |
| @@ -898,8 +895,8 @@ function cfg.init(detected: {any: any}, warning: function(string)): nil, string, | |||
| 898 | ---------------------------------------- | 895 | ---------------------------------------- |
| 899 | 896 | ||
| 900 | do | 897 | do |
| 901 | local function make_paths_from_tree(tree: {any: string}): string, string, string | 898 | local function make_paths_from_tree(tree) |
| 902 | local lua_path, lib_path, bin_path: string, string, string | 899 | local lua_path, lib_path, bin_path |
| 903 | if type(tree) == "string" then | 900 | if type(tree) == "string" then |
| 904 | lua_path = dir.path(tree, cfg.lua_modules_path) | 901 | lua_path = dir.path(tree, cfg.lua_modules_path) |
| 905 | lib_path = dir.path(tree, cfg.lib_modules_path) | 902 | lib_path = dir.path(tree, cfg.lib_modules_path) |
| @@ -940,15 +937,15 @@ function cfg.init(detected: {any: any}, warning: function(string)): nil, string, | |||
| 940 | --- Check if platform was detected | 937 | --- Check if platform was detected |
| 941 | -- @param name string: The platform name to check. | 938 | -- @param name string: The platform name to check. |
| 942 | -- @return boolean: true if LuaRocks is currently running on queried platform. | 939 | -- @return boolean: true if LuaRocks is currently running on queried platform. |
| 943 | function cfg.is_platform(name: string): boolean | 940 | function cfg.is_platform(name) |
| 944 | assert(type(name) == "string") | 941 | assert(type(name) == "string") |
| 945 | return platforms[name] | 942 | return platforms[name] |
| 946 | end | 943 | end |
| 947 | 944 | ||
| 948 | -- @param direction (optional) "least-specific-first" (default) or "most-specific-first" | 945 | -- @param direction (optional) "least-specific-first" (default) or "most-specific-first" |
| 949 | function cfg.each_platform(direction: string): function(): string | 946 | function cfg.each_platform(direction) |
| 950 | direction = direction or "least-specific-first" | 947 | direction = direction or "least-specific-first" |
| 951 | local i, delta: integer, integer | 948 | local i, delta |
| 952 | if direction == "least-specific-first" then | 949 | if direction == "least-specific-first" then |
| 953 | i = 0 | 950 | i = 0 |
| 954 | delta = 1 | 951 | delta = 1 |
| @@ -957,7 +954,7 @@ function cfg.init(detected: {any: any}, warning: function(string)): nil, string, | |||
| 957 | delta = -1 | 954 | delta = -1 |
| 958 | end | 955 | end |
| 959 | return function() | 956 | return function() |
| 960 | local p: string | 957 | local p |
| 961 | repeat | 958 | repeat |
| 962 | i = i + delta | 959 | i = i + delta |
| 963 | p = platform_order[i] | 960 | p = platform_order[i] |
| @@ -966,7 +963,7 @@ function cfg.init(detected: {any: any}, warning: function(string)): nil, string, | |||
| 966 | end | 963 | end |
| 967 | end | 964 | end |
| 968 | 965 | ||
| 969 | function cfg.print_platforms(): string | 966 | function cfg.print_platforms() |
| 970 | local platform_keys = {} | 967 | local platform_keys = {} |
| 971 | for k,_ in pairs(platforms) do | 968 | for k,_ in pairs(platforms) do |
| 972 | table.insert(platform_keys, k) | 969 | table.insert(platform_keys, k) |
| @@ -978,4 +975,4 @@ function cfg.init(detected: {any: any}, warning: function(string)): nil, string, | |||
| 978 | return exit_ok, exit_err, exit_what | 975 | return exit_ok, exit_err, exit_what |
| 979 | end | 976 | end |
| 980 | 977 | ||
| 981 | return cfg \ No newline at end of file | 978 | return cfg |
