aboutsummaryrefslogtreecommitdiffstats
path: root/source/Utility/Reproducer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Utility/Reproducer.cpp')
-rw-r--r--source/Utility/Reproducer.cpp85
1 files changed, 77 insertions, 8 deletions
diff --git a/source/Utility/Reproducer.cpp b/source/Utility/Reproducer.cpp
index 479ed311d1de..4777d7576a32 100644
--- a/source/Utility/Reproducer.cpp
+++ b/source/Utility/Reproducer.cpp
@@ -136,7 +136,17 @@ FileSpec Reproducer::GetReproducerPath() const {
return {};
}
-Generator::Generator(const FileSpec &root) : m_root(root), m_done(false) {}
+static FileSpec MakeAbsolute(FileSpec file_spec) {
+ SmallString<128> path;
+ file_spec.GetPath(path, false);
+ llvm::sys::fs::make_absolute(path);
+ return FileSpec(path, file_spec.GetPathStyle());
+}
+
+Generator::Generator(FileSpec root)
+ : m_root(MakeAbsolute(std::move(root))), m_done(false) {
+ GetOrCreate<repro::WorkingDirectoryProvider>();
+}
Generator::~Generator() {}
@@ -175,8 +185,8 @@ void Generator::AddProvidersToIndex() {
index.AppendPathComponent("index.yaml");
std::error_code EC;
- auto strm = llvm::make_unique<raw_fd_ostream>(index.GetPath(), EC,
- sys::fs::OpenFlags::F_None);
+ auto strm = std::make_unique<raw_fd_ostream>(index.GetPath(), EC,
+ sys::fs::OpenFlags::OF_None);
yaml::Output yout(*strm);
std::vector<std::string> files;
@@ -188,7 +198,8 @@ void Generator::AddProvidersToIndex() {
yout << files;
}
-Loader::Loader(const FileSpec &root) : m_root(root), m_loaded(false) {}
+Loader::Loader(FileSpec root)
+ : m_root(MakeAbsolute(std::move(root))), m_loaded(false) {}
llvm::Error Loader::LoadIndex() {
if (m_loaded)
@@ -223,7 +234,7 @@ bool Loader::HasFile(StringRef file) {
llvm::Expected<std::unique_ptr<DataRecorder>>
DataRecorder::Create(const FileSpec &filename) {
std::error_code ec;
- auto recorder = llvm::make_unique<DataRecorder>(std::move(filename), ec);
+ auto recorder = std::make_unique<DataRecorder>(std::move(filename), ec);
if (ec)
return llvm::errorCodeToError(ec);
return std::move(recorder);
@@ -254,7 +265,7 @@ void CommandProvider::Keep() {
FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file);
std::error_code ec;
- llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::F_Text);
+ llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text);
if (ec)
return;
yaml::Output yout(os);
@@ -266,20 +277,78 @@ void CommandProvider::Discard() { m_data_recorders.clear(); }
void VersionProvider::Keep() {
FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file);
std::error_code ec;
- llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::F_Text);
+ llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text);
if (ec)
return;
os << m_version << "\n";
}
+void WorkingDirectoryProvider::Keep() {
+ FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file);
+ std::error_code ec;
+ llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text);
+ if (ec)
+ return;
+ os << m_cwd << "\n";
+}
+
+llvm::raw_ostream *ProcessGDBRemoteProvider::GetHistoryStream() {
+ FileSpec history_file = GetRoot().CopyByAppendingPathComponent(Info::file);
+
+ std::error_code EC;
+ m_stream_up = std::make_unique<raw_fd_ostream>(history_file.GetPath(), EC,
+ sys::fs::OpenFlags::OF_Text);
+ return m_stream_up.get();
+}
+
+std::unique_ptr<CommandLoader> CommandLoader::Create(Loader *loader) {
+ if (!loader)
+ return {};
+
+ FileSpec file = loader->GetFile<repro::CommandProvider::Info>();
+ if (!file)
+ return {};
+
+ auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath());
+ if (auto err = error_or_file.getError())
+ return {};
+
+ std::vector<std::string> files;
+ llvm::yaml::Input yin((*error_or_file)->getBuffer());
+ yin >> files;
+
+ if (auto err = yin.error())
+ return {};
+
+ for (auto &file : files) {
+ FileSpec absolute_path =
+ loader->GetRoot().CopyByAppendingPathComponent(file);
+ file = absolute_path.GetPath();
+ }
+
+ return std::make_unique<CommandLoader>(std::move(files));
+}
+
+llvm::Optional<std::string> CommandLoader::GetNextFile() {
+ if (m_index >= m_files.size())
+ return {};
+ return m_files[m_index++];
+}
+
void ProviderBase::anchor() {}
-char ProviderBase::ID = 0;
char CommandProvider::ID = 0;
char FileProvider::ID = 0;
+char ProcessGDBRemoteProvider::ID = 0;
+char ProviderBase::ID = 0;
char VersionProvider::ID = 0;
+char WorkingDirectoryProvider::ID = 0;
const char *CommandProvider::Info::file = "command-interpreter.yaml";
const char *CommandProvider::Info::name = "command-interpreter";
const char *FileProvider::Info::file = "files.yaml";
const char *FileProvider::Info::name = "files";
+const char *ProcessGDBRemoteProvider::Info::file = "gdb-remote.yaml";
+const char *ProcessGDBRemoteProvider::Info::name = "gdb-remote";
const char *VersionProvider::Info::file = "version.txt";
const char *VersionProvider::Info::name = "version";
+const char *WorkingDirectoryProvider::Info::file = "cwd.txt";
+const char *WorkingDirectoryProvider::Info::name = "cwd";