Skip to content

Commit 2a1a7a8

Browse files
authored
Merge pull request #36388 from nkcsgexi/75275788
driver: prefer a new driver name as swift-driver instead of swift-driver-new
2 parents ddb96cd + b948f20 commit 2a1a7a8

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

tools/driver/driver.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ static bool shouldDisallowNewDriver(StringRef ExecName,
148148
return false;
149149
}
150150

151+
static bool appendSwiftDriverName(SmallString<256> &buffer) {
152+
assert(llvm::sys::fs::exists(buffer));
153+
if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) {
154+
llvm::sys::path::append(buffer, *driverNameOp);
155+
return true;
156+
}
157+
#ifdef __APPLE__
158+
// FIXME: use swift-driver as the default driver for all platforms.
159+
llvm::sys::path::append(buffer, "swift-driver");
160+
if (llvm::sys::fs::exists(buffer)) {
161+
return true;
162+
}
163+
llvm::sys::path::remove_filename(buffer);
164+
llvm::sys::path::append(buffer, "swift-driver-new");
165+
return true;
166+
#else
167+
return false;
168+
#endif
169+
}
170+
151171
static int run_driver(StringRef ExecName,
152172
const ArrayRef<const char *> argv) {
153173
// Handle integrated tools.
@@ -182,16 +202,12 @@ static int run_driver(StringRef ExecName,
182202
DiagnosticEngine Diags(SM);
183203
Diags.addConsumer(PDC);
184204

185-
std::string newDriverName = "swift-driver-new";
186-
if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) {
187-
newDriverName = driverNameOp.getValue();
188-
}
189205
// Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
190206
// or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
191207
if (!shouldDisallowNewDriver(ExecName, argv)) {
192208
SmallString<256> NewDriverPath(llvm::sys::path::parent_path(Path));
193-
llvm::sys::path::append(NewDriverPath, newDriverName);
194-
if (llvm::sys::fs::exists(NewDriverPath)) {
209+
if (appendSwiftDriverName(NewDriverPath) &&
210+
llvm::sys::fs::exists(NewDriverPath)) {
195211
SmallVector<const char *, 256> subCommandArgs;
196212
// Rewrite the program argument.
197213
subCommandArgs.push_back(NewDriverPath.c_str());

utils/build-script

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,6 @@ class BuildScriptInvocation(object):
886886
product_classes = []
887887
if self.args.build_swiftpm:
888888
product_classes.append(products.SwiftPM)
889-
if self.args.build_swift_driver or self.args.install_swift_driver:
890-
product_classes.append(products.SwiftDriver)
891889
if self.args.build_swiftsyntax:
892890
product_classes.append(products.SwiftSyntax)
893891
if self.args.build_skstresstester:
@@ -908,6 +906,13 @@ class BuildScriptInvocation(object):
908906
product_classes.append(products.SwiftInspect)
909907
if self.args.tsan_libdispatch_test:
910908
product_classes.append(products.TSanLibDispatch)
909+
910+
# Keep SwiftDriver at last.
911+
# swift-driver's integration with the build scripts is not fully
912+
# supported. Using swift-driver to build these products may hit
913+
# failures.
914+
if self.args.build_swift_driver or self.args.install_swift_driver:
915+
product_classes.append(products.SwiftDriver)
911916
# Sanity check that all of our non-impl classes are actually
912917
# not build_script_impl products.
913918
for prod in product_classes:

0 commit comments

Comments
 (0)