[clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

This patch exposes `InputInfo` in `Job` instead of plain filenames. This is useful in a follow-up patch that uses this to recognize `-cc1` commands interesting for Clang tooling.

Depends on D106787.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D106788
This commit is contained in:
Jan Svoboda 2021-07-26 13:30:58 +02:00
parent 60426f33b1
commit b76c7c6faf
3 changed files with 13 additions and 13 deletions

View File

@ -10,6 +10,7 @@
#define LLVM_CLANG_DRIVER_JOB_H
#include "clang/Basic/LLVM.h"
#include "clang/Driver/InputInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
@ -119,8 +120,8 @@ class Command {
/// argument, which will be the executable).
llvm::opt::ArgStringList Arguments;
/// The list of program arguments which are inputs.
llvm::opt::ArgStringList InputFilenames;
/// The list of program inputs.
std::vector<InputInfo> InputInfoList;
/// The list of program arguments which are outputs. May be empty.
std::vector<std::string> OutputFilenames;
@ -207,9 +208,7 @@ public:
const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
const llvm::opt::ArgStringList &getInputFilenames() const {
return InputFilenames;
}
const std::vector<InputInfo> &getInputInfos() const { return InputInfoList; }
const std::vector<std::string> &getOutputFilenames() const {
return OutputFilenames;

View File

@ -43,7 +43,7 @@ Command::Command(const Action &Source, const Tool &Creator,
Executable(Executable), Arguments(Arguments) {
for (const auto &II : Inputs)
if (II.isFilename())
InputFilenames.push_back(II.getFilename());
InputInfoList.push_back(II);
for (const auto &II : Outputs)
if (II.isFilename())
OutputFilenames.push_back(II.getFilename());
@ -237,9 +237,10 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
}
}
auto Found = llvm::find_if(InputFilenames,
[&Arg](StringRef IF) { return IF == Arg; });
if (Found != InputFilenames.end() &&
auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
return II.getFilename() == Arg;
});
if (Found != InputInfoList.end() &&
(i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
// Replace the input file name with the crashinfo's file name.
OS << ' ';
@ -302,8 +303,8 @@ void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
void Command::PrintFileNames() const {
if (PrintInputFilenames) {
for (const char *Arg : InputFilenames)
llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
for (const auto &Arg : InputInfoList)
llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
llvm::outs().flush();
}
}

View File

@ -321,13 +321,13 @@ TEST(ToolChainTest, CommandOutput) {
const JobList &Jobs = CC->getJobs();
const auto &CmdCompile = Jobs.getJobs().front();
const auto &InFile = CmdCompile->getInputFilenames().front();
const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
EXPECT_STREQ(InFile, "foo.cpp");
auto ObjFile = CmdCompile->getOutputFilenames().front();
EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
const auto &CmdLink = Jobs.getJobs().back();
const auto LinkInFile = CmdLink->getInputFilenames().front();
const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
EXPECT_EQ(ObjFile, LinkInFile);
auto ExeFile = CmdLink->getOutputFilenames().front();
EXPECT_EQ("a.out", ExeFile);