@@ -81,12 +81,48 @@ openModuleFiles(StringRef DirName, StringRef ModuleFilename,
81
81
return std::error_code ();
82
82
}
83
83
84
+ static void addDiagnosticInfoForArchitectureMismatch (ASTContext &ctx,
85
+ SourceLoc sourceLocation,
86
+ StringRef moduleName,
87
+ StringRef archName,
88
+ StringRef directoryPath) {
89
+
90
+ std::error_code errorCode;
91
+ llvm::sys::fs::directory_iterator directoryIterator (directoryPath, errorCode,
92
+ true );
93
+ llvm::sys::fs::directory_iterator endIterator;
94
+
95
+ if (errorCode) {
96
+ return ;
97
+ }
98
+
99
+ std::string foundArchs;
100
+ for (; directoryIterator != endIterator;
101
+ directoryIterator.increment (errorCode)) {
102
+ if (errorCode) {
103
+ return ;
104
+ }
105
+ auto entry = *directoryIterator;
106
+ StringRef filePath (entry.path ());
107
+ StringRef extension = llvm::sys::path::extension (filePath);
108
+ if (extension.startswith (" ." ) &&
109
+ extension.drop_front () == SERIALIZED_MODULE_EXTENSION) {
110
+ foundArchs = foundArchs + (foundArchs.length () > 0 ? " , " : " " ) +
111
+ llvm::sys::path::stem (filePath).str ();
112
+ }
113
+ }
114
+
115
+ ctx.Diags .diagnose (sourceLocation, diag::sema_no_import_arch, moduleName,
116
+ archName, foundArchs);
117
+ }
118
+
84
119
static bool
85
120
findModule (ASTContext &ctx, AccessPathElem moduleID,
86
121
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
87
122
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
88
123
bool &isFramework) {
89
- llvm::SmallString<64 > moduleFilename (moduleID.first .str ());
124
+ llvm::SmallString<64 > moduleName (moduleID.first .str ());
125
+ llvm::SmallString<64 > moduleFilename (moduleName);
90
126
moduleFilename += ' .' ;
91
127
moduleFilename += SERIALIZED_MODULE_EXTENSION;
92
128
@@ -96,9 +132,10 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
96
132
97
133
// FIXME: Which name should we be using here? Do we care about CPU subtypes?
98
134
// FIXME: At the very least, don't hardcode "arch".
99
- llvm::SmallString<16 > archFile {
135
+ llvm::SmallString<16 > archName {
100
136
ctx.LangOpts .getPlatformConditionValue (PlatformConditionKind::Arch)};
101
- llvm::SmallString<16 > archDocFile{archFile};
137
+ llvm::SmallString<16 > archFile{archName};
138
+ llvm::SmallString<16 > archDocFile{archName};
102
139
if (!archFile.empty ()) {
103
140
archFile += ' .' ;
104
141
archFile += SERIALIZED_MODULE_EXTENSION;
@@ -122,6 +159,12 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
122
159
archFile.str (), archDocFile.str (),
123
160
moduleBuffer, moduleDocBuffer,
124
161
scratch);
162
+
163
+ if (err == std::errc::no_such_file_or_directory) {
164
+ addDiagnosticInfoForArchitectureMismatch (
165
+ ctx, moduleID.second , moduleName, archName, currPath);
166
+ return false ;
167
+ }
125
168
}
126
169
if (!err)
127
170
return true ;
@@ -134,12 +177,22 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
134
177
135
178
auto tryFrameworkImport = [&](StringRef frameworkPath) -> bool {
136
179
currPath = frameworkPath;
137
- llvm::sys::path::append (currPath, moduleFramework.str (),
138
- " Modules" , moduleFilename.str ());
139
- auto err = openModuleFiles (currPath,
140
- archFile.str (), archDocFile.str (),
141
- moduleBuffer, moduleDocBuffer,
142
- scratch);
180
+ llvm::sys::path::append (currPath, moduleFramework.str ());
181
+ // Check if the framework directory exists
182
+ if (!llvm::sys::fs::is_directory (currPath)) {
183
+ return false ;
184
+ }
185
+
186
+ llvm::sys::path::append (currPath, " Modules" , moduleFilename.str ());
187
+ auto err = openModuleFiles (currPath, archFile.str (), archDocFile.str (),
188
+ moduleBuffer, moduleDocBuffer, scratch);
189
+
190
+ if (err == std::errc::no_such_file_or_directory) {
191
+ addDiagnosticInfoForArchitectureMismatch (
192
+ ctx, moduleID.second , moduleName, archName, currPath);
193
+ return false ;
194
+ }
195
+
143
196
return !err;
144
197
};
145
198
@@ -649,4 +702,4 @@ SerializedASTFile::getDiscriminatorForPrivateValue(const ValueDecl *D) const {
649
702
Identifier discriminator = File.getDiscriminatorForPrivateValue (D);
650
703
assert (!discriminator.empty () && " no discriminator found for value" );
651
704
return discriminator;
652
- }
705
+ }
0 commit comments