2023-06-03 03:06:00 -07:00
|
|
|
local platform = vim.uv.os_uname()
|
2023-09-05 02:49:08 -07:00
|
|
|
local deps_install_dir = table.remove(_G.arg, 1)
|
|
|
|
local subcommand = table.remove(_G.arg, 1)
|
2023-05-21 11:57:39 -07:00
|
|
|
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;
|
2023-01-31 15:35:04 -07:00
|
|
|
|
2023-09-02 15:38:10 -07:00
|
|
|
local uv = vim.uv
|
|
|
|
|
2023-09-05 02:49:08 -07:00
|
|
|
-- 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
|
|
|
|
|
2023-09-02 15:38:10 -07:00
|
|
|
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
|
|
|
|
|
2023-09-05 02:49:08 -07:00
|
|
|
local lfs = {_VERSION = 'fake'}
|
2023-09-02 15:38:10 -07:00
|
|
|
package.loaded['lfs'] = lfs
|
|
|
|
|
|
|
|
function lfs.attributes(path, attr)
|
2023-09-05 02:49:08 -07:00
|
|
|
local stat = uv.fs_stat(path)
|
2023-09-02 15:38:10 -07:00
|
|
|
if attr == 'mode' then
|
|
|
|
return stat and stat.type or ''
|
2023-09-05 02:49:08 -07:00
|
|
|
elseif attr == 'modification' then
|
|
|
|
if not stat then return nil end
|
|
|
|
local mtime = stat.mtime
|
|
|
|
return mtime.sec + mtime.nsec*1e-9
|
2023-09-02 15:38:10 -07:00
|
|
|
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
|
|
|
|
|
2023-09-05 02:49:08 -07:00
|
|
|
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
|