fix(tests): use correct include path for unittest

Copy whatever was made to work for generated headers:

(1) we need to consider all cmake targets not just main_lib
(2) we need to add the sysroot for macOS
This commit is contained in:
bfredl
2025-05-22 11:22:29 +02:00
parent c81af9428c
commit 2d4b028d02
6 changed files with 23 additions and 2 deletions

View File

@ -408,6 +408,7 @@ pub fn test_config(b: *std.Build, gen_dir: LazyPath) ![]u8 {
\\local M = {{}} \\local M = {{}}
\\ \\
\\M.include_paths = {{}} \\M.include_paths = {{}}
\\M.apple_sysroot = ""
\\M.translations_enabled = "$ENABLE_TRANSLATIONS" == "ON" \\M.translations_enabled = "$ENABLE_TRANSLATIONS" == "ON"
\\M.is_asan = "$ENABLE_ASAN_UBSAN" == "ON" \\M.is_asan = "$ENABLE_ASAN_UBSAN" == "ON"
\\M.is_zig_build = true \\M.is_zig_build = true

View File

@ -481,11 +481,13 @@ foreach(target ${targets})
message(STATUS "${target} props '${prop}'") message(STATUS "${target} props '${prop}'")
foreach(gen_include ${prop}) foreach(gen_include ${prop})
list(APPEND gen_cflags "-I${gen_include}") list(APPEND gen_cflags "-I${gen_include}")
list(APPEND TEST_INCLUDE_DIRS "${gen_include}")
endforeach() endforeach()
endif() endif()
endforeach() endforeach()
list(REMOVE_DUPLICATES gen_cflags) list(REMOVE_DUPLICATES gen_cflags)
list(REMOVE_DUPLICATES TEST_INCLUDE_DIRS)
if(APPLE AND CMAKE_OSX_SYSROOT) if(APPLE AND CMAKE_OSX_SYSROOT)
list(APPEND gen_cflags "-isysroot" "${CMAKE_OSX_SYSROOT}") list(APPEND gen_cflags "-isysroot" "${CMAKE_OSX_SYSROOT}")

View File

@ -1,6 +1,6 @@
add_subdirectory(functional/fixtures) # compile test programs add_subdirectory(functional/fixtures) # compile test programs
get_target_property(TEST_INCLUDE_DIRS main_lib INTERFACE_INCLUDE_DIRECTORIES) get_directory_property(TEST_INCLUDE_DIRS DIRECTORY ${PROJECT_SOURCE_DIR}/src/nvim DEFINITION TEST_INCLUDE_DIRS)
set(TEST_OPTIONS set(TEST_OPTIONS
-D BUILD_DIR=${CMAKE_BINARY_DIR} -D BUILD_DIR=${CMAKE_BINARY_DIR}

View File

@ -4,6 +4,7 @@ M.include_paths = {}
for p in ("${TEST_INCLUDE_DIRS}" .. ";"):gmatch("[^;]+") do for p in ("${TEST_INCLUDE_DIRS}" .. ";"):gmatch("[^;]+") do
table.insert(M.include_paths, p) table.insert(M.include_paths, p)
end end
M.apple_sysroot = "${CMAKE_OSX_SYSROOT}"
M.translations_enabled = "${ENABLE_TRANSLATIONS}" == "ON" M.translations_enabled = "${ENABLE_TRANSLATIONS}" == "ON"
M.is_asan = "${ENABLE_ASAN_UBSAN}" == "ON" M.is_asan = "${ENABLE_ASAN_UBSAN}" == "ON"

View File

@ -146,13 +146,20 @@ end
--- @param ... string --- @param ... string
function Gcc:add_to_include_path(...) function Gcc:add_to_include_path(...)
local ef = self.preprocessor_extra_flags
for i = 1, select('#', ...) do for i = 1, select('#', ...) do
local path = select(i, ...) local path = select(i, ...)
local ef = self.preprocessor_extra_flags
ef[#ef + 1] = '-I' .. path ef[#ef + 1] = '-I' .. path
end end
end end
function Gcc:add_apple_sysroot(sysroot)
local ef = self.preprocessor_extra_flags
table.insert(ef, '-isysroot')
table.insert(ef, sysroot)
end
-- returns a list of the headers files upon which this file relies -- returns a list of the headers files upon which this file relies
--- @param hdr string --- @param hdr string
--- @return string[]? --- @return string[]?
@ -278,4 +285,9 @@ function M.add_to_include_path(...)
return cc:add_to_include_path(...) return cc:add_to_include_path(...)
end end
--- @param ... string
function M.add_apple_sysroot(...)
return cc:add_apple_sysroot(...)
end
return M return M

View File

@ -19,6 +19,11 @@ for _, p in ipairs(paths.include_paths) do
Preprocess.add_to_include_path(p) Preprocess.add_to_include_path(p)
end end
-- add some nonstandard header locations
if paths.apple_sysroot ~= '' then
Preprocess.add_apple_sysroot(paths.apple_sysroot)
end
local child_pid = nil --- @type integer? local child_pid = nil --- @type integer?
--- @generic F: function --- @generic F: function
--- @param func F --- @param func F