feat(compdb): write compile_commands.json for clangd

One entry per translation unit with directory, arguments and file, taken from
the compile actions already in the graph.
This commit is contained in:
milner committed 2022-06-17 19:15:48 +00:00
1 parent b6a41fda7b
commit 597c5b0d75
1 file changed
+19
+19
View File
@@ -0,0 +1,19 @@
let render (b : Build.t) =
let dir = Sys.getcwd () in
let entries =
Array.to_list b.g.Graph.nodes
|> List.filter (fun (n : Graph.node) -> n.tag = "cc" || n.tag = "c++")
|> List.map (fun (n : Graph.node) ->
Printf.sprintf
" {\n \"directory\": %s,\n \"file\": %s,\n \"output\": %s,\n \"arguments\": %s\n }"
(Json.str dir) (Json.str n.label)
(Json.str (List.hd n.outs))
(Json.list Json.str (Array.to_list n.cmd)))
in
"[\n" ^ String.concat ",\n" entries ^ "\n]\n"
let write b path =
Fs.write path (render b);
List.length
(List.filter (fun (n : Graph.node) -> n.Graph.tag = "cc" || n.Graph.tag = "c++")
(Array.to_list b.Build.g.Graph.nodes))