diff options
author | Eric Beckmann <ecbeckmann@google.com> | 2017-07-20 21:42:04 +0000 |
---|---|---|
committer | Eric Beckmann <ecbeckmann@google.com> | 2017-07-20 21:42:04 +0000 |
commit | 7d50c389c4d46ccd3b4f06d09f32202f9ae94bc9 (patch) | |
tree | 776f10fa768d2ca0d66da2aa46438d286e4cdf56 /llvm/lib/Support/WindowsManifestMerger.cpp | |
parent | eaf833ca2bb35323cfcb333b0ec71f1adc35b530 (diff) | |
download | bcm5719-llvm-7d50c389c4d46ccd3b4f06d09f32202f9ae94bc9.tar.gz bcm5719-llvm-7d50c389c4d46ccd3b4f06d09f32202f9ae94bc9.zip |
Implement parsing and writing of a single xml manifest file.
Summary: Implement parsing and writing of a single xml manifest file.
Subscribers: mgorny, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D35425
llvm-svn: 308679
Diffstat (limited to 'llvm/lib/Support/WindowsManifestMerger.cpp')
-rw-r--r-- | llvm/lib/Support/WindowsManifestMerger.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/llvm/lib/Support/WindowsManifestMerger.cpp b/llvm/lib/Support/WindowsManifestMerger.cpp new file mode 100644 index 00000000000..60cddd10596 --- /dev/null +++ b/llvm/lib/Support/WindowsManifestMerger.cpp @@ -0,0 +1,70 @@ +//===-- WindowsManifestMerger.cpp ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===---------------------------------------------------------------------===// +// +// This file implements the .manifest merger class. +// +//===---------------------------------------------------------------------===// + +#include "llvm/Support/WindowsManifestMerger.h" +#include "llvm/Support/MemoryBuffer.h" + +#include <stdarg.h> + +namespace llvm { + +char WindowsManifestError::ID = 0; + +WindowsManifestError::WindowsManifestError(const Twine &Msg) : Msg(Msg.str()) {} + +void WindowsManifestError::log(raw_ostream &OS) const { OS << Msg; } + +Error WindowsManifestMerger::merge(const MemoryBuffer &Manifest) { +#if LLVM_LIBXML2_ENABLED + xmlSetGenericErrorFunc((void *)this, WindowsManifestMerger::errorCallback); + XMLDocumentImpl ManifestXML = + xmlReadMemory(Manifest.getBufferStart(), Manifest.getBufferSize(), + "manifest.xml", nullptr, 0); + xmlSetGenericErrorFunc(nullptr, nullptr); + if (auto E = getParseError()) + return E; + CombinedRoot = xmlDocGetRootElement(ManifestXML); +#endif + return Error::success(); +} + +std::unique_ptr<MemoryBuffer> WindowsManifestMerger::getMergedManifest() { +#if LLVM_LIBXML2_ENABLED + unsigned char *XmlBuff; + int BufferSize = 0; + if (CombinedRoot) { + std::unique_ptr<xmlDoc> OutputDoc(xmlNewDoc((const unsigned char *)"1.0")); + xmlDocSetRootElement(OutputDoc.get(), CombinedRoot); + xmlDocDumpMemory(OutputDoc.get(), &XmlBuff, &BufferSize); + } + if (BufferSize == 0) + return nullptr; + return MemoryBuffer::getMemBuffer( + StringRef(reinterpret_cast<const char *>(XmlBuff), (size_t)BufferSize)); +#else + return nullptr; +#endif +} + +void WindowsManifestMerger::errorCallback(void *Ctx, const char *Format, ...) { + auto *Merger = (WindowsManifestMerger *)Ctx; + Merger->ParseErrorOccurred = true; +} + +Error WindowsManifestMerger::getParseError() { + if (!ParseErrorOccurred) + return Error::success(); + return make_error<WindowsManifestError>("invalid xml document"); +} + +} // namespace llvm |