aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-02-28 11:32:25 +0100
committerGitHub <noreply@github.com>2024-02-28 11:32:25 +0100
commitc538ec85220aea11bbdb52028aa335787e9e4f42 (patch)
tree138b11577f1896643fb593481a41c9b841be6362 /src/nvim/generators
parent07b4b7524fc7faefb69e5c94d2512eb0807f0593 (diff)
parentde5cf09cf98e20d8d3296ad6933ff2741acf83f7 (diff)
downloadrneovim-c538ec85220aea11bbdb52028aa335787e9e4f42.tar.gz
rneovim-c538ec85220aea11bbdb52028aa335787e9e4f42.tar.bz2
rneovim-c538ec85220aea11bbdb52028aa335787e9e4f42.zip
Merge pull request #27643 from bfredl/metadata2
refactor(metadata): generate all metadata in lua
Diffstat (limited to 'src/nvim/generators')
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua94
-rw-r--r--src/nvim/generators/gen_api_ui_events.lua4
-rw-r--r--src/nvim/generators/nvim_version.lua.in9
-rw-r--r--src/nvim/generators/preload.lua3
4 files changed, 92 insertions, 18 deletions
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index 56331e4162..78a83445af 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -2,15 +2,18 @@ local mpack = vim.mpack
local hashy = require 'generators.hashy'
-assert(#arg >= 5)
+local pre_args = 7
+assert(#arg >= pre_args)
-- output h file with generated dispatch functions (dispatch_wrappers.generated.h)
local dispatch_outputf = arg[1]
--- output h file with packed metadata (funcs_metadata.generated.h)
-local funcs_metadata_outputf = arg[2]
+-- output h file with packed metadata (api_metadata.generated.h)
+local api_metadata_outputf = arg[2]
-- output metadata mpack file, for use by other build scripts (api_metadata.mpack)
local mpack_outputf = arg[3]
local lua_c_bindings_outputf = arg[4] -- lua_api_c_bindings.generated.c
local keysets_outputf = arg[5] -- keysets_defs.generated.h
+local ui_metadata_inputf = arg[6] -- ui events metadata
+local git_version_inputf = arg[7] -- git version header
local functions = {}
@@ -96,8 +99,10 @@ local function add_keyset(val)
})
end
+local ui_options_text = nil
+
-- read each input file, parse and append to the api metadata
-for i = 6, #arg do
+for i = pre_args + 1, #arg do
local full_path = arg[i]
local parts = {}
for part in string.gmatch(full_path, '[^/]+') do
@@ -107,17 +112,18 @@ for i = 6, #arg do
local input = assert(io.open(full_path, 'rb'))
- local tmp = c_grammar.grammar:match(input:read('*all'))
+ local text = input:read('*all')
+ local tmp = c_grammar.grammar:match(text)
for j = 1, #tmp do
local val = tmp[j]
- if val[1] ~= 'empty' then
- if val.keyset_name then
- add_keyset(val)
- else
- add_function(val)
- end
+ if val.keyset_name then
+ add_keyset(val)
+ elseif val.name then
+ add_function(val)
end
end
+
+ ui_options_text = ui_options_text or string.match(text, 'ui_ext_names%[][^{]+{([^}]+)}')
input:close()
end
@@ -218,13 +224,71 @@ for _, f in ipairs(functions) do
end
end
+local ui_options = { 'rgb' }
+for x in string.gmatch(ui_options_text, '"([a-z][a-z_]+)"') do
+ table.insert(ui_options, x)
+end
+
+local version = require 'nvim_version'
+local git_version = io.open(git_version_inputf):read '*a'
+local version_build = string.match(git_version, '#define NVIM_VERSION_BUILD "([^"]+)"') or vim.NIL
+
-- serialize the API metadata using msgpack and embed into the resulting
-- binary for easy querying by clients
-local funcs_metadata_output = assert(io.open(funcs_metadata_outputf, 'wb'))
-local packed = mpack.encode(exported_functions)
+local api_metadata_output = assert(io.open(api_metadata_outputf, 'wb'))
+local pieces = {}
+
+-- Naively using mpack.encode({foo=x, bar=y}) will make the build
+-- "non-reproducible". Emit maps directly as FIXDICT(2) "foo" x "bar" y instead
+local function fixdict(num)
+ if num > 15 then
+ error 'implement more dict codes'
+ end
+ table.insert(pieces, string.char(128 + num))
+end
+local function put(item, item2)
+ table.insert(pieces, mpack.encode(item))
+ if item2 ~= nil then
+ table.insert(pieces, mpack.encode(item2))
+ end
+end
+
+fixdict(6)
+
+put('version')
+fixdict(1 + #version)
+for _, item in ipairs(version) do
+ -- NB: all items are mandatory. But any error will be less confusing
+ -- with placholder vim.NIL (than invalid mpack data)
+ put(item[1], item[2] or vim.NIL)
+end
+put('build', version_build)
+
+put('functions', exported_functions)
+put('ui_events')
+table.insert(pieces, io.open(ui_metadata_inputf, 'rb'):read('*all'))
+put('ui_options', ui_options)
+
+put('error_types')
+fixdict(2)
+put('Exception', { id = 0 })
+put('Validation', { id = 1 })
+
+put('types')
+local types =
+ { { 'Buffer', 'nvim_buf_' }, { 'Window', 'nvim_win_' }, { 'Tabpage', 'nvim_tabpage_' } }
+fixdict(#types)
+for i, item in ipairs(types) do
+ put(item[1])
+ fixdict(2)
+ put('id', i - 1)
+ put('prefix', item[2])
+end
+
+local packed = table.concat(pieces)
local dump_bin_array = require('generators.dump_bin_array')
-dump_bin_array(funcs_metadata_output, 'funcs_metadata', packed)
-funcs_metadata_output:close()
+dump_bin_array(api_metadata_output, 'packed_api_metadata', packed)
+api_metadata_output:close()
-- start building the dispatch wrapper output
local output = assert(io.open(dispatch_outputf, 'wb'))
diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua
index 697626b793..a4f59c7209 100644
--- a/src/nvim/generators/gen_api_ui_events.lua
+++ b/src/nvim/generators/gen_api_ui_events.lua
@@ -204,7 +204,5 @@ for _, ev in ipairs(events) do
end
end
-local packed = mpack.encode(exported_events)
-local dump_bin_array = require('generators.dump_bin_array')
-dump_bin_array(metadata_output, 'ui_events_metadata', packed)
+metadata_output:write(mpack.encode(exported_events))
metadata_output:close()
diff --git a/src/nvim/generators/nvim_version.lua.in b/src/nvim/generators/nvim_version.lua.in
new file mode 100644
index 0000000000..d0dbf77922
--- /dev/null
+++ b/src/nvim/generators/nvim_version.lua.in
@@ -0,0 +1,9 @@
+return {
+ {"major", ${NVIM_VERSION_MAJOR}},
+ {"minor", ${NVIM_VERSION_MINOR}},
+ {"patch", ${NVIM_VERSION_PATCH}},
+ {"prerelease", "$NVIM_VERSION_PRERELEASE" ~= ""},
+ {"api_level", ${NVIM_API_LEVEL}},
+ {"api_compatible", ${NVIM_API_LEVEL_COMPAT}},
+ {"api_prerelease", ${NVIM_API_PRERELEASE}},
+}
diff --git a/src/nvim/generators/preload.lua b/src/nvim/generators/preload.lua
index 721d2880b8..e14671074c 100644
--- a/src/nvim/generators/preload.lua
+++ b/src/nvim/generators/preload.lua
@@ -1,10 +1,13 @@
local srcdir = table.remove(arg, 1)
local nlualib = table.remove(arg, 1)
+local gendir = table.remove(arg, 1)
package.path = srcdir .. '/src/nvim/?.lua;' .. srcdir .. '/runtime/lua/?.lua;' .. package.path
+package.path = gendir .. '/?.lua;' .. package.path
_G.vim = require 'vim.shared'
_G.vim.inspect = require 'vim.inspect'
package.cpath = package.cpath .. ';' .. nlualib
require 'nlua0'
+vim.NIL = vim.mpack.NIL -- WOW BOB WOW
arg[0] = table.remove(arg, 1)
return loadfile(arg[0])()