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