@@ -126,24 +126,6 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
126
126
return true ;
127
127
}
128
128
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
-
147
129
static int run_driver (StringRef ExecName,
148
130
const ArrayRef<const char *> argv) {
149
131
// Handle integrated tools.
@@ -178,16 +160,23 @@ static int run_driver(StringRef ExecName,
178
160
DiagnosticEngine Diags (SM);
179
161
Diags.addConsumer (PDC);
180
162
181
- std::string newDriverName = " swift-driver-new " ;
163
+ std::string newDriverName;
182
164
if (auto driverNameOp = llvm::sys::Process::GetEnv (" SWIFT_USE_NEW_DRIVER" )) {
183
165
newDriverName = driverNameOp.getValue ();
184
166
}
167
+ auto disallowForwarding = llvm::find_if (argv, [](const char * arg) {
168
+ return StringRef (arg) == " -disallow-use-new-driver" ;
169
+ }) != argv.end ();
185
170
// Forwarding calls to the swift driver if the C++ driver is invoked as `swift`
186
171
// or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined.
187
- if (!shouldDisallowNewDriver (ExecName, argv)) {
172
+ if (!newDriverName.empty () && !disallowForwarding &&
173
+ (ExecName == " swift" || ExecName == " swiftc" )) {
188
174
SmallString<256 > NewDriverPath (llvm::sys::path::parent_path (Path));
189
175
llvm::sys::path::append (NewDriverPath, newDriverName);
190
- if (llvm::sys::fs::exists (NewDriverPath)) {
176
+ if (!llvm::sys::fs::exists (NewDriverPath)) {
177
+ Diags.diagnose (SourceLoc (), diag::remark_forwarding_driver_not_there,
178
+ NewDriverPath);
179
+ } else {
191
180
SmallVector<const char *, 256 > subCommandArgs;
192
181
// Rewrite the program argument.
193
182
subCommandArgs.push_back (NewDriverPath.c_str ());
0 commit comments