1//===- ExpandResponseFileCompilationDataBase.cpp --------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "clang/Tooling/CompilationDatabase.h"
10#include "clang/Tooling/Tooling.h"
11#include "llvm/ADT/StringRef.h"
12#include "llvm/Support/CommandLine.h"
13#include "llvm/Support/ConvertUTF.h"
14#include "llvm/TargetParser/Host.h"
15#include "llvm/TargetParser/Triple.h"
16
17namespace clang {
18namespace tooling {
19namespace {
20
21class ExpandResponseFilesDatabase : public CompilationDatabase {
22public:
23 ExpandResponseFilesDatabase(
24 std::unique_ptr<CompilationDatabase> Base,
25 llvm::cl::TokenizerCallback Tokenizer,
26 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
27 : Base(std::move(Base)), Tokenizer(Tokenizer), FS(std::move(FS)) {
28 assert(this->Base != nullptr);
29 assert(this->Tokenizer != nullptr);
30 assert(this->FS != nullptr);
31 }
32
33 std::vector<std::string> getAllFiles() const override {
34 return Base->getAllFiles();
35 }
36
37 std::vector<CompileCommand>
38 getCompileCommands(StringRef FilePath) const override {
39 return expand(Cmds: Base->getCompileCommands(FilePath));
40 }
41
42 std::vector<CompileCommand> getAllCompileCommands() const override {
43 return expand(Cmds: Base->getAllCompileCommands());
44 }
45
46private:
47 std::vector<CompileCommand> expand(std::vector<CompileCommand> Cmds) const {
48 for (auto &Cmd : Cmds)
49 tooling::addExpandedResponseFiles(CommandLine&: Cmd.CommandLine, WorkingDir: Cmd.Directory,
50 Tokenizer, FS&: *FS);
51 return Cmds;
52 }
53
54private:
55 std::unique_ptr<CompilationDatabase> Base;
56 llvm::cl::TokenizerCallback Tokenizer;
57 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
58};
59
60} // namespace
61
62std::unique_ptr<CompilationDatabase>
63expandResponseFiles(std::unique_ptr<CompilationDatabase> Base,
64 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
65 auto Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
66 ? llvm::cl::TokenizeWindowsCommandLine
67 : llvm::cl::TokenizeGNUCommandLine;
68 return std::make_unique<ExpandResponseFilesDatabase>(
69 args: std::move(Base), args&: Tokenizer, args: std::move(FS));
70}
71
72} // namespace tooling
73} // namespace clang
74

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp