WindowsManifestMerger.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- WindowsManifestMerger.h ---------------------------------*- C++-*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===---------------------------------------------------------------------===//
  13. //
  14. // This file provides a utility for merging Microsoft .manifest files. These
  15. // files are xml documents which contain meta-information about applications,
  16. // such as whether or not admin access is required, system compatibility,
  17. // versions, etc. Part of the linking process of an executable may require
  18. // merging several of these .manifest files using a tree-merge following
  19. // specific rules. Unfortunately, these rules are not documented well
  20. // anywhere. However, a careful investigation of the behavior of the original
  21. // Microsoft Manifest Tool (mt.exe) revealed the rules of this merge. As the
  22. // saying goes, code is the best documentation, so please look below if you are
  23. // interested in the exact merging requirements.
  24. //
  25. // Ref:
  26. // https://msdn.microsoft.com/en-us/library/windows/desktop/aa374191(v=vs.85).aspx
  27. //
  28. //===---------------------------------------------------------------------===//
  29. #ifndef LLVM_WINDOWSMANIFEST_WINDOWSMANIFESTMERGER_H
  30. #define LLVM_WINDOWSMANIFEST_WINDOWSMANIFESTMERGER_H
  31. #include "llvm/Support/Error.h"
  32. namespace llvm {
  33. class MemoryBuffer;
  34. class MemoryBufferRef;
  35. namespace windows_manifest {
  36. bool isAvailable();
  37. class WindowsManifestError : public ErrorInfo<WindowsManifestError, ECError> {
  38. public:
  39. static char ID;
  40. WindowsManifestError(const Twine &Msg);
  41. void log(raw_ostream &OS) const override;
  42. private:
  43. std::string Msg;
  44. };
  45. class WindowsManifestMerger {
  46. public:
  47. WindowsManifestMerger();
  48. ~WindowsManifestMerger();
  49. Error merge(MemoryBufferRef Manifest);
  50. // Returns vector containing merged xml manifest, or uninitialized vector for
  51. // empty manifest.
  52. std::unique_ptr<MemoryBuffer> getMergedManifest();
  53. private:
  54. class WindowsManifestMergerImpl;
  55. std::unique_ptr<WindowsManifestMergerImpl> Impl;
  56. };
  57. } // namespace windows_manifest
  58. } // namespace llvm
  59. #endif
  60. #ifdef __GNUC__
  61. #pragma GCC diagnostic pop
  62. #endif