Skip to content

Commit eebc8de

Browse files
committed
Make the diagnostic message at a Note and append found architectures with it
1 parent ea3a9f4 commit eebc8de

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,9 @@ ERROR(cannot_return_value_from_void_func,none,
562562

563563
ERROR(sema_no_import,Fatal,
564564
"no such module '%0'", (StringRef))
565-
ERROR(sema_no_import_arch,Fatal,
566-
"could not find module '%0' for architecture '%1'", (StringRef, StringRef))
565+
NOTE(sema_no_import_arch,Fatal,
566+
"could not find module '%0' for architecture '%1' "
567+
"found: %2", (StringRef, StringRef, StringRef))
567568
ERROR(sema_no_import_repl,none,
568569
"no such module '%0'", (StringRef))
569570
NOTE(sema_no_import_no_sdk,none,

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ openModuleFiles(StringRef DirName, StringRef ModuleFilename,
8181
return std::error_code();
8282
}
8383

84+
static void addDiagnosticInfoForArchitectureMismatch(ASTContext &ctx,
85+
SourceLoc sourceLocation,
86+
llvm::SmallString<64> moduleName,
87+
llvm::SmallString<16> archName,
88+
llvm::SmallString<128> directoryPath) {
89+
90+
std::error_code errorCode;
91+
llvm::Twine twineDirPath(directoryPath);
92+
llvm::sys::fs::directory_iterator directoryIterator(twineDirPath,
93+
errorCode,
94+
true);
95+
llvm::sys::fs::directory_iterator endIterator;
96+
97+
if(errorCode) {
98+
return;
99+
}
100+
101+
std::string foundArchs;
102+
for (; directoryIterator != endIterator; directoryIterator.increment(errorCode)) {
103+
auto entry = *directoryIterator;
104+
llvm::StringRef filePath(entry.path());
105+
foundArchs = foundArchs + (foundArchs.length() > 0 ? ", " : "")
106+
+ llvm::sys::path::stem(filePath).str();
107+
}
108+
109+
ctx.Diags.diagnose(sourceLocation, diag::sema_no_import_arch,
110+
moduleName, archName, foundArchs);
111+
}
112+
84113
static bool
85114
findModule(ASTContext &ctx, AccessPathElem moduleID,
86115
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
@@ -125,12 +154,15 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
125154
moduleBuffer, moduleDocBuffer,
126155
scratch);
127156

128-
if(err == std::errc::no_such_file_or_directory) {
129-
ctx.Diags.diagnose(moduleID.second, diag::sema_no_import_arch,
130-
moduleName, archName);
131-
}
157+
if(err == std::errc::no_such_file_or_directory) {
158+
addDiagnosticInfoForArchitectureMismatch(ctx,
159+
moduleID.second,
160+
moduleName,
161+
archName,
162+
currPath);
163+
}
132164

133-
return false;
165+
return false;
134166
}
135167
if (!err)
136168
return true;

test/Serialization/load-invalid-arch.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// RUN: %empty-directory(%t)
33
// RUN: mkdir %t/new_module.swiftmodule
44
// RUN: touch %t/new_module.swiftmodule/arm64.swiftmodule
5+
// RUN: touch %t/new_module.swiftmodule/powerpc64.swiftmodule
56
// RUN: %target-swift-frontend %s -typecheck -I %t -verify -show-diagnostics-after-fatal
67

7-
import new_module // expected-error {{no such module 'new_module'}} expected-error {{could not find module 'new_module' for architecture 'x86_64'}}
8+
import new_module // expected-error {{no such module 'new_module'}} expected-note {{could not find module 'new_module' for architecture 'x86_64' found: powerpc64, arm64}}
89

910
new_module.foo() // expected-error {{use of unresolved identifier 'new_module'}}

0 commit comments

Comments
 (0)