From 6b777105e72bd9489101abfb7dd69a49b4cf9fea Mon Sep 17 00:00:00 2001 From: Yaroslav Dynnikov Date: Thu, 16 May 2019 17:21:41 +0300 Subject: [PATCH] Made luarocks compatible with tarantool * Skip external commands loading if no external_namespace provided: it is so when a command is run using `tarantoolctl rocks `. * Allow to omit a description field in a rockspec. * Configure more options using hardcoded.lua (it is named as site_config.lua in luarocks-2.x). Based on or inspired by the following commits: - 9f557665 ('Add LUAROCKS_LOCAL_BY_DEFAULT option to site_config.lua'). - e3f74869 ('Allow to override certain values in cfg.lua'). - dba49e0d ('Enable cfg.home_tree even for root'). - 6e6fe62d ('Add site_config.LUAROCKS_LOCALDIR config variable'). The following options are added for hardcoded.lua: - LOCALDIR - LOCAL_BY_DEFAULT - HOMEDIR - HOME_TREE_SUBDIR - LUA_MODULES_LUA_SUBDIR - LUA_MODULES_LIB_SUBDIR - ROCKS_SERVERS The following options are ported from luarocks-2 (and renamed from LUAROCKS_FOO to FOO): - ROCKS_SUBDIR - EXTERNAL_DEPS_SUBDIRS All that options are needed to adjust behaviour of luarocks from tarantool-side hardcoded.lua file. * Detect tarantool and add it to rocks_provided and rocks_provided_3_0. Based on: - 370d1739 ('Detect and add Tarantool it to rocks_provided)' * Execute cfg.init() code only once. * Fixed strict mode. Inspired by: - dfaf765e ('Fix strict mode'). * Dropped site_config.lua support: tarantool doesn't use it anymore. --- src/luarocks/core/cfg.lua | 33 +++++++++++++++++++++------------ src/luarocks/core/sysdetect.lua | 1 + src/luarocks/loader.lua | 21 --------------------- src/luarocks/util.lua | 7 +++++++ 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index eb170f358..1ce19b292 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -170,13 +170,13 @@ end -------------------------------------------------------------------------------- -local function make_defaults(lua_version, target_cpu, platforms, home) +local function make_defaults(lua_version, target_cpu, platforms, home, hardcoded) -- Configure defaults: local defaults = { - lua_interpreter = "lua", - local_by_default = false, + lua_interpreter = hardcoded.LUA_INTERPRETER or "lua", + local_by_default = hardcoded.LOCAL_BY_DEFAULT or false, accept_unknown_fields = false, fs_use_modules = true, hooks_enabled = true, @@ -187,16 +187,16 @@ local function make_defaults(lua_version, target_cpu, platforms, home) cache_timeout = 60, cache_fail_timeout = 86400, - lua_modules_path = "/share/lua/"..lua_version, - lib_modules_path = "/lib/lua/"..lua_version, - rocks_subdir = "/lib/luarocks/rocks-"..lua_version, + lua_modules_path = hardcoded.LUA_MODULES_LUA_SUBDIR or "/share/lua/"..lua_version, + lib_modules_path = hardcoded.LUA_MODULES_LIB_SUBDIR or "/lib/lua/"..lua_version, + rocks_subdir = hardcoded.ROCKS_SUBDIR or "/lib/luarocks/rocks-"..lua_version, arch = "unknown", lib_extension = "unknown", obj_extension = "unknown", link_lua_explicitly = false, - rocks_servers = { + rocks_servers = hardcoded.ROCKS_SERVERS or { { "https://luarocks.org", "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/", @@ -264,12 +264,12 @@ local function make_defaults(lua_version, target_cpu, platforms, home) WGETNOCERTFLAG = "", }, - external_deps_subdirs = { + external_deps_subdirs = hardcoded.EXTERNAL_DEPS_SUBDIRS or { bin = "bin", lib = "lib", include = "include" }, - runtime_external_deps_subdirs = { + runtime_external_deps_subdirs = hardcoded.RUNTIME_EXTERNAL_DEPS_SUBDIRS or { bin = "bin", lib = "lib", include = "include" @@ -556,6 +556,7 @@ local function use_defaults(cfg, defaults) end local function get_first_arg() + local arg = rawget(_G, 'arg') if not arg then return end @@ -585,6 +586,10 @@ local cfg = {} -- @param warning a logging function for warnings that takes a string -- @return true on success; nil and an error message on failure. function cfg.init(detected, warning) + if cfg.initialized == true then + return true + end + detected = detected or {} local exit_ok = true @@ -687,8 +692,11 @@ function cfg.init(detected, warning) cfg.home_tree = cfg.home.."/luarocks" cfg.sysconfdir = sysconfdir or ((os.getenv("PROGRAMFILES") or "c:") .. "/luarocks") else - cfg.home = os.getenv("HOME") or "" - cfg.home_tree = cfg.home.."/.luarocks" + cfg.home = hardcoded.HOMEDIR or os.getenv("HOME") or "" + local localdir = hardcoded.LOCALDIR or cfg.home + local home_tree_subdir = hardcoded.HOME_TREE_SUBDIR or "/.luarocks" + cfg.homeconfdir = localdir .. home_tree_subdir + cfg.home_tree = localdir .. home_tree_subdir cfg.sysconfdir = sysconfdir or detect_sysconfdir() or "/etc/luarocks" end end @@ -782,7 +790,7 @@ function cfg.init(detected, warning) end end - local defaults = make_defaults(cfg.lua_version, processor, platforms, cfg.home) + local defaults = make_defaults(cfg.lua_version, processor, platforms, cfg.home, hardcoded) if platforms.windows and hardcoded.WIN_TOOLS then local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "WGET", } @@ -903,6 +911,7 @@ function cfg.init(detected, warning) return table.concat(platform_keys, ", ") end + cfg.initialized = true return exit_ok, exit_err, exit_what end diff --git a/src/luarocks/core/sysdetect.lua b/src/luarocks/core/sysdetect.lua index d999203ae..f4af1eb48 100644 --- a/src/luarocks/core/sysdetect.lua +++ b/src/luarocks/core/sysdetect.lua @@ -367,6 +367,7 @@ function sysdetect.detect(input_file) local dirsep = package.config:sub(1,1) local files + local arg = rawget(_G, 'arg') or {} if input_file then files = { input_file } else diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 772fdfcb4..c409a1da9 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -29,28 +29,7 @@ local vers = require("luarocks.core.vers") local require = nil -- luacheck: ignore 411 -------------------------------------------------------------------------------- --- Workaround for wrappers produced by older versions of LuaRocks local temporary_global = false -local status, luarocks_value = pcall(function() return luarocks end) -if status and luarocks_value then - -- The site_config.lua file generated by old versions uses module(), - -- so it produces a global `luarocks` table. Since we have the table, - -- add the `loader` field to make the old wrappers happy. - luarocks.loader = loader -else - -- When a new version is installed on top of an old version, - -- site_config.lua may be replaced, and then it no longer creates - -- a global. - -- Detect when being called via -lluarocks.loader; this is - -- most likely a wrapper. - local info = debug and debug.getinfo(2, "nS") - if info and info.what == "C" and not info.name then - luarocks = { loader = loader } - temporary_global = true - -- For the other half of this hack, - -- see the next use of `temporary_global` below. - end -end loader.context = {} diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index fa3a628ed..d044b170b 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -620,6 +620,13 @@ function util.get_rocks_provided(rockspec) end end + local tarantool_ver_raw = rawget(_G, '_TARANTOOL') + if tarantool_ver_raw then + -- Tarantool + local tarantool_version = tarantool_ver_raw:match("([^-]+)-") + rocks_provided["tarantool"] = tarantool_version.."-1" + end + if cfg.rocks_provided then util.deep_merge_under(rocks_provided, cfg.rocks_provided) end