blob: 05c9238c7c6455250da62d39e74c51c55e778f4a [file] [log] [blame]
Eric Beckmann82998502017-07-17 21:35:12 +00001//===- llvm-mt.cpp - Merge .manifest files ---------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===---------------------------------------------------------------------===//
9//
10// Merge .manifest files. This is intended to be a platform-independent port
11// of Microsoft's mt.exe.
12//
13//===---------------------------------------------------------------------===//
14
15#include "llvm/Option/Arg.h"
16#include "llvm/Option/ArgList.h"
17#include "llvm/Option/Option.h"
18#include "llvm/Support/Error.h"
19#include "llvm/Support/ManagedStatic.h"
20#include "llvm/Support/Path.h"
21#include "llvm/Support/PrettyStackTrace.h"
22#include "llvm/Support/Process.h"
23#include "llvm/Support/Signals.h"
24#include "llvm/Support/raw_ostream.h"
25
26#include <system_error>
27
28using namespace llvm;
29
30namespace {
31
32enum ID {
33 OPT_INVALID = 0, // This is not an option ID.
34#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
35 HELPTEXT, METAVAR, VALUES) \
36 OPT_##ID,
37#include "Opts.inc"
38#undef OPTION
39};
40
41#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
42#include "Opts.inc"
43#undef PREFIX
44
45static const opt::OptTable::Info InfoTable[] = {
46#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
47 HELPTEXT, METAVAR, VALUES) \
48{ \
49 PREFIX, NAME, HELPTEXT, \
50 METAVAR, OPT_##ID, opt::Option::KIND##Class, \
51 PARAM, FLAGS, OPT_##GROUP, \
52 OPT_##ALIAS, ALIASARGS, VALUES},
53#include "Opts.inc"
54#undef OPTION
55};
56
57class CvtResOptTable : public opt::OptTable {
58public:
59 CvtResOptTable() : OptTable(InfoTable, true) {}
60};
61
62static ExitOnError ExitOnErr;
63} // namespace
64
65LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
66 errs() << "llvm-mt error: " << Msg << "\n";
67 exit(1);
68}
69
Eric Beckmann94c74872017-07-18 03:37:34 +000070int main(int argc, const char **argv) {
Eric Beckmann94c74872017-07-18 03:37:34 +000071 sys::PrintStackTraceOnErrorSignal(argv[0]);
72 PrettyStackTraceProgram X(argc, argv);
73
74 ExitOnErr.setBanner("llvm-mt: ");
75
76 SmallVector<const char *, 256> argv_buf;
77 SpecificBumpPtrAllocator<char> ArgAllocator;
78 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
79 argv_buf, makeArrayRef(argv, argc), ArgAllocator)));
80
81 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
82
Eric Beckmann82998502017-07-17 21:35:12 +000083 CvtResOptTable T;
84 unsigned MAI, MAC;
Eric Beckmannd782ca3a2017-07-18 03:38:04 +000085 ArrayRef<const char *> ArgsArr = makeArrayRef(argv + 1, argc);
Eric Beckmann82998502017-07-17 21:35:12 +000086 opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
87
88 for (auto &Arg : InputArgs) {
89 if (Arg->getOption().matches(OPT_unsupported)) {
90 outs() << "llvm-mt: ignoring unsupported '" << Arg->getOption().getName()
91 << "' option\n";
Eric Beckmann82998502017-07-17 21:35:12 +000092 }
93 }
94
95 if (InputArgs.hasArg(OPT_help)) {
96 T.PrintHelp(outs(), "mt", "Manifest Tool", false);
97 return 0;
98 }
99
100 std::vector<std::string> InputFiles = InputArgs.getAllArgValues(OPT_manifest);
101
102 if (InputFiles.size() == 0) {
103 reportError("no input file specified");
104 }
105
106 StringRef OutputFile;
107
108 if (InputArgs.hasArg(OPT_out)) {
109 OutputFile = InputArgs.getLastArgValue(OPT_out);
110 } else if (InputFiles.size() == 1) {
111 OutputFile = InputFiles[0];
112 } else {
113 reportError("no output file specified");
114 }
115
116 return 0;
117}