11
11
#include < optional>
12
12
#include < iostream>
13
13
14
- // Creates a copy of the output file map and updated remapping table in place
14
+ // Creates a copy of the output file map and updates remapping table in place
15
15
// It does not change the original map file as it is depended upon by the original compiler
16
16
// Returns path to the newly created output file map on success, or None in a case of failure
17
17
static std::optional<std::string> rewriteOutputFileMap (
@@ -96,7 +96,12 @@ static std::vector<std::string> computeModuleAliases(llvm::StringRef modulePath,
96
96
if (!modulePath.endswith (" .swiftmodule" )) {
97
97
return {};
98
98
}
99
-
99
+ // Deconstructing the Xcode generated path
100
+ //
101
+ // clang-format off
102
+ // intermediatesDirIndex destinationDir (2) arch(5)
103
+ // DerivedData/FooBar/Build/Intermediates.noindex/FooBar.build/Debug-iphonesimulator/FooBar.build/Objects-normal/x86_64/FooBar.swiftmodule
104
+ // clang-format on
100
105
llvm::SmallVector<llvm::StringRef> chunks;
101
106
modulePath.split (chunks, ' /' );
102
107
size_t intermediatesDirIndex = 0 ;
@@ -110,9 +115,14 @@ static std::vector<std::string> computeModuleAliases(llvm::StringRef modulePath,
110
115
if (intermediatesDirIndex == 0 ) {
111
116
return {};
112
117
}
118
+ size_t destinationDirIndex = intermediatesDirIndex + 2 ;
119
+ size_t archIndex = intermediatesDirIndex + 5 ;
120
+ if (archIndex >= chunks.size ()) {
121
+ return {};
122
+ }
113
123
// e.g. Debug-iphoneos, Release-iphonesimulator, etc.
114
- auto destinationDir = chunks[intermediatesDirIndex + 2 ].str ();
115
- auto arch = chunks[intermediatesDirIndex + 5 ].str ();
124
+ auto destinationDir = chunks[destinationDirIndex ].str ();
125
+ auto arch = chunks[archIndex ].str ();
116
126
auto moduleNameWithExt = chunks.back ();
117
127
auto moduleName = moduleNameWithExt.substr (0 , moduleNameWithExt.find_last_of (' .' ));
118
128
std::string relocatedModulePath = chunks[0 ].str ();
0 commit comments