@@ -133,7 +133,7 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
133133 // If we are not run as 'swift', don't do anything special. This doesn't work
134134 // with symlinks with alternate names, but we can't detect 'swift' vs 'swiftc'
135135 // if we try and resolve using the actual executable path.
136- if (ExecName != " swift" )
136+ if (ExecName != " swift" && ExecName != " swift-legacy-driver " )
137137 return false ;
138138
139139 // If there are no program arguments, always invoke as normal.
@@ -167,14 +167,30 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
167167static bool shouldDisallowNewDriver (DiagnosticEngine &diags,
168168 StringRef ExecName,
169169 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 ;
173174 }
174175 StringRef disableArg = " -disallow-use-new-driver" ;
175176 StringRef disableEnv = " SWIFT_USE_OLD_DRIVER" ;
176177 auto shouldWarn = !llvm::sys::Process::
177178 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+
178194 // If user specified using the old driver, don't forward.
179195 if (llvm::find_if (argv, [&](const char * arg) {
180196 return StringRef (arg) == disableArg;
@@ -193,7 +209,7 @@ static bool shouldDisallowNewDriver(DiagnosticEngine &diags,
193209
194210static bool appendSwiftDriverName (SmallString<256 > &buffer) {
195211 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 " )) {
197213 llvm::sys::path::append (buffer, *driverNameOp);
198214 return true ;
199215 }
@@ -312,8 +328,7 @@ static int run_driver(StringRef ExecName,
312328 subCommandArgs.push_back (DriverModeArg.data ());
313329 } else if (ExecName == " swiftc" ) {
314330 subCommandArgs.push_back (" --driver-mode=swiftc" );
315- } else {
316- assert (ExecName == " swift" );
331+ } else if (ExecName == " swift" ) {
317332 subCommandArgs.push_back (" --driver-mode=swift" );
318333 }
319334 // Push these non-op frontend arguments so the build log can indicate
@@ -344,7 +359,16 @@ static int run_driver(StringRef ExecName,
344359 return 2 ;
345360 }
346361 }
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+
348372 Driver TheDriver (Path, ExecName, argv, Diags);
349373 switch (TheDriver.getDriverKind ()) {
350374 case Driver::DriverKind::SILOpt:
0 commit comments