clang 19.0.0git
ExpandResponseFilesCompilationDatabase.cpp
Go to the documentation of this file.
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
11#include "llvm/ADT/StringRef.h"
12#include "llvm/Support/CommandLine.h"
13#include "llvm/Support/ConvertUTF.h"
14#include "llvm/Support/ErrorOr.h"
15#include "llvm/Support/MemoryBuffer.h"
16#include "llvm/Support/Path.h"
17#include "llvm/Support/StringSaver.h"
18#include "llvm/TargetParser/Host.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22namespace tooling {
23namespace {
24
25class ExpandResponseFilesDatabase : public CompilationDatabase {
26public:
27 ExpandResponseFilesDatabase(
28 std::unique_ptr<CompilationDatabase> Base,
29 llvm::cl::TokenizerCallback Tokenizer,
31 : Base(std::move(Base)), Tokenizer(Tokenizer), FS(std::move(FS)) {
32 assert(this->Base != nullptr);
33 assert(this->Tokenizer != nullptr);
34 assert(this->FS != nullptr);
35 }
36
37 std::vector<std::string> getAllFiles() const override {
38 return Base->getAllFiles();
39 }
40
41 std::vector<CompileCommand>
42 getCompileCommands(StringRef FilePath) const override {
43 return expand(Base->getCompileCommands(FilePath));
44 }
45
46 std::vector<CompileCommand> getAllCompileCommands() const override {
47 return expand(Base->getAllCompileCommands());
48 }
49
50private:
51 std::vector<CompileCommand> expand(std::vector<CompileCommand> Cmds) const {
52 for (auto &Cmd : Cmds)
53 tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
54 Tokenizer, *FS);
55 return Cmds;
56 }
57
58private:
59 std::unique_ptr<CompilationDatabase> Base;
60 llvm::cl::TokenizerCallback Tokenizer;
62};
63
64} // namespace
65
66std::unique_ptr<CompilationDatabase>
67expandResponseFiles(std::unique_ptr<CompilationDatabase> Base,
69 auto Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
70 ? llvm::cl::TokenizeWindowsCommandLine
71 : llvm::cl::TokenizeGNUCommandLine;
72 return std::make_unique<ExpandResponseFilesDatabase>(
73 std::move(Base), Tokenizer, std::move(FS));
74}
75
76} // namespace tooling
77} // namespace clang
CompileCommand Cmd
std::unique_ptr< CompilationDatabase > expandResponseFiles(std::unique_ptr< CompilationDatabase > Base, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
Returns a wrapped CompilationDatabase that will expand all rsp(response) files on commandline returne...
void addExpandedResponseFiles(std::vector< std::string > &CommandLine, llvm::StringRef WorkingDir, llvm::cl::TokenizerCallback Tokenizer, llvm::vfs::FileSystem &FS)
Helper function that expands response files in command line.
Definition: Tooling.cpp:308
The JSON file list parser is used to communicate input to InstallAPI.
Definition: Format.h:5433