@@ -128,6 +128,23 @@ static void addDiagnosticInfoForArchitectureMismatch(ASTContext &ctx,
128
128
archName, foundArchs);
129
129
}
130
130
131
+ static std::pair<llvm::SmallString<16 >, llvm::SmallString<16 >>
132
+ getArchSpecificModuleFileNames (StringRef archName) {
133
+ llvm::SmallString<16 > archFile, archDocFile;
134
+
135
+ if (!archName.empty ()) {
136
+ archFile += archName;
137
+ archFile += ' .' ;
138
+ archFile += file_types::getExtension (file_types::TY_SwiftModuleFile);
139
+
140
+ archDocFile += archName;
141
+ archDocFile += ' .' ;
142
+ archDocFile += file_types::getExtension (file_types::TY_SwiftModuleDocFile);
143
+ }
144
+
145
+ return {archFile, archDocFile};
146
+ }
147
+
131
148
bool
132
149
SerializedModuleLoaderBase::findModule (AccessPathElem moduleID,
133
150
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
@@ -143,19 +160,19 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
143
160
moduleDocFilename +=
144
161
file_types::getExtension (file_types::TY_SwiftModuleDocFile);
145
162
146
- // FIXME: Which name should we be using here? Do we care about CPU subtypes?
147
- // FIXME: At the very least, don't hardcode "arch".
148
- llvm::SmallString<16 > archName{
149
- Ctx.LangOpts .getPlatformConditionValue (PlatformConditionKind::Arch)};
150
- llvm::SmallString<16 > archFile{archName};
151
- llvm::SmallString<16 > archDocFile{archName};
152
- if (!archFile.empty ()) {
153
- archFile += ' .' ;
154
- archFile += file_types::getExtension (file_types::TY_SwiftModuleFile);
163
+ StringRef archName = Ctx.LangOpts .Target .getArchName ();
164
+ auto archFileNames = getArchSpecificModuleFileNames (archName);
155
165
156
- archDocFile += ' .' ;
157
- archDocFile += file_types::getExtension (file_types::TY_SwiftModuleDocFile);
158
- }
166
+ // FIXME: We used to use "major architecture" names for these files---the
167
+ // names checked in "#if arch(...)". Fall back to that name in the one case
168
+ // where it's different from what Swift 4.2 supported: 32-bit ARM platforms.
169
+ // We should be able to drop this once there's an Xcode that supports the
170
+ // new names.
171
+ StringRef alternateArchName;
172
+ if (Ctx.LangOpts .Target .getArch () == llvm::Triple::ArchType::arm)
173
+ alternateArchName = " arm" ;
174
+ auto alternateArchFileNames =
175
+ getArchSpecificModuleFileNames (alternateArchName);
159
176
160
177
llvm::SmallString<128 > scratch;
161
178
llvm::SmallString<128 > currPath;
@@ -169,10 +186,19 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
169
186
currPath = path;
170
187
llvm::sys::path::append (currPath, moduleFilename.str ());
171
188
err = openModuleFiles (currPath,
172
- archFile. str (), archDocFile. str () ,
189
+ archFileNames. first , archFileNames. second ,
173
190
moduleBuffer, moduleDocBuffer,
174
191
scratch);
175
192
193
+ if (err == std::errc::no_such_file_or_directory &&
194
+ !alternateArchName.empty ()) {
195
+ err = openModuleFiles (currPath,
196
+ alternateArchFileNames.first ,
197
+ alternateArchFileNames.second ,
198
+ moduleBuffer, moduleDocBuffer,
199
+ scratch);
200
+ }
201
+
176
202
if (err == std::errc::no_such_file_or_directory) {
177
203
addDiagnosticInfoForArchitectureMismatch (
178
204
Ctx, moduleID.second , moduleName, archName, currPath);
@@ -197,9 +223,18 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
197
223
}
198
224
199
225
llvm::sys::path::append (currPath, " Modules" , moduleFilename.str ());
200
- auto err = openModuleFiles (currPath, archFile.str (), archDocFile.str (),
226
+ auto err = openModuleFiles (currPath,
227
+ archFileNames.first , archFileNames.second ,
201
228
moduleBuffer, moduleDocBuffer, scratch);
202
229
230
+ if (err == std::errc::no_such_file_or_directory &&
231
+ !alternateArchName.empty ()) {
232
+ err = openModuleFiles (currPath,
233
+ alternateArchFileNames.first ,
234
+ alternateArchFileNames.second ,
235
+ moduleBuffer, moduleDocBuffer, scratch);
236
+ }
237
+
203
238
if (err == std::errc::no_such_file_or_directory) {
204
239
addDiagnosticInfoForArchitectureMismatch (
205
240
Ctx, moduleID.second , moduleName, archName, currPath);
0 commit comments