ClangSwift
ClangSwift copied to clipboard
Add CompilationDatabase and CompileCommand.
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: URLis 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_testsfiles as a single library. - the
.build/build.input_tests/compile_commands.jsonwill be made.
- It will build the sources in the