Skip to content

Commit

Permalink
Made luarocks compatible with tarantool
Browse files Browse the repository at this point in the history
* Skip external commands loading if no external_namespace provided: it
  is so when a command is run using `tarantoolctl rocks <command>`.

* 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:

  - 9f55766 ('Add LUAROCKS_LOCAL_BY_DEFAULT option to site_config.lua').
  - e3f7486 ('Allow to override certain values in cfg.lua').
  - dba49e0 ('Enable cfg.home_tree even for root').
  - 6e6fe62 ('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:

  - 370d173 ('Detect and add Tarantool it to rocks_provided)'

* Execute cfg.init() code only once.

* Fixed strict mode.

  Inspired by:

  - dfaf765 ('Fix strict mode').

* Dropped site_config.lua support: tarantool doesn't use it anymore.
  • Loading branch information
rosik authored and 0x501D committed Sep 12, 2023
1 parent b5a1b7d commit 6b77710
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
33 changes: 21 additions & 12 deletions src/luarocks/core/cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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/",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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", }
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/luarocks/core/sysdetect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions src/luarocks/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
7 changes: 7 additions & 0 deletions src/luarocks/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b77710

Please sign in to comment.