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