Skip to content

Commit f0015a2

Browse files
committed
[clang] Move options from clangDriver into new clangOptions library (NFC)
The goal of this change is to remove dependencies on the Driver. This is part of a larger effort to support driver-managed builds for compilations using C++ named modules and/or Clang modules. It is required to eventually allow linking the dependency scanning tooling against the Driver without creating cyclic dependencies, which would cause build failures when dynamic linking is enabled. This PR is motivated by the following review comment: #152770 (comment)
1 parent 26db214 commit f0015a2

File tree

116 files changed

+585
-609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+585
-609
lines changed

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ clang_target_link_libraries(clangDaemon
165165
clangBasic
166166
clangDependencyScanning
167167
clangDriver
168+
clangOptions
168169
clangFormat
169170
clangFrontend
170171
clangIndex

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "support/Logger.h"
1212
#include "support/Trace.h"
1313
#include "clang/Driver/Driver.h"
14-
#include "clang/Driver/Options.h"
1514
#include "clang/Frontend/CompilerInvocation.h"
15+
#include "clang/Options/Options.h"
1616
#include "clang/Tooling/CompilationDatabase.h"
1717
#include "clang/Tooling/Tooling.h"
1818
#include "llvm/ADT/ArrayRef.h"
@@ -206,7 +206,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
206206
if (Cmd.empty())
207207
return;
208208

209-
auto &OptTable = clang::driver::getDriverOptTable();
209+
auto &OptTable = getDriverOptTable();
210210
// OriginalArgs needs to outlive ArgList.
211211
llvm::SmallVector<const char *, 16> OriginalArgs;
212212
OriginalArgs.reserve(Cmd.size());
@@ -222,8 +222,8 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
222222
llvm::opt::InputArgList ArgList;
223223
ArgList = OptTable.ParseArgs(
224224
llvm::ArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
225-
llvm::opt::Visibility(IsCLMode ? driver::options::CLOption
226-
: driver::options::ClangOption));
225+
llvm::opt::Visibility(IsCLMode ? options::CLOption
226+
: options::ClangOption));
227227

