commit 3afbf4745bcc9836c0bc5e383a8e46cc16ea8014
parent 131a1ee82d15ce9d1356a46117c9a1651947d4b8
Author: bfredl <bjorn.linse@gmail.com>
Date: Thu, 7 Sep 2023 16:08:01 +0200
Merge pull request #25024 from bfredl/luacheck2
refactor(build): derocksify luacheck
Diffstat:
4 files changed, 92 insertions(+), 74 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -220,13 +220,13 @@ find_program(STYLUA_PRG stylua ${LINT_REQUIRED})
add_glob_target(
TARGET lintlua-luacheck
- COMMAND ${DEPS_BIN_DIR}/luacheck
- FLAGS -q
+ COMMAND $<TARGET_FILE:nvim>
+ FLAGS -ll ${PROJECT_SOURCE_DIR}/test/lua_runner.lua ${CMAKE_BINARY_DIR}/usr luacheck -q
GLOB_DIRS runtime/ scripts/ src/ test/
GLOB_PAT *.lua
EXCLUDE runtime/lua/vim/_meta/.*
TOUCH_STRATEGY SINGLE)
-add_dependencies(lintlua-luacheck luacheck)
+add_dependencies(lintlua-luacheck lua-dev-deps)
add_glob_target(
TARGET lintlua-stylua
@@ -297,14 +297,14 @@ ExternalProject_Add(uncrustify
include(BuildLuarocks)
-ExternalProject_Add(busted
- URL https://github.com/neovim/deps/raw/41d2f1b92aef964c8cb86985768702571e190e96/opt/busted-2.1.1.tar.gz
- URL_HASH SHA256=9b23efce883ad25a3fe140598a32ab89ecc73f4c3d998cb937293d88e5b4c645
+ExternalProject_Add(lua-dev-deps
+ URL https://github.com/neovim/deps/raw/5a1f71cceb24990a0b15fd9a472a5f549f019248/opt/lua-dev-deps.tar.gz
+ URL_HASH SHA256=27db2495f5eddc7fc191701ec9b291486853530c6125609d3197d03481e8d5a2
DOWNLOAD_NO_PROGRESS TRUE
- DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/busted
+ DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/lua-dev-deps
SOURCE_DIR ${DEPS_SHARE_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
EXCLUDE_FROM_ALL TRUE)
-add_dependencies(test_deps busted)
+add_dependencies(test_deps lua-dev-deps)
diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake
@@ -63,12 +63,11 @@ if(NOT DEFINED ENV{TEST_TIMEOUT} OR "$ENV{TEST_TIMEOUT}" STREQUAL "")
endif()
set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/helpers.lua.
-set(ENV{DEPS_INSTALL_DIR} ${DEPS_INSTALL_DIR}) # used by test/busted_runner.lua
execute_process(
# Note: because of "-ll" (low-level interpreter mode), some modules like
# _editor.lua are not loaded.
- COMMAND ${NVIM_PRG} -ll ${WORKING_DIR}/test/busted_runner.lua -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE}
+ COMMAND ${NVIM_PRG} -ll ${WORKING_DIR}/test/lua_runner.lua ${DEPS_INSTALL_DIR} busted -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE}
--lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
--lpath=${BUILD_DIR}/?.lua
--lpath=${WORKING_DIR}/runtime/lua/?.lua
diff --git a/test/busted_runner.lua b/test/busted_runner.lua
@@ -1,64 +0,0 @@
-local platform = vim.uv.os_uname()
-local deps_install_dir = os.getenv 'DEPS_INSTALL_DIR'
-local suffix = (platform and platform.sysname:lower():find'windows') and '.dll' or '.so'
-package.path = deps_install_dir.."/share/lua/5.1/?.lua;"..deps_install_dir.."/share/lua/5.1/?/init.lua;"..package.path
-package.cpath = deps_install_dir.."/lib/lua/5.1/?"..suffix..";"..package.cpath;
-
-local uv = vim.uv
-
-local system = {}
-package.loaded['system.core'] = system
-function system.monotime()
- uv.update_time()
- return uv.now()*1e-3
-end
-function system.gettime()
- local sec, usec = uv.gettimeofday()
- return sec+usec*1e-6
-end
-function system.sleep(sec)
- uv.sleep(sec*1e3)
-end
-
-local term = {}
-package.loaded['term.core'] = term
-function term.isatty(_)
- return uv.guess_handle(1) == 'tty'
-end
-
-local lfs = {}
-package.loaded['lfs'] = lfs
-
-function lfs.attributes(path, attr)
- if attr == 'mode' then
- local stat = uv.fs_stat(path)
- return stat and stat.type or ''
- else
- error('not implemented')
- end
-end
-
-function lfs.currentdir()
- return uv.cwd()
-end
-
-function lfs.chdir(dir)
- local status, err = pcall(uv.chdir, dir)
- if status then
- return true
- else
- return nil, err
- end
-end
-
-function lfs.dir(path)
- local fs = uv.fs_scandir(path)
- return function()
- if not fs then
- return
- end
- return uv.fs_scandir_next(fs)
- end
-end
-
-require 'busted.runner'({ standalone = false })
diff --git a/test/lua_runner.lua b/test/lua_runner.lua
@@ -0,0 +1,83 @@
+local platform = vim.uv.os_uname()
+local deps_install_dir = table.remove(_G.arg, 1)
+local subcommand = table.remove(_G.arg, 1)
+local suffix = (platform and platform.sysname:lower():find'windows') and '.dll' or '.so'
+package.path = deps_install_dir.."/share/lua/5.1/?.lua;"..deps_install_dir.."/share/lua/5.1/?/init.lua;"..package.path
+package.cpath = deps_install_dir.."/lib/lua/5.1/?"..suffix..";"..package.cpath;
+
+local uv = vim.uv
+
+-- we use busted and luacheck and their lua dependencies
+-- But installing their binary dependencies with luarocks is very
+-- slow, replace them with vim.uv wrappers
+
+local system = {}
+package.loaded['system.core'] = system
+function system.monotime()
+ uv.update_time()
+ return uv.now()*1e-3
+end
+function system.gettime()
+ local sec, usec = uv.gettimeofday()
+ return sec+usec*1e-6
+end
+function system.sleep(sec)
+ uv.sleep(sec*1e3)
+end
+
+local term = {}
+package.loaded['term.core'] = term
+function term.isatty(_)
+ return uv.guess_handle(1) == 'tty'
+end
+
+local lfs = {_VERSION = 'fake'}
+package.loaded['lfs'] = lfs
+
+function lfs.attributes(path, attr)
+ local stat = uv.fs_stat(path)
+ if attr == 'mode' then
+ return stat and stat.type or ''
+ elseif attr == 'modification' then
+ if not stat then return nil end
+ local mtime = stat.mtime
+ return mtime.sec + mtime.nsec*1e-9
+ else
+ error('not implemented')
+ end
+end
+
+function lfs.currentdir()
+ return uv.cwd()
+end
+
+function lfs.chdir(dir)
+ local status, err = pcall(uv.chdir, dir)
+ if status then
+ return true
+ else
+ return nil, err
+ end
+end
+
+function lfs.dir(path)
+ local fs = uv.fs_scandir(path)
+ return function()
+ if not fs then
+ return
+ end
+ return uv.fs_scandir_next(fs)
+ end
+end
+
+function lfs.mkdir(dir)
+ return uv.fs_mkdir(dir, 493) -- octal 755
+end
+
+if subcommand == "busted" then
+ require 'busted.runner'({ standalone = false })
+elseif subcommand == "luacheck" then
+ require 'luacheck.main'
+else
+ error 'unknown subcommand'
+end