[PATCH] D102149: [analyzer][ctu] Allow loading invocation list from a compilation database automatically detected from the ctu-dir

Ella Ma via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 19 07:54:45 PDT 2021


OikawaKirie added a comment.

In D102149#2768541 <https://reviews.llvm.org/D102149#2768541>, @martong wrote:

> Thank you for the patch!
>
> Though, the idea is nice, there is a serious technical obstacle here: we cannot use the clangTooling lib as a dependency of the CTU lib because that would introduce a circular dependency. Actually, this was the reason for introducing the invocation list yaml file; we could not use the compilation database implementation from tooling (https://reviews.llvm.org/D75665?id=260238#inline-722328).

According to my recent experiences on using clang-check, converting the compilation database to an invocation list is also an acceptable solution.
Currently, a better solution may be adding a tool to handle the conversion, just as what has been mentioned in the revision you presented. Although, it would be a very simple python script such as:

  a = dict()
  for i in json.load(open("/path/to/compile_commands.json")):
      a[os.path.abspath(os.path.join(i['directory'], i['file']))] = \
          (shlex.split(i['command']) if 'command' in i else i['arguments']) + \
          ['-Xclang', '-working-directory=' + i['directory']]
  print(yaml.dump(a));

If you agree with this idea, I will follow the way to create a tool for the conversion and drop this revision.

Actually, I am writing a makefile to schedule the ctu-index generation as well as analyzing the code with the clang-check tool. And the python script snippet presented above is just a part of my makefile.
Maybe I can add my makefile to as a part of the analyzer.



================
Comment at: clang/lib/CrossTU/CrossTranslationUnit.cpp:711-712
+
+      List.emplace_back("-Xclang");
+      List.emplace_back("-working-directory=" + CC.Directory);
+    }
----------------
The approach of converting a compilation database to an invocation list is just simply adding the `-working-directory` argument for the `"directory"` entry for each compile command object. Therefore, a script doing the conversion can make it simpler and easier to use.

The main reason why this patch is submitted is I previously do not know the `-working-directory` argument. Without this argument, it would be very difficult and complex to convert a compilation database to an invocation list.

If you agree that my approach of converting the database (presented in the for loop) is OK, I will continue with making a tool for the conversion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102149/new/

https://reviews.llvm.org/D102149



More information about the cfe-commits mailing list