Files
meowc/lib/compdb.ml
T
sneeker d4e210f33c 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.
2022-06-17 19:15:48 +00:00

20 lines
750 B
OCaml

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))