Skip to content

Commit 84afba5

Browse files
committed
driver: forward driver invocation to the new driver by default
rdar://71817843
1 parent 158427b commit 84afba5

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,5 @@ WARNING(warn_drv_darwin_sdk_invalid_settings, none,
193193
REMARK(remark_forwarding_to_new_driver, none,
194194
"new Swift driver at '%0' will be used", (StringRef))
195195

196-
REMARK(remark_forwarding_driver_not_there, none,
197-
"new Swift driver at '%0' cannot be found; C++ driver will be used", (StringRef))
198-
199196
#define UNDEFINE_DIAGNOSTIC_MACROS
200197
#include "DefineDiagnosticMacros.h"

test/Driver/opt-record.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// RUN: %target-swiftc_driver -O -wmo -save-optimization-record -save-optimization-record-passes unknown -save-optimization-record-path %t/optrecordmod-filtered.opt.yaml %s -module-name optrecordmod -o %t/opt-record 2>&1 | %FileCheck -allow-empty %s
99
// RUN: %FileCheck -allow-empty -check-prefix=YAML-FILTERED %s < %t/optrecordmod-filtered.opt.yaml
1010

11-
// CHECK-NOT: remark
11+
// CHECK-NOT: warning
12+
// CHECK-NOT: error
1213

1314
var a: Int = 1
1415

test/Driver/tools_directory.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
// RUN: %swiftc_driver -### -target x86_64-linux-unknown -tools-directory /Something/obviously/fake %s 2>&1 | %FileCheck -check-prefix BINUTILS %s
77

88
// CLANGSUB: swift
9-
// CLANGSUB-SAME: -o [[OBJECTFILE:.*]]
9+
// CLANGSUB: -o [[OBJECTFILE:.*]]
1010
// CLANGSUB: swift-autolink-extract{{(\.exe)?"?}} [[OBJECTFILE]]
11-
// CLANGSUB-SAME: -o {{"?}}[[AUTOLINKFILE:.*]]
11+
// CLANGSUB: -o {{"?}}[[AUTOLINKFILE:.*]]
1212
// CLANGSUB: {{[^ ]+(\\\\|/)}}Inputs{{/|\\\\}}fake-toolchain{{/|\\\\}}clang
1313
// CLANGSUB-DAG: [[OBJECTFILE]]
1414
// CLANGSUB-DAG: @[[AUTOLINKFILE]]
1515
// CLANGSUB: -o tools_directory
1616

1717
// BINUTILS: swift
18-
// BINUTILS-SAME: -o [[OBJECTFILE:.*]]
18+
// BINUTILS: -o [[OBJECTFILE:.*]]
1919
// BINUTILS: swift-autolink-extract{{(\.exe)?"?}} [[OBJECTFILE]]
20-
// BINUTILS-SAME: -o {{"?}}[[AUTOLINKFILE:.*]]
20+
// BINUTILS: -o {{"?}}[[AUTOLINKFILE:.*]]
2121
// BINUTILS: clang
2222
// BINUTILS-DAG: [[OBJECTFILE]]
2323
// BINUTILS-DAG: @[[AUTOLINKFILE]]
@@ -31,6 +31,6 @@
3131
// RUN: %swiftc_driver -### -target x86_64-apple-macosx10.9 -tools-directory %S/Inputs/fake-toolchain %s 2>&1 | %FileCheck -check-prefix LDSUB %s
3232

3333
// LDSUB: swift
34-
// LDSUB-SAME: -o [[OBJECTFILE:.*]]
34+
// LDSUB: -o [[OBJECTFILE:.*]]
3535
// LDSUB: {{[^ ]+(\\\\|/)}}Inputs{{/|\\\\}}fake-toolchain{{(\\\\|/)ld"?}} [[OBJECTFILE]]
3636
// LDSUB: -o tools_directory

tools/driver/driver.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
126126
return true;
127127
}
128128

129+
static bool shouldDisallowNewDriver(StringRef ExecName,
130+
const ArrayRef<const char *> argv) {
131+
// We are not invoking the driver, so don't forward.
132+
if (ExecName != "swift" && ExecName != "swiftc") {
133+
return true;
134+
}
135+
// If user specified using the old driver, don't forward.
136+
if (llvm::find_if(argv, [](const char* arg) {
137+
return StringRef(arg) == "-disallow-use-new-driver";
138+
}) != argv.end()) {
139+
return true;
140+
}
141+
if (llvm::sys::Process::GetEnv("SWIFT_USE_OLD_DRIVER").hasValue()) {
142+
return true;
143+
}
144+
return false;
145+
}
146+
129147
static int run_driver(StringRef ExecName,
130148
const ArrayRef<const char *> argv) {
131149
// Handle integrated tools.
@@ -160,23 +178,16 @@ static int run_driver(StringRef ExecName,
160178
DiagnosticEngine Diags(SM);
161179
Diags.addConsumer(PDC);
162180

163-
std::string newDriverName;
181+
std::string newDriverName = "swift-driver-new";
164182
if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) {
165183
newDriverName = driverNameOp.getValue();
166184
}
167-
auto disallowForwarding = llvm::find_if(argv, [](const char* arg) {
168-
return StringRef(arg) == "-disallow-use-new-driver";
169-
}) != argv.end();
170185
// Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
171186
// or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
172-
if (!newDriverName.empty() && !disallowForwarding &&
173-
(ExecName == "swift" || ExecName == "swiftc")) {
187+
if (!shouldDisallowNewDriver(ExecName, argv)) {
174188
SmallString<256> NewDriverPath(llvm::sys::path::parent_path(Path));
175189
llvm::sys::path::append(NewDriverPath, newDriverName);
176-
if (!llvm::sys::fs::exists(NewDriverPath)) {
177-
Diags.diagnose(SourceLoc(), diag::remark_forwarding_driver_not_there,
178-
NewDriverPath);
179-
} else {
190+
if (llvm::sys::fs::exists(NewDriverPath)) {
180191
SmallVector<const char *, 256> subCommandArgs;
181192
// Rewrite the program argument.
182193
subCommandArgs.push_back(NewDriverPath.c_str());

0 commit comments

Comments
 (0)