Skip to content

Commit 5e2bd57

Browse files
committed
driver: prefer a new driver name as swift-driver instead of swift-driver-new
rdar://75275788
1 parent f5e32aa commit 5e2bd57

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tools/driver/driver.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ static bool shouldDisallowNewDriver(StringRef ExecName,
144144
return false;
145145
}
146146

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+
147167
static int run_driver(StringRef ExecName,
148168
const ArrayRef<const char *> argv) {
149169
// Handle integrated tools.
@@ -178,16 +198,12 @@ static int run_driver(StringRef ExecName,
178198
DiagnosticEngine Diags(SM);
179199
Diags.addConsumer(PDC);
180200

181-
std::string newDriverName = "swift-driver-new";
182-
if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) {
183-
newDriverName = driverNameOp.getValue();
184-
}
185201
// Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
186202
// or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
187203
if (!shouldDisallowNewDriver(ExecName, argv)) {
188204
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)) {
191207
SmallVector<const char *, 256> subCommandArgs;
192208
// Rewrite the program argument.
193209
subCommandArgs.push_back(NewDriverPath.c_str());

0 commit comments

Comments
 (0)