228228
llvm::SmallVector<unsigned, 1> IndicesToDrop;
229229
// Having multiple architecture options (e.g. when building fat binaries)
@@ -232,7 +232,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
232232
// As there are no signals to figure out which one user actually wants. They
233233
// can explicitly specify one through `CompileFlags.Add` if need be.
234234
unsigned ArchOptCount = 0;
235-
for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
235+
for (auto *Input : ArgList.filtered(options::OPT_arch)) {
236236
++ArchOptCount;
237237
for (auto I = 0U; I <= Input->getNumValues(); ++I)
238238
IndicesToDrop.push_back(Input->getIndex() + I);
@@ -262,13 +262,12 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
262262
// explicitly at the end of the flags. This ensures modifications done in the
263263
// following steps apply in more cases (like setting -x, which only affects
264264
// inputs that come after it).
265-
for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT)) {
265+
for (auto *Input : ArgList.filtered(options::OPT_INPUT)) {
266266
SawInput(Input->getValue(0));
267267
IndicesToDrop.push_back(Input->getIndex());
268268
}
269269
// Anything after `--` is also treated as input, drop them as well.
270-
if (auto *DashDash =
271-
ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
270+
if (auto *DashDash = ArgList.getLastArgNoClaim(options::OPT__DASH_DASH)) {
272271
auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0]
273272
// Another +1 so we don't treat the `--` itself as an input.
274273
for (unsigned I = DashDashIndex + 1; I < Cmd.size(); ++I)
@@ -424,11 +423,11 @@ DriverMode getDriverMode(const std::vector<std::string> &Args) {
424423
// Returns the set of DriverModes where an option may be used.
425424
unsigned char getModes(const llvm::opt::Option &Opt) {
426425
unsigned char Result = DM_None;
427-
if (Opt.hasVisibilityFlag(driver::options::ClangOption))
426+
if (Opt.hasVisibilityFlag(options::ClangOption))
428427
Result |= DM_GCC;
429-
if (Opt.hasVisibilityFlag(driver::options::CC1Option))
428+
if (Opt.hasVisibilityFlag(options::CC1Option))
430429
Result |= DM_CC1;
431-
if (Opt.hasVisibilityFlag(driver::options::CLOption))
430+
if (Opt.hasVisibilityFlag(options::CLOption))
432431
Result |= DM_CL;
433432
return Result;
434433
}
@@ -442,8 +441,8 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
442441
using TableTy =
443442
llvm::StringMap<llvm::SmallVector<Rule, 4>, llvm::BumpPtrAllocator>;
444443
static TableTy *Table = [] {
445-
auto &DriverTable = driver::getDriverOptTable();
446-
using DriverID = clang::driver::options::ID;
444+
auto &DriverTable = getDriverOptTable();
445+
using DriverID = clang::options::ID;
447446

448447
// Collect sets of aliases, so we can treat -foo and -foo= as synonyms.
449448
// Conceptually a double-linked list: PrevAlias[I] -> I -> NextAlias[I].
@@ -468,7 +467,7 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
468467
FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
469468
METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
470469
{DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS},
471-
#include "clang/Driver/Options.inc"
470+
#include "clang/Options/Options.inc"
472471
#undef OPTION
473472
};
474473
for (auto &E : AliasTable)

clang-tools-extra/modularize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ clang_target_link_libraries(modularize
2020
clangAST
2121
clangBasic
2222
clangDriver
23+
clangOptions
2324
clangFrontend
2425
clangLex
2526
clangSerialization

clang-tools-extra/modularize/CoverageChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@
5050
//
5151
//===----------------------------------------------------------------------===//
5252

53+
#include "CoverageChecker.h"
5354
#include "ModularizeUtilities.h"
5455
#include "clang/AST/ASTConsumer.h"
55-
#include "CoverageChecker.h"
5656
#include "clang/AST/ASTContext.h"
5757
#include "clang/AST/RecursiveASTVisitor.h"
5858
#include "clang/Basic/SourceManager.h"
59-
#include "clang/Driver/Options.h"
6059
#include "clang/Frontend/CompilerInstance.h"
6160
#include "clang/Frontend/FrontendAction.h"
6261
#include "clang/Frontend/FrontendActions.h"
6362
#include "clang/Lex/PPCallbacks.h"
6463
#include "clang/Lex/Preprocessor.h"
64+
#include "clang/Options/Options.h"
6565
#include "clang/Tooling/CompilationDatabase.h"
6666
#include "clang/Tooling/Tooling.h"
6767
#include "llvm/Option/Option.h"
@@ -73,7 +73,7 @@
7373
using namespace Modularize;
7474
using namespace clang;
7575
using namespace clang::driver;
76-
using namespace clang::driver::options;
76+
using namespace clang::options;
7777
using namespace clang::tooling;
7878
namespace cl = llvm::cl;
7979
namespace sys = llvm::sys;

clang-tools-extra/modularize/Modularize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@
231231
#include "clang/AST/ASTContext.h"
232232
#include "clang/AST/RecursiveASTVisitor.h"
233233
#include "clang/Basic/SourceManager.h"
234-
#include "clang/Driver/Options.h"
235234
#include "clang/Frontend/CompilerInstance.h"
236235
#include "clang/Frontend/FrontendAction.h"
237236
#include "clang/Frontend/FrontendActions.h"
238237
#include "clang/Lex/Preprocessor.h"
238+
#include "clang/Options/Options.h"
239239
#include "clang/Tooling/CompilationDatabase.h"
240240
#include "clang/Tooling/Tooling.h"
241241
#include "llvm/Option/Arg.h"
@@ -254,7 +254,7 @@
254254

255255
using namespace clang;
256256
using namespace clang::driver;
257-
using namespace clang::driver::options;
257+
using namespace clang::options;
258258
using namespace clang::tooling;
259259
using namespace llvm;
260260
using namespace llvm::opt;

clang-tools-extra/modularize/ModularizeUtilities.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "ModularizeUtilities.h"
16+
#include "CoverageChecker.h"
1517
#include "clang/Basic/SourceManager.h"
16-
#include "clang/Driver/Options.h"
1718
#include "clang/Frontend/CompilerInstance.h"
1819
#include "clang/Frontend/FrontendActions.h"
19-
#include "CoverageChecker.h"
20+
#include "clang/Options/Options.h"
2021
#include "llvm/ADT/SmallString.h"
2122
#include "llvm/Support/FileUtilities.h"
2223
#include "llvm/Support/MemoryBuffer.h"
2324
#include "llvm/Support/Path.h"
2425
#include "llvm/Support/raw_ostream.h"
25-
#include "ModularizeUtilities.h"
2626

2727
using namespace clang;
2828
using namespace llvm;

clang-tools-extra/pp-trace/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ clang_target_link_libraries(pp-trace
1414
PRIVATE
1515
clangAST
1616
clangBasic
17+
clangOptions
1718
clangFrontend
1819
clangLex
1920
clangSerialization

clang-tools-extra/pp-trace/PPTrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
#include "clang/AST/ASTConsumer.h"
2929
#include "clang/AST/ASTContext.h"
3030
#include "clang/Basic/SourceManager.h"
31-
#include "clang/Driver/Options.h"
3231
#include "clang/Frontend/CompilerInstance.h"
3332
#include "clang/Frontend/FrontendAction.h"
3433
#include "clang/Frontend/FrontendActions.h"
3534
#include "clang/Lex/Preprocessor.h"
35+
#include "clang/Options/Options.h"
3636
#include "clang/Tooling/Execution.h"
3737
#include "clang/Tooling/Tooling.h"
3838
#include "llvm/Option/Arg.h"

clang/docs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ if (LLVM_ENABLE_SPHINX)
132132
# Generated files
133133
gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs ../include/clang/Basic/Attr.td "${docs_targets}")
134134
gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs ../include/clang/Basic/Diagnostic.td "${docs_targets}")
135-
gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Driver/ClangOptionDocs.td "${docs_targets}")
135+
gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Options/ClangOptionDocs.td "${docs_targets}")
136136

137137
# Another generated file from a different source
138138
set(docs_tools_dir ${CMAKE_CURRENT_SOURCE_DIR}/tools)

clang/docs/InternalsManual.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ Command Line Interface
667667
----------------------
668668

669669
The command line interface of the Clang ``-cc1`` frontend is defined alongside
670-
the driver options in ``clang/Driver/Options.td``. The information making up an
670+
the driver options in ``clang/Options/Options.td``. The information making up an
671671
option definition includes its prefix and name (for example ``-std=``), form and
672672
position of the option value, help text, aliases and more. Each option may
673673
belong to a certain group and can be marked with zero or more flags. Options
@@ -712,7 +712,7 @@ variable for the option value:
712712
}
713713
714714
Next, declare the command line interface of the option in the tablegen file
715-
``clang/include/clang/Driver/Options.td``. This is done by instantiating the
715+
``clang/include/clang/Options/Options.td``. This is done by instantiating the
716716
``Option`` class (defined in ``llvm/include/llvm/Option/OptParser.td``). The
717717
instance is typically created through one of the helper classes that encode the
718718
acceptable ways to specify the option value on the command line:
@@ -906,7 +906,7 @@ command line:
906906
SHOULD_PARSE, KEYPATH, DEFAULT_VALUE, \
907907
IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \
908908
MERGER, TABLE_INDEX)
909-
#include "clang/Driver/Options.inc"
909+
#include "clang/Options/Options.inc"
910910
#undef LANG_OPTION_WITH_MARSHALLING
911911

912912
// ...
@@ -925,7 +925,7 @@ command line:
925925
GENERATE_OPTION_WITH_MARSHALLING( \
926926
Args, SA, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
927927
IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, EXTRACTOR, TABLE_INDEX)
928-
#include "clang/Driver/Options.inc"
928+
#include "clang/Options/Options.inc"
929929
#undef LANG_OPTION_WITH_MARSHALLING
930930
931931
// ...

0 commit comments

Comments
 (0)