Skip to content

Commit 889d9a7

Browse files
authored
Merge pull request #34623 from nkcsgexi/allow-driver-name
driver: allow SWIFT_USE_NEW_DRIVER to specify a driver executable name
2 parents 1f71144 + f8577b2 commit 889d9a7

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ WARNING(warn_drv_darwin_sdk_invalid_settings, none,
190190
"SDK settings were ignored because 'SDKSettings.json' could not be parsed",
191191
())
192192

193-
REMARK(remark_forwarding_to_new_driver, none, "new Swift driver will be used", ())
193+
REMARK(remark_forwarding_to_new_driver, none,
194+
"new Swift driver at '%0' will be used", (StringRef))
195+
196+
REMARK(remark_forwarding_driver_not_there, none,
197+
"new Swift driver at '%0' cannot be found; C++ driver will be used", (StringRef))
194198

195199
#define UNDEFINE_DIAGNOSTIC_MACROS
196200
#include "DefineDiagnosticMacros.h"

tools/driver/driver.cpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)