Skip to content

Commit

Permalink
rock: override built-in checks
Browse files Browse the repository at this point in the history
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. tarantool/tarantool#7774
2. tarantool/tarantool#7726
  • Loading branch information
DifferentialOrange committed Mar 17, 2023
1 parent db5dfa3 commit e54545e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/push_rockspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions debian/tarantool-checks.install
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
checks.lua usr/share/tarantool/
checks usr/share/tarantool/
checks.lua usr/share/tarantool/override
checks usr/share/tarantool/override
3 changes: 3 additions & 0 deletions rpm/tarantool-checks.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion test/rock_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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,
}

0 comments on commit e54545e

Please sign in to comment.