@@ -19,11 +19,12 @@ static std::optional<std::string> rewriteOutputFileMap(
19
19
const std::string& outputFileMapPath,
20
20
const std::vector<std::string>& inputs,
21
21
std::unordered_map<std::string, std::string>& remapping) {
22
- auto newPath = config.tempArtifactDir + ' /' + outputFileMapPath;
22
+ auto newMapPath = config.getTempArtifactDir () + ' /' + outputFileMapPath;
23
23
24
24
// TODO: do not assume absolute path for the second parameter
25
25
auto outputMapOrError = swift::OutputFileMap::loadFromPath (outputFileMapPath, " " );
26
26
if (!outputMapOrError) {
27
+ std::cerr << " Cannot load output map: '" << outputFileMapPath << " '\n " ;
27
28
return std::nullopt;
28
29
}
29
30
auto oldOutputMap = outputMapOrError.get ();
@@ -39,23 +40,23 @@ static std::optional<std::string> rewriteOutputFileMap(
39
40
newMap.copyFrom (*oldMap);
40
41
for (auto & entry : newMap) {
41
42
auto oldPath = entry.getSecond ();
42
- auto newPath = config.tempArtifactDir + ' /' + oldPath;
43
+ auto newPath = config.getTempArtifactDir () + ' /' + oldPath;
43
44
entry.getSecond () = newPath;
44
45
remapping[oldPath] = newPath;
45
46
}
46
47
}
47
48
std::error_code ec;
48
- llvm::SmallString<PATH_MAX> filepath (newPath );
49
+ llvm::SmallString<PATH_MAX> filepath (newMapPath );
49
50
llvm::StringRef parent = llvm::sys::path::parent_path (filepath);
50
51
if (std::error_code ec = llvm::sys::fs::create_directories (parent)) {
51
52
std::cerr << " Cannot create relocated output map dir: '" << parent.str ()
52
53
<< " ': " << ec.message () << " \n " ;
53
54
return std::nullopt;
54
55
}
55
56
56
- llvm::raw_fd_ostream fd (newPath , ec, llvm::sys::fs::OF_None);
57
+ llvm::raw_fd_ostream fd (newMapPath , ec, llvm::sys::fs::OF_None);
57
58
newOutputMap.write (fd, keys);
58
- return newPath ;
59
+ return newMapPath ;
59
60
}
60
61
61
62
// This is an Xcode-specific workaround to produce alias names for an existing .swiftmodule file.
@@ -132,30 +133,27 @@ static std::vector<std::string> computeModuleAliases(llvm::StringRef modulePath,
132
133
relocatedModulePath += " /Products/" ;
133
134
relocatedModulePath += destinationDir + ' /' ;
134
135
135
- std::vector<std::string> moduleLocations;
136
-
137
- std::string firstCase = relocatedModulePath;
138
- firstCase += moduleNameWithExt.str () + ' /' ;
139
- moduleLocations. push_back (firstCase);
140
-
141
- std::string secondCase = relocatedModulePath;
142
- secondCase += moduleName.str () + ' /' ;
143
- secondCase += moduleNameWithExt. str () + ' / ' ;
144
- moduleLocations. push_back (secondCase);
136
+ // clang-format off
137
+ std::vector<std::string> moduleLocations = {
138
+ // First case
139
+ relocatedModulePath + moduleNameWithExt.str () + ' /' ,
140
+ // Second case
141
+ relocatedModulePath + moduleName. str () + ' / ' + moduleNameWithExt. str () + ' / ' ,
142
+ // Third case
143
+ relocatedModulePath + moduleName.str () + ' /' + moduleName. str () + " .framework/Modules/ " + moduleNameWithExt. str () + ' / ' ,
144
+ } ;
145
+ // clang-format on
145
146
146
- std::string thirdCase = relocatedModulePath ;
147
- thirdCase += moduleName. str () + ' / ' ;
148
- thirdCase += moduleName. str () + " .framework/Modules/ " ;
149
- thirdCase += moduleNameWithExt. str () + ' / ' ;
150
- moduleLocations. push_back (thirdCase);
147
+ std::vector<std:: string> archs ({arch}) ;
148
+ if (!targetTriple. empty ()) {
149
+ llvm::Triple triple (targetTriple) ;
150
+ archs. push_back ( swift::getTargetSpecificModuleTriple (triple). normalize ()) ;
151
+ }
151
152
152
153
std::vector<std::string> aliases;
153
154
for (auto & location : moduleLocations) {
154
- aliases.push_back (location + arch + " .swiftmodule" );
155
- if (!targetTriple.empty ()) {
156
- llvm::Triple triple (targetTriple);
157
- auto moduleTriple = swift::getTargetSpecificModuleTriple (triple);
158
- aliases.push_back (location + moduleTriple.normalize () + " .swiftmodule" );
155
+ for (auto & a : archs) {
156
+ aliases.push_back (location + a + " .swiftmodule" );
159
157
}
160
158
}
161
159
@@ -195,7 +193,7 @@ std::unordered_map<std::string, std::string> rewriteOutputsInPlace(
195
193
for (size_t i = 0 ; i < CLIArgs.size (); i++) {
196
194
if (pathRewriteOptions.count (CLIArgs[i])) {
197
195
auto oldPath = CLIArgs[i + 1 ];
198
- auto newPath = config.tempArtifactDir + ' /' + oldPath;
196
+ auto newPath = config.getTempArtifactDir () + ' /' + oldPath;
199
197
CLIArgs[++i] = newPath;
200
198
newLocations.push_back (newPath);
201
199
@@ -261,20 +259,20 @@ void storeRemappingForVFS(const SwiftExtractorConfiguration& config,
261
259
return ;
262
260
}
263
261
264
- if (std::error_code ec = llvm::sys::fs::create_directories (config.tempVFSDir )) {
262
+ if (std::error_code ec = llvm::sys::fs::create_directories (config.getTempVFSDir () )) {
265
263
std::cerr << " Cannot create temp VFS directory: " << ec.message () << " \n " ;
266
264
return ;
267
265
}
268
266
269
- if (std::error_code ec = llvm::sys::fs::create_directories (config.VFSDir )) {
267
+ if (std::error_code ec = llvm::sys::fs::create_directories (config.getVFSDir () )) {
270
268
std::cerr << " Cannot create VFS directory: " << ec.message () << " \n " ;
271
269
return ;
272
270
}
273
271
274
272
// Constructing the VFS yaml file in a temp folder so that the other process doesn't read it
275
273
// while it is not complete
276
274
// TODO: Pick a more robust way to not collide with files from other processes
277
- auto tempVfsPath = config.tempVFSDir + ' /' + std::to_string (getpid ()) + " -vfs.yaml" ;
275
+ auto tempVfsPath = config.getTempVFSDir () + ' /' + std::to_string (getpid ()) + " -vfs.yaml" ;
278
276
std::error_code ec;
279
277
llvm::raw_fd_ostream fd (tempVfsPath, ec, llvm::sys::fs::OF_None);
280
278
if (ec) {
@@ -299,7 +297,7 @@ void storeRemappingForVFS(const SwiftExtractorConfiguration& config,
299
297
fd << " }\n " ;
300
298
301
299
fd.flush ();
302
- auto vfsPath = config.VFSDir + ' /' + std::to_string (getpid ()) + " -vfs.yaml" ;
300
+ auto vfsPath = config.getVFSDir () + ' /' + std::to_string (getpid ()) + " -vfs.yaml" ;
303
301
if (std::error_code ec = llvm::sys::fs::rename (tempVfsPath, vfsPath)) {
304
302
std::cerr << " Cannot move temp VFS file '" << tempVfsPath << " ' -> '" << vfsPath
305
303
<< " ': " << ec.message () << " \n " ;
@@ -308,7 +306,7 @@ void storeRemappingForVFS(const SwiftExtractorConfiguration& config,
308
306
}
309
307
310
308
std::vector<std::string> collectVFSFiles (const SwiftExtractorConfiguration& config) {
311
- auto vfsDir = config.VFSDir + ' /' ;
309
+ auto vfsDir = config.getVFSDir () + ' /' ;
312
310
if (!llvm::sys::fs::exists (vfsDir)) {
313
311
return {};
314
312
}
0 commit comments