2

I am working on a tool, using clang's LibTooling library, and I want it to parse the entire build system.

Code I've been trying to call clang with:

int main(int argc, const char** argv) {
  clang::tooling::CommonOptionParser parser(argc, argv, OptionCategory);
  clang::tooling::ClangTool tool(parser.getCompilations(),
                                 parser.getSourcePathList());

  return tool.run(
      clang::tooling::newFrontendActionFactory<tlx::TemplateAction>().get());
}

The build system I want to run my tool on uses CMake, so I can easily export the compile_commands.json compilation database.

But I dont know how can I pass it to my tool.

I've tried: ./myTool <path>/compile_commands.json where I get an error skipping <path>/compile_commands.json. Compile command not found.

I also tried: ./myTool -p <path to build> <path to source>/main.cppwhich works but than I have to list every translation unit. The point of having a compilation database is that it contains every translation unit with the command that it was compiled with.

Is there a way to just simply pass the compile_commands.json as an argument to my tool and let the CommonOptionParser parse it?

Bako
  • 313
  • 1
  • 15
  • Did you get an answer to this? I know it is 5 years too late, but facing the same problem and haven't found a clear way to do this – gPats Oct 31 '20 at 14:45
  • @gPats yes, you can just pass the absolute path to the compile_commands.json file as a parameter when invoking the tool. Let me know if you need a detailed example – Bako Oct 31 '20 at 17:55

0 Answers0