@@ -160,33 +160,44 @@ static int run_driver(StringRef ExecName,
160160 DiagnosticEngine Diags (SM);
161161 Diags.addConsumer (PDC);
162162
163+ std::string newDriverName;
164+ if (auto driverNameOp = llvm::sys::Process::GetEnv (" SWIFT_USE_NEW_DRIVER" )) {
165+ newDriverName = driverNameOp.getValue ();
166+ }
167+
163168 // Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
164169 // or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
165- if (llvm::sys::Process::GetEnv ( " SWIFT_USE_NEW_DRIVER " ) &&
170+ if (!newDriverName. empty ( ) &&
166171 (ExecName == " swift" || ExecName == " swiftc" )) {
167172 SmallString<256 > NewDriverPath (llvm::sys::path::parent_path (Path));
168- llvm::sys::path::append (NewDriverPath, " swift-driver" );
169- SmallVector<const char *, 256 > subCommandArgs;
170- // Rewrite the program argument.
171- subCommandArgs.push_back (NewDriverPath.c_str ());
172- if (ExecName == " swiftc" ) {
173- subCommandArgs.push_back (" --driver-mode=swiftc" );
173+ llvm::sys::path::append (NewDriverPath, newDriverName);
174+ if (!llvm::sys::fs::exists (NewDriverPath)) {
175+ Diags.diagnose (SourceLoc (), diag::remark_forwarding_driver_not_there,
176+ NewDriverPath);
174177 } else {
175- assert (ExecName == " swift" );
176- subCommandArgs.push_back (" --driver-mode=swift" );
178+ SmallVector<const char *, 256 > subCommandArgs;
179+ // Rewrite the program argument.
180+ subCommandArgs.push_back (NewDriverPath.c_str ());
181+ if (ExecName == " swiftc" ) {
182+ subCommandArgs.push_back (" --driver-mode=swiftc" );
183+ } else {
184+ assert (ExecName == " swift" );
185+ subCommandArgs.push_back (" --driver-mode=swift" );
186+ }
187+ subCommandArgs.insert (subCommandArgs.end (), argv.begin () + 1 , argv.end ());
188+
189+ // Execute the subcommand.
190+ subCommandArgs.push_back (nullptr );
191+ Diags.diagnose (SourceLoc (), diag::remark_forwarding_to_new_driver,
192+ NewDriverPath);
193+ ExecuteInPlace (NewDriverPath.c_str (), subCommandArgs.data ());
194+
195+ // If we reach here then an error occurred (typically a missing path).
196+ std::string ErrorString = llvm::sys::StrError ();
197+ llvm::errs () << " error: unable to invoke subcommand: " << subCommandArgs[0 ]
198+ << " (" << ErrorString << " )\n " ;
199+ return 2 ;
177200 }
178- subCommandArgs.insert (subCommandArgs.end (), argv.begin () + 1 , argv.end ());
179-
180- // Execute the subcommand.
181- subCommandArgs.push_back (nullptr );
182- Diags.diagnose (SourceLoc (), diag::remark_forwarding_to_new_driver);
183- ExecuteInPlace (NewDriverPath.c_str (), subCommandArgs.data ());
184-
185- // If we reach here then an error occurred (typically a missing path).
186- std::string ErrorString = llvm::sys::StrError ();
187- llvm::errs () << " error: unable to invoke subcommand: " << subCommandArgs[0 ]
188- << " (" << ErrorString << " )\n " ;
189- return 2 ;
190201 }
191202
192203 Driver TheDriver (Path, ExecName, argv, Diags);
0 commit comments