forked from OSchip/llvm-project
[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:
parent
60426f33b1
commit
b76c7c6faf
|
@ -10,6 +10,7 @@
|
||||||
#define LLVM_CLANG_DRIVER_JOB_H
|
#define LLVM_CLANG_DRIVER_JOB_H
|
||||||
|
|
||||||
#include "clang/Basic/LLVM.h"
|
#include "clang/Basic/LLVM.h"
|
||||||
|
#include "clang/Driver/InputInfo.h"
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/Optional.h"
|
#include "llvm/ADT/Optional.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
@ -119,8 +120,8 @@ class Command {
|
||||||
/// argument, which will be the executable).
|
/// argument, which will be the executable).
|
||||||
llvm::opt::ArgStringList Arguments;
|
llvm::opt::ArgStringList Arguments;
|
||||||
|
|
||||||
/// The list of program arguments which are inputs.
|
/// The list of program inputs.
|
||||||
llvm::opt::ArgStringList InputFilenames;
|
std::vector<InputInfo> InputInfoList;
|
||||||
|
|
||||||
/// The list of program arguments which are outputs. May be empty.
|
/// The list of program arguments which are outputs. May be empty.
|
||||||
std::vector<std::string> OutputFilenames;
|
std::vector<std::string> OutputFilenames;
|
||||||
|
@ -207,9 +208,7 @@ public:
|
||||||
|
|
||||||
const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
|
const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
|
||||||
|
|
||||||
const llvm::opt::ArgStringList &getInputFilenames() const {
|
const std::vector<InputInfo> &getInputInfos() const { return InputInfoList; }
|
||||||
return InputFilenames;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<std::string> &getOutputFilenames() const {
|
const std::vector<std::string> &getOutputFilenames() const {
|
||||||
return OutputFilenames;
|
return OutputFilenames;
|
||||||
|
|
|
@ -43,7 +43,7 @@ Command::Command(const Action &Source, const Tool &Creator,
|
||||||
Executable(Executable), Arguments(Arguments) {
|
Executable(Executable), Arguments(Arguments) {
|
||||||
for (const auto &II : Inputs)
|
for (const auto &II : Inputs)
|
||||||
if (II.isFilename())
|
if (II.isFilename())
|
||||||
InputFilenames.push_back(II.getFilename());
|
InputInfoList.push_back(II);
|
||||||
for (const auto &II : Outputs)
|
for (const auto &II : Outputs)
|
||||||
if (II.isFilename())
|
if (II.isFilename())
|
||||||
OutputFilenames.push_back(II.getFilename());
|
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,
|
auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
|
||||||
[&Arg](StringRef IF) { return IF == Arg; });
|
return II.getFilename() == Arg;
|
||||||
if (Found != InputFilenames.end() &&
|
});
|
||||||
|
if (Found != InputInfoList.end() &&
|
||||||
(i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
|
(i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
|
||||||
// Replace the input file name with the crashinfo's file name.
|
// Replace the input file name with the crashinfo's file name.
|
||||||
OS << ' ';
|
OS << ' ';
|
||||||
|
@ -302,8 +303,8 @@ void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
|
||||||
|
|
||||||
void Command::PrintFileNames() const {
|
void Command::PrintFileNames() const {
|
||||||
if (PrintInputFilenames) {
|
if (PrintInputFilenames) {
|
||||||
for (const char *Arg : InputFilenames)
|
for (const auto &Arg : InputInfoList)
|
||||||
llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
|
llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
|
||||||
llvm::outs().flush();
|
llvm::outs().flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,13 +321,13 @@ TEST(ToolChainTest, CommandOutput) {
|
||||||
const JobList &Jobs = CC->getJobs();
|
const JobList &Jobs = CC->getJobs();
|
||||||
|
|
||||||
const auto &CmdCompile = Jobs.getJobs().front();
|
const auto &CmdCompile = Jobs.getJobs().front();
|
||||||
const auto &InFile = CmdCompile->getInputFilenames().front();
|
const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
|
||||||
EXPECT_STREQ(InFile, "foo.cpp");
|
EXPECT_STREQ(InFile, "foo.cpp");
|
||||||
auto ObjFile = CmdCompile->getOutputFilenames().front();
|
auto ObjFile = CmdCompile->getOutputFilenames().front();
|
||||||
EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
|
EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
|
||||||
|
|
||||||
const auto &CmdLink = Jobs.getJobs().back();
|
const auto &CmdLink = Jobs.getJobs().back();
|
||||||
const auto LinkInFile = CmdLink->getInputFilenames().front();
|
const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
|
||||||
EXPECT_EQ(ObjFile, LinkInFile);
|
EXPECT_EQ(ObjFile, LinkInFile);
|
||||||
auto ExeFile = CmdLink->getOutputFilenames().front();
|
auto ExeFile = CmdLink->getOutputFilenames().front();
|
||||||
EXPECT_EQ("a.out", ExeFile);
|
EXPECT_EQ("a.out", ExeFile);
|
||||||
|
|
Loading…
Reference in New Issue