aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/clang-installapi/Options.h
blob: d62f2efd3141ac3785686d0f6792b29208233714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//===--- clang-installapi/Options.h - Options -------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_CLANG_INSTALLAPI_OPTIONS_H
#define LLVM_CLANG_TOOLS_CLANG_INSTALLAPI_OPTIONS_H

#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Driver/Driver.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/InstallAPI/Context.h"
#include "clang/InstallAPI/DylibVerifier.h"
#include "clang/InstallAPI/MachO.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Program.h"
#include "llvm/TargetParser/Triple.h"
#include <string>
#include <vector>

namespace clang {
namespace installapi {

struct DriverOptions {
  /// \brief Path to input file lists (JSON).
  llvm::MachO::PathSeq FileLists;

  /// \brief Path to input directory.
  std::string InputDirectory;

  /// \brief Path to public umbrella header.
  std::string PublicUmbrellaHeader;

  /// \brief Path to private umbrella header.
  std::string PrivateUmbrellaHeader;

  /// \brief Path to project umbrella header.
  std::string ProjectUmbrellaHeader;

  /// \brief Paths of extra public headers.
  PathSeq ExtraPublicHeaders;

  /// \brief Paths of extra private headers.
  PathSeq ExtraPrivateHeaders;

  /// \brief Paths of extra project headers.
  PathSeq ExtraProjectHeaders;

  /// \brief List of excluded public headers.
  PathSeq ExcludePublicHeaders;

  /// \brief List of excluded private headers.
  PathSeq ExcludePrivateHeaders;

  /// \brief List of excluded project headers.
  PathSeq ExcludeProjectHeaders;

  /// \brief Mappings of target triples & tapi targets to build for.
  std::map<llvm::MachO::Target, llvm::Triple> Targets;

  /// \brief Path to binary dylib for comparing.
  std::string DylibToVerify;

  /// \brief Output path.
  std::string OutputPath;

  /// \brief DSYM path.
  std::string DSYMPath;

  /// \brief File encoding to print.
  FileType OutFT = FileType::TBD_V5;

  /// \brief Verification mode for comparing symbols.
  VerificationMode VerifyMode = VerificationMode::Pedantic;

  /// \brief Whether the library is zippered.
  bool Zippered = false;

  /// \brief Print demangled symbols when reporting errors.
  bool Demangle = false;

  /// \brief Print verbose output.
  bool Verbose = false;

  /// \brief Log libraries loaded.
  bool TraceLibraryLocation = false;
};

struct LinkerOptions {
  /// \brief List of allowable clients to use for the dynamic library.
  LibAttrs AllowableClients;

  /// \brief List of reexported libraries to use for the dynamic library.
  LibAttrs ReexportedLibraries;

  /// \brief List of reexported libraries to use for the dynamic library.
  LibAttrs ReexportedLibraryPaths;

  /// \brief List of reexported frameworks to use for the dynamic library.
  LibAttrs ReexportedFrameworks;

  /// \brief List of rpaths to use for the dynamic library.
  LibAttrs RPaths;

  /// \brief Additional library search paths.
  PathSeq LibPaths;

  /// \brief List of alias symbol files.
  PathSeq AliasLists;

  /// \brief The install name to use for the dynamic library.
  std::string InstallName;

  /// \brief The current version to use for the dynamic library.
  PackedVersion CurrentVersion;

  /// \brief The compatibility version to use for the dynamic library.
  PackedVersion CompatVersion;

  /// \brief Name of the umbrella library.
  std::string ParentUmbrella;

  /// \brief Is application extension safe.
  bool AppExtensionSafe = false;

  /// \brief Set if we should scan for a dynamic library and not a framework.
  bool IsDylib = false;

  /// \brief Is an OS library that is not shared cache eligible.
  bool OSLibNotForSharedCache = false;
};

struct FrontendOptions {
  /// \brief Unique clang options to pass per key in map.
  llvm::StringMap<std::vector<std::string>> UniqueArgs;

  /// \brief The language mode to parse headers in.
  Language LangMode = Language::ObjC;

  /// \brief The sysroot to search for SDK headers or libraries.
  std::string ISysroot;

  /// \brief Additional framework search paths.
  PathSeq FwkPaths;

  /// \brief Additional SYSTEM framework search paths.
  PathToPlatformSeq SystemFwkPaths;
};

using arg_iterator = llvm::opt::arg_iterator<llvm::opt::Arg **>;
class Options {
private:
  bool processDriverOptions(llvm::opt::InputArgList &Args);
  bool processLinkerOptions(llvm::opt::InputArgList &Args);
  bool processFrontendOptions(llvm::opt::InputArgList &Args);
  std::vector<const char *>
  processAndFilterOutInstallAPIOptions(ArrayRef<const char *> Args);
  bool processInstallAPIXOptions(llvm::opt::InputArgList &Args);
  bool processXarchOption(llvm::opt::InputArgList &Args, arg_iterator Curr);
  bool processXplatformOption(llvm::opt::InputArgList &Args, arg_iterator Curr);
  bool processXprojectOption(llvm::opt::InputArgList &Args, arg_iterator Curr);
  bool processOptionList(llvm::opt::InputArgList &Args,
                         llvm::opt::OptTable *Table);

public:
  /// The various options grouped together.
  DriverOptions DriverOpts;
  LinkerOptions LinkerOpts;
  FrontendOptions FEOpts;

  Options() = delete;

  /// \brief Create InstallAPIContext from processed options.
  InstallAPIContext createContext();

  /// \brief Constructor for options.
  Options(clang::DiagnosticsEngine &Diag, FileManager *FM,
          ArrayRef<const char *> Args, const StringRef ProgName);

  /// \brief Get CC1 arguments after extracting out the irrelevant
  /// ones.
  std::vector<std::string> &getClangFrontendArgs() { return FrontendArgs; }

  /// \brief Add relevant, but conditionalized by active target and header type,
  /// arguments for constructing a CC1 invocation.
  void addConditionalCC1Args(std::vector<std::string> &ArgStrings,
                             const llvm::Triple &Targ, const HeaderType Type);

private:
  bool addFilePaths(llvm::opt::InputArgList &Args, PathSeq &Headers,
                    llvm::opt::OptSpecifier ID);

  std::pair<LibAttrs, ReexportedInterfaces> getReexportedLibraries();

  DiagnosticsEngine *Diags;
  FileManager *FM;
  std::vector<std::string> FrontendArgs;
  llvm::DenseMap<const llvm::opt::Arg *, Architecture> ArgToArchMap;
  std::vector<std::string> ProjectLevelArgs;
};

enum ID {
  OPT_INVALID = 0, // This is not an option ID.
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS,         \
               VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR,     \
               VALUES)                                                         \
  OPT_##ID,
#include "InstallAPIOpts.inc"
  LastOption
#undef OPTION
};

} // namespace installapi
} // namespace clang
#endif