@@ -148,6 +148,26 @@ static bool shouldDisallowNewDriver(StringRef ExecName,
148
148
return false ;
149
149
}
150
150
151
+ static bool appendSwiftDriverName (SmallString<256 > &buffer) {
152
+ assert (llvm::sys::fs::exists (buffer));
153
+ if (auto driverNameOp = llvm::sys::Process::GetEnv (" SWIFT_USE_NEW_DRIVER" )) {
154
+ llvm::sys::path::append (buffer, *driverNameOp);
155
+ return true ;
156
+ }
157
+ #ifdef __APPLE__
158
+ // FIXME: use swift-driver as the default driver for all platforms.
159
+ llvm::sys::path::append (buffer, " swift-driver" );
160
+ if (llvm::sys::fs::exists (buffer)) {
161
+ return true ;
162
+ }
163
+ llvm::sys::path::remove_filename (buffer);
164
+ llvm::sys::path::append (buffer, " swift-driver-new" );
165
+ return true ;
166
+ #else
167
+ return false ;
168
+ #endif
169
+ }
170
+
151
171
static int run_driver (StringRef ExecName,
152
172
const ArrayRef<const char *> argv) {
153
173
// Handle integrated tools.
@@ -182,16 +202,12 @@ static int run_driver(StringRef ExecName,
182
202
DiagnosticEngine Diags (SM);
183
203
Diags.addConsumer (PDC);
184
204
185
- std::string newDriverName = " swift-driver-new" ;
186
- if (auto driverNameOp = llvm::sys::Process::GetEnv (" SWIFT_USE_NEW_DRIVER" )) {
187
- newDriverName = driverNameOp.getValue ();
188
- }
189
205
// Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
190
206
// or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
191
207
if (!shouldDisallowNewDriver (ExecName, argv)) {
192
208
SmallString<256 > NewDriverPath (llvm::sys::path::parent_path (Path));
193
- llvm::sys::path::append ( NewDriverPath, newDriverName);
194
- if ( llvm::sys::fs::exists (NewDriverPath)) {
209
+ if ( appendSwiftDriverName ( NewDriverPath) &&
210
+ llvm::sys::fs::exists (NewDriverPath)) {
195
211
SmallVector<const char *, 256 > subCommandArgs;
196
212
// Rewrite the program argument.
197
213
subCommandArgs.push_back (NewDriverPath.c_str ());
0 commit comments