Skip to content

Commit ec7934c

Browse files
committed
Add symlinks for the legacy driver invocation (for emergency fallback invoked from 'swift-driver')
1 parent 53b2111 commit ec7934c

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lib/Driver/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ void Driver::parseDriverKind(ArrayRef<const char *> Args) {
9999
llvm::StringSwitch<llvm::Optional<DriverKind>>(DriverName)
100100
.Case("swift", DriverKind::Interactive)
101101
.Case("swiftc", DriverKind::Batch)
102+
.Case("swift-legacy-driver", DriverKind::Interactive)
103+
.Case("swiftc-legacy-driver", DriverKind::Batch)
102104
.Case("sil-opt", DriverKind::SILOpt)
103105
.Case("sil-func-extractor", DriverKind::SILFuncExtractor)
104106
.Case("sil-nm", DriverKind::SILNM)

lib/DriverTool/driver.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,25 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
167167
static 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;
173-
}
174170
StringRef disableArg = "-disallow-use-new-driver";
175171
StringRef disableEnv = "SWIFT_USE_OLD_DRIVER";
176172
auto shouldWarn = !llvm::sys::Process::
177173
GetEnv("SWIFT_AVOID_WARNING_USING_OLD_DRIVER").has_value();
174+
175+
// We explicitly are on the fallback to the legacy driver from the new driver.
176+
// Do not forward.
177+
if (ExecName == "swift-legacy-driver" ||
178+
ExecName == "swiftc-legacy-driver") {
179+
if (shouldWarn)
180+
diags.diagnose(SourceLoc(), diag::old_driver_deprecated, disableArg);
181+
return true;
182+
}
183+
184+
// We are not invoking the driver, so don't forward.
185+
if (ExecName != "swift" && ExecName != "swiftc") {
186+
return true;
187+
}
188+
178189
// If user specified using the old driver, don't forward.
179190
if (llvm::find_if(argv, [&](const char* arg) {
180191
return StringRef(arg) == disableArg;
@@ -345,6 +356,15 @@ static int run_driver(StringRef ExecName,
345356
}
346357
}
347358

359+
// We are in the fallback to legacy driver mode.
360+
// Now that we have determined above that we are not going to
361+
// forward the invocation to the new driver, ensure the rest of the
362+
// downstream driver execution refers to itself by the appropriate name.
363+
if (ExecName == "swift-legacy-driver")
364+
ExecName = "swift";
365+
else if (ExecName == "swiftc-legacy-driver")
366+
ExecName = "swiftc";
367+
348368
Driver TheDriver(Path, ExecName, argv, Diags);
349369
switch (TheDriver.getDriverKind()) {
350370
case Driver::DriverKind::SILOpt:

tools/driver/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,20 @@ if(EXISTS "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-driver${CMAKE_EXECUTABLE_SUFFIX}
8585
SOURCE "swift-driver${CMAKE_EXECUTABLE_SUFFIX}"
8686
DESTINATION "swift${CMAKE_EXECUTABLE_SUFFIX}"
8787
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
88-
8988
swift_create_post_build_symlink(swift-frontend
9089
SOURCE "swift-driver${CMAKE_EXECUTABLE_SUFFIX}"
9190
DESTINATION "swiftc${CMAKE_EXECUTABLE_SUFFIX}"
9291
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
92+
93+
message(STATUS "Pointing 'swift-legacy-driver' and 'swiftc-legacy-driver' symlinks at 'swift-frontend'.")
94+
swift_create_post_build_symlink(swift-frontend
95+
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
96+
DESTINATION "swift-legacy-driver${CMAKE_EXECUTABLE_SUFFIX}"
97+
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
98+
swift_create_post_build_symlink(swift-frontend
99+
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
100+
DESTINATION "swiftc-legacy-driver${CMAKE_EXECUTABLE_SUFFIX}"
101+
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
93102
else()
94103
message(STATUS "Pointing 'swift' and 'swiftc' symlinks at 'swift-frontend' - no early SwiftDriver build found.")
95104
swift_create_post_build_symlink(swift-frontend
@@ -207,4 +216,10 @@ if(EXISTS "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-driver${CMAKE_EXECUTABLE_SUFFIX}
207216
swift_install_in_component(PROGRAMS "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-help${CMAKE_EXECUTABLE_SUFFIX}"
208217
DESTINATION "bin"
209218
COMPONENT compiler)
219+
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc-legacy-driver${CMAKE_EXECUTABLE_SUFFIX}"
220+
DESTINATION "bin"
221+
COMPONENT compiler)
222+
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-legacy-driver${CMAKE_EXECUTABLE_SUFFIX}"
223+
DESTINATION "bin"
224+
COMPONENT compiler)
210225
endif()

0 commit comments

Comments
 (0)