From f30844008bdd313b03a19486159f571a067e68b9 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 3 Sep 2023 00:38:10 +0200 Subject: [PATCH] build: download busted from own neovim/deps repository Downloading the necessary files all at once instead of doing dependency handling with luarocks speeds up installation immensely. We speed up the process even more by using luv as a replacement for the C modules in the busted dependencies, which allows us to skip costly compilation times. Co-authored-by: bfredl --- CMakeLists.txt | 12 +++++++++ cmake/BuildLuarocks.cmake | 5 ---- cmake/Deps.cmake | 1 + src/nvim/lua/executor.c | 4 +-- test/busted_runner.lua | 57 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df9f1cfa85..c91821d843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -316,3 +316,15 @@ ExternalProject_Add(uncrustify EXCLUDE_FROM_ALL TRUE) include(BuildLuarocks) + +ExternalProject_Add(busted + URL https://github.com/neovim/deps/raw/41d2f1b92aef964c8cb86985768702571e190e96/opt/busted-2.1.1.tar.gz + URL_HASH SHA256=9b23efce883ad25a3fe140598a32ab89ecc73f4c3d998cb937293d88e5b4c645 + DOWNLOAD_NO_PROGRESS TRUE + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/busted + SOURCE_DIR ${DEPS_SHARE_DIR} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + EXCLUDE_FROM_ALL TRUE) +add_dependencies(test_deps busted) diff --git a/cmake/BuildLuarocks.cmake b/cmake/BuildLuarocks.cmake index c5e08d2d74..2dc493a59b 100644 --- a/cmake/BuildLuarocks.cmake +++ b/cmake/BuildLuarocks.cmake @@ -89,10 +89,8 @@ function(Download ROCK VER) endfunction() if(WIN32) - set(BUSTED_EXE "${DEPS_BIN_DIR}/busted.bat") set(LUACHECK_EXE "${DEPS_BIN_DIR}/luacheck.bat") else() - set(BUSTED_EXE "${DEPS_BIN_DIR}/busted") set(LUACHECK_EXE "${DEPS_BIN_DIR}/luacheck") endif() @@ -100,9 +98,6 @@ add_custom_target(test_deps) Download(luacheck 1.1.0-1 ${LUACHECK_EXE}) -Download(busted 2.1.1 ${BUSTED_EXE}) -add_dependencies(test_deps busted) - if(PREFER_LUA) Download(coxpcall 1.17.0-1) add_dependencies(test_deps coxpcall) diff --git a/cmake/Deps.cmake b/cmake/Deps.cmake index 69a950eb0d..e8dcbaa79d 100644 --- a/cmake/Deps.cmake +++ b/cmake/Deps.cmake @@ -1,6 +1,7 @@ set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/usr") set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin") set(DEPS_LIB_DIR "${DEPS_INSTALL_DIR}/lib") +set(DEPS_SHARE_DIR "${DEPS_INSTALL_DIR}/share/lua/5.1") set(DEPS_BUILD_DIR "${CMAKE_BINARY_DIR}/build") set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads") diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 4aaf4397f9..f2efd866f8 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -140,8 +140,8 @@ void nlua_error(lua_State *const lstate, const char *const msg) } if (in_script) { - os_errmsg(str); - os_errmsg("\n"); + fprintf(stderr, msg, (int)len, str); + fprintf(stderr, "\n"); } else { msg_ext_set_kind("lua_error"); semsg_multiline(msg, (int)len, str); diff --git a/test/busted_runner.lua b/test/busted_runner.lua index d6864c6492..8176292bcf 100644 --- a/test/busted_runner.lua +++ b/test/busted_runner.lua @@ -4,4 +4,61 @@ local suffix = (platform and platform.sysname:lower():find'windows') and '.dll' 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 })