Skip to content

Commit 736b8ac

Browse files
authored
Merge pull request #37423 from nkcsgexi/78021402
driver: emit a warning when user specified flags to disable the new driver
2 parents bf4a4af + e24eef4 commit 736b8ac

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,8 @@ WARNING(warn_drv_darwin_sdk_invalid_settings, none,
175175

176176
WARNING(warning_unsupported_driver_option,none,
177177
"option '%0' is ony supported in swift-driver", (StringRef))
178+
179+
WARNING(old_driver_deprecated,none,
180+
"legacy driver is now deprecated; consider avoiding specifying `%0`", (StringRef))
178181
#define UNDEFINE_DIAGNOSTIC_MACROS
179182
#include "DefineDiagnosticMacros.h"

test/lit.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ if not 'swift_driver' in lit_config.params:
672672
if swift_test_subset != 'only_early_swiftdriver' and\
673673
os.environ.get('SWIFT_FORCE_TEST_NEW_DRIVER') is None:
674674
config.environment['SWIFT_USE_OLD_DRIVER'] = '1'
675+
config.environment['SWIFT_AVOID_WARNING_USING_OLD_DRIVER'] = '1'
675676

676677
# Enable benchmark testing when the binary is found (has fully qualified path).
677678
if config.benchmark_o != 'Benchmark_O':

tools/driver/driver.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,28 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
134134
return true;
135135
}
136136

137-
static bool shouldDisallowNewDriver(StringRef ExecName,
137+
static bool shouldDisallowNewDriver(DiagnosticEngine &diags,
138+
StringRef ExecName,
138139
const ArrayRef<const char *> argv) {
139140
// We are not invoking the driver, so don't forward.
140141
if (ExecName != "swift" && ExecName != "swiftc") {
141142
return true;
142143
}
144+
StringRef disableArg = "-disallow-use-new-driver";
145+
StringRef disableEnv = "SWIFT_USE_OLD_DRIVER";
146+
auto shouldWarn = !llvm::sys::Process::
147+
GetEnv("SWIFT_AVOID_WARNING_USING_OLD_DRIVER").hasValue();
143148
// If user specified using the old driver, don't forward.
144-
if (llvm::find_if(argv, [](const char* arg) {
145-
return StringRef(arg) == "-disallow-use-new-driver";
149+
if (llvm::find_if(argv, [&](const char* arg) {
150+
return StringRef(arg) == disableArg;
146151
}) != argv.end()) {
152+
if (shouldWarn)
153+
diags.diagnose(SourceLoc(), diag::old_driver_deprecated, disableArg);
147154
return true;
148155
}
149-
if (llvm::sys::Process::GetEnv("SWIFT_USE_OLD_DRIVER").hasValue()) {
156+
if (llvm::sys::Process::GetEnv(disableEnv).hasValue()) {
157+
if (shouldWarn)
158+
diags.diagnose(SourceLoc(), diag::old_driver_deprecated, disableEnv);
150159
return true;
151160
}
152161
return false;
@@ -208,7 +217,7 @@ static int run_driver(StringRef ExecName,
208217

209218
// Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
210219
// or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
211-
if (!shouldDisallowNewDriver(ExecName, argv)) {
220+
if (!shouldDisallowNewDriver(Diags, ExecName, argv)) {
212221
SmallString<256> NewDriverPath(llvm::sys::path::parent_path(Path));
213222
if (appendSwiftDriverName(NewDriverPath) &&
214223
llvm::sys::fs::exists(NewDriverPath)) {

0 commit comments

Comments
 (0)