Path: blob/main/contrib/llvm-project/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
35233 views
//===- ExpandResponseFileCompilationDataBase.cpp --------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "clang/Tooling/CompilationDatabase.h"9#include "clang/Tooling/Tooling.h"10#include "llvm/ADT/StringRef.h"11#include "llvm/Support/CommandLine.h"12#include "llvm/Support/ConvertUTF.h"13#include "llvm/Support/ErrorOr.h"14#include "llvm/Support/MemoryBuffer.h"15#include "llvm/Support/Path.h"16#include "llvm/Support/StringSaver.h"17#include "llvm/TargetParser/Host.h"18#include "llvm/TargetParser/Triple.h"1920namespace clang {21namespace tooling {22namespace {2324class ExpandResponseFilesDatabase : public CompilationDatabase {25public:26ExpandResponseFilesDatabase(27std::unique_ptr<CompilationDatabase> Base,28llvm::cl::TokenizerCallback Tokenizer,29llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)30: Base(std::move(Base)), Tokenizer(Tokenizer), FS(std::move(FS)) {31assert(this->Base != nullptr);32assert(this->Tokenizer != nullptr);33assert(this->FS != nullptr);34}3536std::vector<std::string> getAllFiles() const override {37return Base->getAllFiles();38}3940std::vector<CompileCommand>41getCompileCommands(StringRef FilePath) const override {42return expand(Base->getCompileCommands(FilePath));43}4445std::vector<CompileCommand> getAllCompileCommands() const override {46return expand(Base->getAllCompileCommands());47}4849private:50std::vector<CompileCommand> expand(std::vector<CompileCommand> Cmds) const {51for (auto &Cmd : Cmds)52tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,53Tokenizer, *FS);54return Cmds;55}5657private:58std::unique_ptr<CompilationDatabase> Base;59llvm::cl::TokenizerCallback Tokenizer;60llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;61};6263} // namespace6465std::unique_ptr<CompilationDatabase>66expandResponseFiles(std::unique_ptr<CompilationDatabase> Base,67llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {68auto Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()69? llvm::cl::TokenizeWindowsCommandLine70: llvm::cl::TokenizeGNUCommandLine;71return std::make_unique<ExpandResponseFilesDatabase>(72std::move(Base), Tokenizer, std::move(FS));73}7475} // namespace tooling76} // namespace clang777879