@@ -1160,6 +1160,14 @@ static std::string GetPluginServerForSDK(llvm::StringRef sdk_path) {
1160
1160
return server_or_err->str ();
1161
1161
}
1162
1162
1163
+ namespace {
1164
+ constexpr std::array<std::string_view, 4 > g_known_eplicit_module_prefixes =
1165
+ {" -fmodule-map-file=" ,
1166
+ " -fmodule-file=" ,
1167
+ " -fno-implicit-modules" ,
1168
+ " -fno-implicit-module-maps" };
1169
+ }
1170
+
1163
1171
// / Retrieve the serialized AST data blobs and initialize the compiler
1164
1172
// / invocation with the concatenated search paths from the blobs.
1165
1173
// / \returns true if an error was encountered.
@@ -1483,8 +1491,8 @@ bool ConsumeIncludeOption(StringRef &arg, StringRef &prefix) {
1483
1491
}
1484
1492
1485
1493
std::array<StringRef, 2 > macro_flags = { " -D" , " -U" };
1486
- std::array<StringRef, 5 > multi_arg_flags =
1487
- { " -D" , " -U" , " -I" , " -F" , " -working-directory" };
1494
+ std::array<StringRef, 6 > multi_arg_flags = {
1495
+ " -D" , " -U" , " -I" , " -F" , " -working-directory" , " -triple " };
1488
1496
std::array<StringRef, 6 > args_to_unique = {
1489
1497
" -D" , " -U" , " -I" , " -F" , " -fmodule-file=" , " -fmodule-map-file=" };
1490
1498
@@ -1519,7 +1527,25 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
1519
1527
1520
1528
llvm::SmallString<128 > cur_working_dir;
1521
1529
llvm::SmallString<128 > clang_argument;
1530
+
1531
+ auto match_explicit_build_option = [](StringRef arg) {
1532
+ for (const auto &option : g_known_eplicit_module_prefixes)
1533
+ if (arg.starts_with (option))
1534
+ return true ;
1535
+ return false ;
1536
+ };
1537
+ bool has_explicit_builds_enabled =
1538
+ llvm::find (source, " -fno-implicit-modules" ) != source.end ();
1539
+
1522
1540
for (const std::string &arg : source) {
1541
+ // Ignore the `-triple` flag. First, this is not a driver flag, and second,
1542
+ // lldb has its own logic to determine the target. Ignore now, before
1543
+ // appending the argument.
1544
+ if (clang_argument == " -triple" ) {
1545
+ clang_argument.clear ();
1546
+ continue ;
1547
+ }
1548
+
1523
1549
// Join multi-arg options for uniquing.
1524
1550
clang_argument += arg;
1525
1551
if (IsMultiArgClangFlag (clang_argument))
@@ -1549,6 +1575,14 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
1549
1575
if (clang_argument.empty ())
1550
1576
continue ;
1551
1577
1578
+ // In case of explicit modules, for now fallback to implicit
1579
+ // module loading.
1580
+ // TODO: Incorporate loading explicit module dependencies to
1581
+ // speedup dependency resolution.
1582
+ if (has_explicit_builds_enabled &&
1583
+ match_explicit_build_option (clang_argument))
1584
+ continue ;
1585
+
1552
1586
// Otherwise add the argument to the list.
1553
1587
if (!IsMacroDefinition (clang_argument))
1554
1588
ApplyWorkingDir (clang_argument, cur_working_dir);
0 commit comments