Skip to content

driver: forward driver invocation to the new driver by default #34894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/swift/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,5 @@ WARNING(warn_drv_darwin_sdk_invalid_settings, none,
REMARK(remark_forwarding_to_new_driver, none,
"new Swift driver at '%0' will be used", (StringRef))

REMARK(remark_forwarding_driver_not_there, none,
"new Swift driver at '%0' cannot be found; C++ driver will be used", (StringRef))

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
3 changes: 2 additions & 1 deletion test/Driver/opt-record.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// 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
// RUN: %FileCheck -allow-empty -check-prefix=YAML-FILTERED %s < %t/optrecordmod-filtered.opt.yaml

// CHECK-NOT: remark
// CHECK-NOT: warning
// CHECK-NOT: error

var a: Int = 1

Expand Down
10 changes: 5 additions & 5 deletions test/Driver/tools_directory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
// RUN: %swiftc_driver -### -target x86_64-linux-unknown -tools-directory /Something/obviously/fake %s 2>&1 | %FileCheck -check-prefix BINUTILS %s

// CLANGSUB: swift
// CLANGSUB-SAME: -o [[OBJECTFILE:.*]]
// CLANGSUB: -o [[OBJECTFILE:.*]]
// CLANGSUB: swift-autolink-extract{{(\.exe)?"?}} [[OBJECTFILE]]
// CLANGSUB-SAME: -o {{"?}}[[AUTOLINKFILE:.*]]
// CLANGSUB: -o {{"?}}[[AUTOLINKFILE:.*]]
// CLANGSUB: {{[^ ]+(\\\\|/)}}Inputs{{/|\\\\}}fake-toolchain{{/|\\\\}}clang
// CLANGSUB-DAG: [[OBJECTFILE]]
// CLANGSUB-DAG: @[[AUTOLINKFILE]]
// CLANGSUB: -o tools_directory

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

// LDSUB: swift
// LDSUB-SAME: -o [[OBJECTFILE:.*]]
// LDSUB: -o [[OBJECTFILE:.*]]
// LDSUB: {{[^ ]+(\\\\|/)}}Inputs{{/|\\\\}}fake-toolchain{{(\\\\|/)ld"?}} [[OBJECTFILE]]
// LDSUB: -o tools_directory
31 changes: 21 additions & 10 deletions tools/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
return true;
}

static bool shouldDisallowNewDriver(StringRef ExecName,
const ArrayRef<const char *> argv) {
// We are not invoking the driver, so don't forward.
if (ExecName != "swift" && ExecName != "swiftc") {
return true;
}
// If user specified using the old driver, don't forward.
if (llvm::find_if(argv, [](const char* arg) {
return StringRef(arg) == "-disallow-use-new-driver";
}) != argv.end()) {
return true;
}
if (llvm::sys::Process::GetEnv("SWIFT_USE_OLD_DRIVER").hasValue()) {
return true;
}
return false;
}

static int run_driver(StringRef ExecName,
const ArrayRef<const char *> argv) {
// Handle integrated tools.
Expand Down Expand Up @@ -160,23 +178,16 @@ static int run_driver(StringRef ExecName,
DiagnosticEngine Diags(SM);
Diags.addConsumer(PDC);

std::string newDriverName;
std::string newDriverName = "swift-driver-new";
if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) {
newDriverName = driverNameOp.getValue();
}
auto disallowForwarding = llvm::find_if(argv, [](const char* arg) {
return StringRef(arg) == "-disallow-use-new-driver";
}) != argv.end();
// Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
// or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
if (!newDriverName.empty() && !disallowForwarding &&
(ExecName == "swift" || ExecName == "swiftc")) {
if (!shouldDisallowNewDriver(ExecName, argv)) {
SmallString<256> NewDriverPath(llvm::sys::path::parent_path(Path));
llvm::sys::path::append(NewDriverPath, newDriverName);
if (!llvm::sys::fs::exists(NewDriverPath)) {
Diags.diagnose(SourceLoc(), diag::remark_forwarding_driver_not_there,
NewDriverPath);
} else {
if (llvm::sys::fs::exists(NewDriverPath)) {
SmallVector<const char *, 256> subCommandArgs;
// Rewrite the program argument.
subCommandArgs.push_back(NewDriverPath.c_str());
Expand Down