Skip to content

driver: prefer a new driver name as swift-driver instead of swift-driver-new #36388

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 2 commits into from
Mar 15, 2021
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
28 changes: 22 additions & 6 deletions tools/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ static bool shouldDisallowNewDriver(StringRef ExecName,
return false;
}

static bool appendSwiftDriverName(SmallString<256> &buffer) {
assert(llvm::sys::fs::exists(buffer));
if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) {
llvm::sys::path::append(buffer, *driverNameOp);
return true;
}
#ifdef __APPLE__
// FIXME: use swift-driver as the default driver for all platforms.
llvm::sys::path::append(buffer, "swift-driver");
if (llvm::sys::fs::exists(buffer)) {
return true;
}
llvm::sys::path::remove_filename(buffer);
llvm::sys::path::append(buffer, "swift-driver-new");
return true;
#else
return false;
#endif
}

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

std::string newDriverName = "swift-driver-new";
if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) {
newDriverName = driverNameOp.getValue();
}
// 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 (!shouldDisallowNewDriver(ExecName, argv)) {
SmallString<256> NewDriverPath(llvm::sys::path::parent_path(Path));
llvm::sys::path::append(NewDriverPath, newDriverName);
if (llvm::sys::fs::exists(NewDriverPath)) {
if (appendSwiftDriverName(NewDriverPath) &&
llvm::sys::fs::exists(NewDriverPath)) {
SmallVector<const char *, 256> subCommandArgs;
// Rewrite the program argument.
subCommandArgs.push_back(NewDriverPath.c_str());
Expand Down
9 changes: 7 additions & 2 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,6 @@ class BuildScriptInvocation(object):
product_classes = []
if self.args.build_swiftpm:
product_classes.append(products.SwiftPM)
if self.args.build_swift_driver or self.args.install_swift_driver:
product_classes.append(products.SwiftDriver)
if self.args.build_swiftsyntax:
product_classes.append(products.SwiftSyntax)
if self.args.build_skstresstester:
Expand All @@ -908,6 +906,13 @@ class BuildScriptInvocation(object):
product_classes.append(products.SwiftInspect)
if self.args.tsan_libdispatch_test:
product_classes.append(products.TSanLibDispatch)

# Keep SwiftDriver at last.
# swift-driver's integration with the build scripts is not fully
# supported. Using swift-driver to build these products may hit
# failures.
if self.args.build_swift_driver or self.args.install_swift_driver:
product_classes.append(products.SwiftDriver)
# Sanity check that all of our non-impl classes are actually
# not build_script_impl products.
for prod in product_classes:
Expand Down