[PATCH] D84858: [llvm-libtool-darwin] Refactor ArchiveWriter
Sameer Arora via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 13:39:39 PDT 2020
sameerarora101 updated this revision to Diff 282715.
sameerarora101 added a comment.
Implement `writeArchiveBuffer` using `SmallVectorMemoryBuffer`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84858/new/
https://reviews.llvm.org/D84858
Files:
llvm/include/llvm/Object/ArchiveWriter.h
llvm/lib/Object/ArchiveWriter.cpp
Index: llvm/lib/Object/ArchiveWriter.cpp
===================================================================
--- llvm/lib/Object/ArchiveWriter.cpp
+++ llvm/lib/Object/ArchiveWriter.cpp
@@ -26,6 +26,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
@@ -552,10 +553,11 @@
return std::string(Relative.str());
}
-Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
- bool WriteSymtab, object::Archive::Kind Kind,
- bool Deterministic, bool Thin,
- std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
+static Error
+writeTemporaryArchive(raw_ostream &Out, StringRef ArcName,
+ ArrayRef<NewArchiveMember> NewMembers, bool WriteSymtab,
+ object::Archive::Kind Kind, bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
SmallString<0> SymNamesBuf;
@@ -608,12 +610,6 @@
}
}
- Expected<sys::fs::TempFile> Temp =
- sys::fs::TempFile::create(ArcName + ".temp-archive-%%%%%%%.a");
- if (!Temp)
- return Temp.takeError();
-
- raw_fd_ostream Out(Temp->FD, false);
if (Thin)
Out << "!<thin>\n";
else
@@ -639,7 +635,41 @@
// closed before we attempt to rename.
OldArchiveBuf.reset();
+ return Error::success();
+}
+
+Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
+ Expected<sys::fs::TempFile> Temp =
+ sys::fs::TempFile::create(ArcName + ".temp-archive-%%%%%%%.a");
+ if (!Temp)
+ return Temp.takeError();
+ raw_fd_ostream Out(Temp->FD, false);
+
+ if (Error E =
+ writeTemporaryArchive(Out, ArcName, NewMembers, WriteSymtab, Kind,
+ Deterministic, Thin, std::move(OldArchiveBuf)))
+ return E;
return Temp->keep(ArcName);
}
+Expected<std::unique_ptr<MemoryBuffer>>
+writeArchiveToBuffer(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
+ SmallVector<char, 0> ArchiveBufferVector;
+ raw_svector_ostream ArchiveStream(ArchiveBufferVector);
+
+ if (Error E = writeTemporaryArchive(ArchiveStream, ArcName, NewMembers,
+ WriteSymtab, Kind, Deterministic, Thin,
+ std::move(OldArchiveBuf)))
+ return std::move(E);
+
+ return std::make_unique<SmallVectorMemoryBuffer>(
+ std::move(ArchiveBufferVector));
+}
+
} // namespace llvm
Index: llvm/include/llvm/Object/ArchiveWriter.h
===================================================================
--- llvm/include/llvm/Object/ArchiveWriter.h
+++ llvm/include/llvm/Object/ArchiveWriter.h
@@ -39,6 +39,12 @@
bool WriteSymtab, object::Archive::Kind Kind,
bool Deterministic, bool Thin,
std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr);
+
+Expected<std::unique_ptr<MemoryBuffer>>
+writeArchiveToBuffer(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr);
}
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84858.282715.patch
Type: text/x-patch
Size: 3813 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200803/f735adf8/attachment.bin>
More information about the llvm-commits
mailing list