1//===--- clang-installapi/Options.h - Options -------------------*- 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#ifndef LLVM_CLANG_TOOLS_CLANG_INSTALLAPI_OPTIONS_H
10#define LLVM_CLANG_TOOLS_CLANG_INSTALLAPI_OPTIONS_H
11
12#include "clang/Basic/Diagnostic.h"
13#include "clang/Basic/FileManager.h"
14#include "clang/Driver/Driver.h"
15#include "clang/Frontend/FrontendOptions.h"
16#include "clang/InstallAPI/Context.h"
17#include "clang/InstallAPI/DylibVerifier.h"
18#include "clang/InstallAPI/MachO.h"
19#include "llvm/Option/ArgList.h"
20#include "llvm/Option/Option.h"
21#include "llvm/Support/Program.h"
22#include "llvm/TargetParser/Triple.h"
23#include <string>
24#include <vector>
25
26namespace clang {
27namespace installapi {
28
29struct DriverOptions {
30 /// \brief Path to input file lists (JSON).
31 llvm::MachO::PathSeq FileLists;
32
33 /// \brief Path to public umbrella header.
34 std::string PublicUmbrellaHeader;
35
36 /// \brief Path to private umbrella header.
37 std::string PrivateUmbrellaHeader;
38
39 /// \brief Path to project umbrella header.
40 std::string ProjectUmbrellaHeader;
41
42 /// \brief Paths of extra public headers.
43 PathSeq ExtraPublicHeaders;
44
45 /// \brief Paths of extra private headers.
46 PathSeq ExtraPrivateHeaders;
47
48 /// \brief Paths of extra project headers.
49 PathSeq ExtraProjectHeaders;
50
51 /// \brief List of excluded public headers.
52 PathSeq ExcludePublicHeaders;
53
54 /// \brief List of excluded private headers.
55 PathSeq ExcludePrivateHeaders;
56
57 /// \brief List of excluded project headers.
58 PathSeq ExcludeProjectHeaders;
59
60 /// \brief Mappings of target triples & tapi targets to build for.
61 std::map<llvm::MachO::Target, llvm::Triple> Targets;
62
63 /// \brief Path to binary dylib for comparing.
64 std::string DylibToVerify;
65
66 /// \brief Output path.
67 std::string OutputPath;
68
69 /// \brief DSYM path.
70 std::string DSYMPath;
71
72 /// \brief File encoding to print.
73 FileType OutFT = FileType::TBD_V5;
74
75 /// \brief Verification mode for comparing symbols.
76 VerificationMode VerifyMode = VerificationMode::Pedantic;
77
78 /// \brief Whether the library is zippered.
79 bool Zippered = false;
80
81 /// \brief Print demangled symbols when reporting errors.
82 bool Demangle = false;
83
84 /// \brief Print verbose output.
85 bool Verbose = false;
86
87 /// \brief Log libraries loaded.
88 bool TraceLibraryLocation = false;
89};
90
91struct LinkerOptions {
92 /// \brief List of allowable clients to use for the dynamic library.
93 LibAttrs AllowableClients;
94
95 /// \brief List of reexported libraries to use for the dynamic library.
96 LibAttrs ReexportedLibraries;
97
98 /// \brief List of reexported libraries to use for the dynamic library.
99 LibAttrs ReexportedLibraryPaths;
100
101 /// \brief List of reexported frameworks to use for the dynamic library.
102 LibAttrs ReexportedFrameworks;
103
104 /// \brief List of rpaths to use for the dynamic library.
105 LibAttrs RPaths;
106
107 /// \brief Additional library search paths.
108 PathSeq LibPaths;
109
110 /// \brief List of alias symbol files.
111 PathSeq AliasLists;
112
113 /// \brief The install name to use for the dynamic library.
114 std::string InstallName;
115
116 /// \brief The current version to use for the dynamic library.
117 PackedVersion CurrentVersion;
118
119 /// \brief The compatibility version to use for the dynamic library.
120 PackedVersion CompatVersion;
121
122 /// \brief Name of the umbrella library.
123 std::string ParentUmbrella;
124
125 /// \brief Is application extension safe.
126 bool AppExtensionSafe = false;
127
128 /// \brief Set if we should scan for a dynamic library and not a framework.
129 bool IsDylib = false;
130
131 /// \brief Is an OS library that is not shared cache eligible.
132 bool OSLibNotForSharedCache = false;
133};
134
135struct FrontendOptions {
136 /// \brief The language mode to parse headers in.
137 Language LangMode = Language::ObjC;
138
139 /// \brief The sysroot to search for SDK headers or libraries.
140 std::string ISysroot;
141
142 /// \brief Additional framework search paths.
143 PathSeq FwkPaths;
144
145 /// \brief Additional SYSTEM framework search paths.
146 PathSeq SystemFwkPaths;
147};
148
149using arg_iterator = llvm::opt::arg_iterator<llvm::opt::Arg **>;
150class Options {
151private:
152 bool processDriverOptions(llvm::opt::InputArgList &Args);
153 bool processLinkerOptions(llvm::opt::InputArgList &Args);
154 bool processFrontendOptions(llvm::opt::InputArgList &Args);
155 std::vector<const char *>
156 processAndFilterOutInstallAPIOptions(ArrayRef<const char *> Args);
157 bool processInstallAPIXOptions(llvm::opt::InputArgList &Args);
158 bool processXarchOption(llvm::opt::InputArgList &Args, arg_iterator Curr);
159
160public:
161 /// The various options grouped together.
162 DriverOptions DriverOpts;
163 LinkerOptions LinkerOpts;
164 FrontendOptions FEOpts;
165
166 Options() = delete;
167
168 /// \brief Create InstallAPIContext from processed options.
169 InstallAPIContext createContext();
170
171 /// \brief Constructor for options.
172 Options(clang::DiagnosticsEngine &Diag, FileManager *FM,
173 ArrayRef<const char *> Args, const StringRef ProgName);
174
175 /// \brief Get CC1 arguments after extracting out the irrelevant
176 /// ones.
177 std::vector<std::string> &getClangFrontendArgs() { return FrontendArgs; }
178
179private:
180 bool addFilePaths(llvm::opt::InputArgList &Args, PathSeq &Headers,
181 llvm::opt::OptSpecifier ID);
182
183 std::pair<LibAttrs, ReexportedInterfaces> getReexportedLibraries();
184
185 DiagnosticsEngine *Diags;
186 FileManager *FM;
187 std::vector<std::string> FrontendArgs;
188 llvm::DenseMap<const llvm::opt::Arg *, Architecture> ArgToArchMap;
189};
190
191enum ID {
192 OPT_INVALID = 0, // This is not an option ID.
193#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
194 VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, \
195 VALUES) \
196 OPT_##ID,
197#include "InstallAPIOpts.inc"
198 LastOption
199#undef OPTION
200};
201
202} // namespace installapi
203} // namespace clang
204#endif
205

source code of clang/tools/clang-installapi/Options.h