From e54545ef7cb2240521119f4fd06fb21210ffbcc8 Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Fri, 17 Mar 2023 13:23:50 +0300 Subject: [PATCH] rock: override built-in checks The ability to override built-in modules was introduced with [1]. After [1], checks is embedded to the core Tarantool. The ability to override them with installed rock will make it possible to use old Tarantool with new checks. 1. https://github.com/tarantool/tarantool/issues/7774 2. https://github.com/tarantool/tarantool/issues/7726 --- .github/workflows/packaging.yml | 4 +--- .github/workflows/push_rockspec.yml | 4 +--- CMakeLists.txt | 10 ++++++++++ debian/tarantool-checks.install | 2 ++ rpm/tarantool-checks.spec | 3 +++ test/rock_utils.lua | 12 +++++++++++- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index 8a8ce1e..8cb84d4 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -23,9 +23,7 @@ jobs: with: module-name: checks version-pre-extraction-hook: | - local rock_utils = require('test.rock_utils') - rock_utils.remove_builtin('checks') - rock_utils.assert_nonbuiltin('checks') + require('test.rock_utils').assert_nonbuiltin('checks') package: # Skip pull request jobs when the source branch is in the same diff --git a/.github/workflows/push_rockspec.yml b/.github/workflows/push_rockspec.yml index 9936873..ae3e383 100644 --- a/.github/workflows/push_rockspec.yml +++ b/.github/workflows/push_rockspec.yml @@ -24,9 +24,7 @@ jobs: with: module-name: checks version-pre-extraction-hook: | - local rock_utils = require('test.rock_utils') - rock_utils.remove_builtin('checks') - rock_utils.assert_nonbuiltin('checks') + require('test.rock_utils').assert_nonbuiltin('checks') push-scm-rockspec: runs-on: [ ubuntu-20.04 ] diff --git a/CMakeLists.txt b/CMakeLists.txt index c3675a4..2025061 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,3 +18,13 @@ install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME} DESTINATION ${TARANTOOL_INSTALL_LUADIR} ) + +install( + FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.lua + DESTINATION ${TARANTOOL_INSTALL_LUADIR}/override +) + +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME} + DESTINATION ${TARANTOOL_INSTALL_LUADIR}/override +) diff --git a/debian/tarantool-checks.install b/debian/tarantool-checks.install index c256f86..b7fd8eb 100644 --- a/debian/tarantool-checks.install +++ b/debian/tarantool-checks.install @@ -1,2 +1,4 @@ checks.lua usr/share/tarantool/ checks usr/share/tarantool/ +checks.lua usr/share/tarantool/override +checks usr/share/tarantool/override diff --git a/rpm/tarantool-checks.spec b/rpm/tarantool-checks.spec index 9ba8f54..3e9a632 100644 --- a/rpm/tarantool-checks.spec +++ b/rpm/tarantool-checks.spec @@ -22,10 +22,13 @@ Easy, terse, readable and fast function arguments type checking. mkdir -p %{br_luapkgdir} cp -av checks.lua %{br_luapkgdir} cp -rv checks %{br_luapkgdir} +cp -av checks.lua %{br_luapkgdir}/override +cp -rv checks %{br_luapkgdir}/override %files %{luapkgdir}/checks.lua %{luapkgdir}/checks +%{luapkgdir}/override %doc README.md %{!?_licensedir:%global license %doc} %license LICENSE diff --git a/test/rock_utils.lua b/test/rock_utils.lua index 25bce1c..1af5bcf 100644 --- a/test/rock_utils.lua +++ b/test/rock_utils.lua @@ -31,8 +31,11 @@ local function traverse_pkg_func(func, name, pkg) end end -local function remove_builtin_pkg(name, _) +local function remove_loaded_pkg(name, _) package.loaded[name] = nil +end + +local function remove_builtin_pkg(name, _) if loaders_ok then loaders.builtin[name] = nil end @@ -59,6 +62,7 @@ local function assert_builtin_pkg(name, pkg) end local function remove_builtin_rock(name) + traverse_rock(remove_loaded_pkg, name) traverse_rock(remove_builtin_pkg, name) end @@ -72,8 +76,14 @@ local function assert_builtin_rock(name) traverse_rock(assert_builtin_pkg, name) end +local function disable_override_rock(name) + traverse_rock(remove_loaded_pkg, name) + loaders.override_builtin_disable() +end + return { assert_builtin = assert_builtin_rock, assert_nonbuiltin = assert_nonbuiltin_rock, remove_builtin = remove_builtin_rock, + disable_override = disable_override_rock, }