ClangSwift icon indicating copy to clipboard operation
ClangSwift copied to clipboard

Add CompilationDatabase and CompileCommand.

Open juhwangKim opened this issue 6 years ago • 0 comments

Summary

This PR adds the CompilationDatabase and CompileCommand functions of the clang. It is used to load build information from the compile_commands.json generated by the cmake project.

The CompilationDatabase tries to load a compile_commands.json from a given directory path string. After initialization, the CompileCommand can be retrieved by a variable or functions.

The CompileCommand contains filename and argument for a single source, so the TranslationUnit can be initialized with it.

do {
  let db = try CompilationDatabase(directory: "/dir/contains/compile_commands.json/")
  let command = db.compileCommands[0]
  let tu = try TranslationUnit(compileCommand: command)
} catch { ... }
  • https://clang.llvm.org/doxygen/group__COMPILATIONDB.html

Others

  • ClangTests.swift
    • Add three test cases.
    • The var projectRoot: URL is added to find a project folder for the test from Xcode. I'm not sure this is a proper way.
  • utils/make-compile_commands.swift, input_tests/CMakeLists.txt
    • It will build the sources in the input_tests files as a single library.
    • the .build/build.input_tests/compile_commands.json will be made.

juhwangKim avatar Mar 25 '19 08:03 juhwangKim