Skip to content

Commit 4f6026a

Browse files
Generate folders for compilecommands on action (#2666)
1 parent 60967ec commit 4f6026a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

modules/compilecommands/_preload.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ newaction {
8888
elseif f ~= 0 then
8989
printf("Generated %s...", path.getrelative(os.getcwd(), output_path))
9090
end
91+
92+
-- clangd relies on the "directory" entries in compile_commands.json to exist in order to properly
93+
-- resolve relative paths. This is to ensure that the compilecommands action generates them.
94+
local paths_to_generate = {}
95+
for _, cmd in ipairs(all_commands) do
96+
local dir = cmd.directory
97+
if dir and not os.isdir(dir) then
98+
paths_to_generate[dir] = true
99+
end
100+
end
101+
102+
for dir, _ in pairs(paths_to_generate) do
103+
local ok, err = os.mkdir(dir)
104+
if not ok then
105+
error(err, 0)
106+
end
107+
end
91108
end
92109
}
93110

0 commit comments

Comments
 (0)