summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.lua7
-rw-r--r--make.lua43
-rw-r--r--make/bootstrap.lua38
-rw-r--r--make/install.lua12
-rw-r--r--platform.lua63
-rw-r--r--test.lua9
6 files changed, 73 insertions, 99 deletions
diff --git a/main.lua b/main.lua
index 63341d7f..ce43bebe 100644
--- a/main.lua
+++ b/main.lua
@@ -1,8 +1,4 @@
-local currentPath = debug.getinfo(1, 'S').source:sub(2)
-local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
-rootPath = (rootPath == '' and '.' or rootPath)
-loadfile(rootPath .. '/platform.lua')('script')
-local fs = require 'bee.filesystem'
+local fs = require 'bee.filesystem'
local util = require 'utility'
local version = require 'version'
@@ -29,6 +25,7 @@ end
loadArgs()
+local rootPath = fs.exe_path():parent_path():parent_path():parent_path():string()
ROOT = fs.path(util.expandPath(rootPath))
LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log')
METAPATH = METAPATH and util.expandPath(METAPATH) or (ROOT:string() .. '/meta')
diff --git a/make.lua b/make.lua
index 638c6b90..f6a96e68 100644
--- a/make.lua
+++ b/make.lua
@@ -1,6 +1,12 @@
local lm = require 'luamake'
+local platform = require 'bee.platform'
+local fs = require 'bee.filesystem'
+local exe = platform.OS == 'Windows' and ".exe" or ""
-lm.EXE = "lua"
+lm.bindir = "bin/"..platform.OS
+
+lm.EXE_NAME = "lua-language-server"
+lm.EXE_DIR = lm.bindir
lm.EXE_RESOURCE = "../../make/lua-language-server.rc"
lm:import "3rd/bee.lua/make.lua"
@@ -14,23 +20,34 @@ lm:lua_dll 'lpeglabel' {
}
lm:build 'install' {
- '$luamake', 'lua', 'make/install.lua', lm.builddir,
+ '$luamake', 'lua', 'make/install.lua',
+}
+
+lm:copy "copy_bootstrap" {
+ input = "make/bootstrap.lua",
+ output = lm.bindir.."/main.lua",
+}
+
+lm:build "bee-test" {
+ lm.bindir.."/"..lm.EXE_NAME..exe, "3rd/bee.lua/test/test.lua",
+ pool = "console",
deps = {
- 'lua',
- 'lpeglabel',
- 'bee',
- }
+ lm.EXE_NAME,
+ "copy_bootstrap"
+ },
}
-local fs = require 'bee.filesystem'
-local pf = require 'bee.platform'
-local exe = pf.OS == 'Windows' and ".exe" or ""
-lm:build 'unittest' {
- fs.path 'bin' / pf.OS / ('lua-language-server' .. exe), 'test.lua', '-E',
+lm:build 'unit-test' {
+ lm.bindir.."/"..lm.EXE_NAME..exe, 'test.lua',
pool = "console",
deps = {
- 'install',
+ "bee-test",
+ "lpeglabel",
}
}
-lm:default 'unittest'
+lm:default {
+ "bee-test",
+ "unit-test",
+ "install",
+}
diff --git a/make/bootstrap.lua b/make/bootstrap.lua
new file mode 100644
index 00000000..2bbd64f0
--- /dev/null
+++ b/make/bootstrap.lua
@@ -0,0 +1,38 @@
+local i = 1
+while true do
+ if arg[i] == '-E' then
+ elseif arg[i] == '-e' then
+ i = i + 1
+ local expr = assert(arg[i], "'-e' needs argument")
+ assert(load(expr, "=(command line)"))()
+ else
+ break
+ end
+ i = i + 1
+end
+
+if arg[i] == nil then
+ return
+end
+
+for j = -1, #arg do
+ arg[j - i] = arg[j]
+end
+for j = #arg - i + 1, #arg do
+ arg[j] = nil
+end
+
+local root; do
+ local sep = package.config:sub(1,1)
+ local pattern = "["..sep.."][^"..sep.."]+"
+ root = package.cpath:match("(.+)"..pattern..pattern..pattern.."$")
+end
+
+local fs = require "bee.filesystem"
+fs.current_path(fs.path(root))
+
+package.path = table.concat({
+ root .. "/script/?.lua",
+ root .. "/script/?/init.lua",
+}, ";")
+assert(loadfile(arg[0]))(table.unpack(arg))
diff --git a/make/install.lua b/make/install.lua
index e8078770..c7f3b3a1 100644
--- a/make/install.lua
+++ b/make/install.lua
@@ -1,20 +1,8 @@
-local builddir = ...
local fs = require 'bee.filesystem'
local pf = require 'bee.platform'
-
local CWD = fs.current_path()
local output = CWD / 'bin' / pf.OS
-local bindir = CWD / builddir / 'bin'
-local exe = pf.OS == 'Windows' and ".exe" or ""
-local dll = pf.OS == 'Windows' and ".dll" or ".so"
-local OVERWRITE = fs.copy_options.overwrite_existing
-
-fs.create_directories(output)
-fs.copy_file(bindir / 'lpeglabel'..dll, output / 'lpeglabel'..dll, OVERWRITE)
-fs.copy_file(bindir / 'bee'..dll, output / 'bee'..dll, OVERWRITE)
-fs.copy_file(bindir / 'lua'..exe, output / 'lua-language-server'..exe, OVERWRITE)
if pf.OS == 'Windows' then
- fs.copy_file(bindir / 'lua54'..dll, output / 'lua54'..dll, OVERWRITE)
require 'msvc'.copy_vcrt('x64', output)
end
diff --git a/platform.lua b/platform.lua
deleted file mode 100644
index 85a948fa..00000000
--- a/platform.lua
+++ /dev/null
@@ -1,63 +0,0 @@
-local script = ...
-
-local function findExePath()
- local n = 0
- while arg[n-1] do
- n = n - 1
- end
- return arg[n]
-end
-
-local exePath = findExePath()
-local exeDir = exePath:match('(.+)[/\\][%w_.-]+$')
-local dll = package.cpath:match '[/\\]%?%.([a-z]+)'
-package.cpath = ('%s/?.%s;%s'):format(exeDir, dll, package.cpath)
-local bee = package.searchpath('bee', package.cpath)
-if not bee then
- error('Can not find bee.dll? cpath = ' .. tostring(package.cpath))
-end
-local ok, err = package.loadlib(bee, 'luaopen_bee_platform')
-if not ok then
- error(([[It doesn't seem to support your OS, please build it in your OS, see https://github.com/sumneko/vscode-lua/wiki/Build
-errorMsg: %s
-exePath: %s
-exeDir: %s
-dll: %s
-cpath: %s
-]]):format(
- err,
- exePath,
- exeDir,
- dll,
- package.cpath
-))
-end
-
-local currentPath = debug.getinfo(1, 'S').source:sub(2)
-local fs = require 'bee.filesystem'
-local rootPath = fs.path(currentPath):remove_filename():string()
-if dll == 'dll' then
- rootPath = rootPath:gsub('/', '\\')
- package.path = rootPath .. script .. '\\?.lua'
- .. ';' .. rootPath .. script .. '\\?\\init.lua'
-else
- rootPath = rootPath:gsub('\\', '/')
- package.path = rootPath .. script .. '/?.lua'
- .. ';' .. rootPath .. script .. '/?/init.lua'
-end
-
-package.searchers[2] = function (name)
- local filename, err = package.searchpath(name, package.path)
- if not filename then
- return err
- end
- local f = io.open(filename)
- local buf = f:read '*a'
- f:close()
- local relative = filename:sub(#rootPath + 1)
- local init, err = load(buf, '@' .. relative)
- if not init then
- return err
- end
- return init, filename
-end
diff --git a/test.lua b/test.lua
index 2f01bee6..21d10c5d 100644
--- a/test.lua
+++ b/test.lua
@@ -1,11 +1,8 @@
-local currentPath = debug.getinfo(1, 'S').source:sub(2)
-local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
-rootPath = rootPath == '' and '.' or rootPath
-loadfile(rootPath .. '/platform.lua')('script')
package.path = package.path
- .. ';' .. rootPath .. '/test/?.lua'
- .. ';' .. rootPath .. '/test/?/init.lua'
+ .. ';./test/?.lua'
+ .. ';./test/?/init.lua'
local fs = require 'bee.filesystem'
+local rootPath = fs.exe_path():parent_path():parent_path():parent_path():string()
ROOT = fs.path(rootPath)
TEST = true
DEVELOP = true