@@ -133,7 +133,7 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
133
133
// If we are not run as 'swift', don't do anything special. This doesn't work
134
134
// with symlinks with alternate names, but we can't detect 'swift' vs 'swiftc'
135
135
// if we try and resolve using the actual executable path.
136
- if (ExecName != " swift" )
136
+ if (ExecName != " swift" && ExecName != " swift-legacy-driver " )
137
137
return false ;
138
138
139
139
// If there are no program arguments, always invoke as normal.
@@ -167,14 +167,30 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
167
167
static bool shouldDisallowNewDriver (DiagnosticEngine &diags,
168
168
StringRef ExecName,
169
169
const ArrayRef<const char *> argv) {
170
- // We are not invoking the driver, so don't forward.
171
- if (ExecName != " swift" && ExecName != " swiftc" ) {
172
- return true ;
170
+ // We are expected to use the legacy driver to `exec` an overload
171
+ // for testing purposes.
172
+ if (llvm::sys::Process::GetEnv (" SWIFT_OVERLOAD_DRIVER" ).has_value ()) {
173
+ return false ;
173
174
}
174
175
StringRef disableArg = " -disallow-use-new-driver" ;
175
176
StringRef disableEnv = " SWIFT_USE_OLD_DRIVER" ;
176
177
auto shouldWarn = !llvm::sys::Process::
177
178
GetEnv (" SWIFT_AVOID_WARNING_USING_OLD_DRIVER" ).has_value ();
179
+
180
+ // We explicitly are on the fallback to the legacy driver from the new driver.
181
+ // Do not forward.
182
+ if (ExecName == " swift-legacy-driver" ||
183
+ ExecName == " swiftc-legacy-driver" ) {
184
+ if (shouldWarn)
185
+ diags.diagnose (SourceLoc (), diag::old_driver_deprecated, disableArg);
186
+ return true ;
187
+ }
188
+
189
+ // We are not invoking the driver, so don't forward.
190
+ if (ExecName != " swift" && ExecName != " swiftc" ) {
191
+ return true ;
192
+ }
193
+
178
194
// If user specified using the old driver, don't forward.
179
195
if (llvm::find_if (argv, [&](const char * arg) {
180
196
return StringRef (arg) == disableArg;
@@ -193,7 +209,7 @@ static bool shouldDisallowNewDriver(DiagnosticEngine &diags,
193
209
194
210
static bool appendSwiftDriverName (SmallString<256 > &buffer) {
195
211
assert (llvm::sys::fs::exists (buffer));
196
- if (auto driverNameOp = llvm::sys::Process::GetEnv (" SWIFT_USE_NEW_DRIVER " )) {
212
+ if (auto driverNameOp = llvm::sys::Process::GetEnv (" SWIFT_OVERLOAD_DRIVER " )) {
197
213
llvm::sys::path::append (buffer, *driverNameOp);
198
214
return true ;
199
215
}
@@ -312,8 +328,7 @@ static int run_driver(StringRef ExecName,
312
328
subCommandArgs.push_back (DriverModeArg.data ());
313
329
} else if (ExecName == " swiftc" ) {
314
330
subCommandArgs.push_back (" --driver-mode=swiftc" );
315
- } else {
316
- assert (ExecName == " swift" );
331
+ } else if (ExecName == " swift" ) {
317
332
subCommandArgs.push_back (" --driver-mode=swift" );
318
333
}
319
334
// Push these non-op frontend arguments so the build log can indicate
@@ -344,7 +359,16 @@ static int run_driver(StringRef ExecName,
344
359
return 2 ;
345
360
}
346
361
}
347
-
362
+
363
+ // We are in the fallback to legacy driver mode.
364
+ // Now that we have determined above that we are not going to
365
+ // forward the invocation to the new driver, ensure the rest of the
366
+ // downstream driver execution refers to itself by the appropriate name.
367
+ if (ExecName == " swift-legacy-driver" )
368
+ ExecName = " swift" ;
369
+ else if (ExecName == " swiftc-legacy-driver" )
370
+ ExecName = " swiftc" ;
371
+
348
372
Driver TheDriver (Path, ExecName, argv, Diags);
349
373
switch (TheDriver.getDriverKind ()) {
350
374
case Driver::DriverKind::SILOpt:
0 commit comments