Skip to content

Commit 7e6b5b2

Browse files
committed
[Driver] Don't validate arclite linking if the driver is only set up to get the swift-frontend invocation
If the driver is only set up to get the frontend invocation (e.g. from sourcekitd), don't validate that we can link against ARCLite because a) we don't care about link-time when we are only interested in the frontend invocation b) finding arclite might cause us to find clang using xcrun which in turn can cause sourcekitd to hang. rdar://50659268
1 parent e1e0f54 commit 7e6b5b2

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

include/swift/Driver/Driver.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ class Driver {
200200
/// Indicates whether the driver should check that the input files exist.
201201
bool CheckInputFilesExist = true;
202202

203+
/// Indicates that this driver never actually executes any commands but is
204+
/// just set up to retrieve the swift-frontend invocation that would be
205+
/// executed during compilation.
206+
bool IsDummyDriverForFrontendInvocation = false;
207+
203208
public:
204209
Driver(StringRef DriverExecutable, StringRef Name,
205210
ArrayRef<const char *> Args, DiagnosticEngine &Diags);
@@ -226,6 +231,14 @@ class Driver {
226231

227232
void setCheckInputFilesExist(bool Value) { CheckInputFilesExist = Value; }
228233

234+
bool isDummyDriverForFrontendInvocation() const {
235+
return IsDummyDriverForFrontendInvocation;
236+
}
237+
238+
void setIsDummyDriverForFrontendInvocation(bool Value) {
239+
IsDummyDriverForFrontendInvocation = Value;
240+
}
241+
229242
/// Creates an appropriate ToolChain for a given driver, given the target
230243
/// specified in \p Args (or the default target). Sets the value of \c
231244
/// DefaultTargetTriple from \p Args as a side effect.

lib/Driver/DarwinToolChains.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,15 @@ void
901901
toolchains::Darwin::validateArguments(DiagnosticEngine &diags,
902902
const llvm::opt::ArgList &args,
903903
StringRef defaultTarget) const {
904-
// Validating arclite library path when link-objc-runtime.
905-
validateLinkObjcRuntimeARCLiteLib(*this, diags, args);
906-
904+
if (!getDriver().isDummyDriverForFrontendInvocation()) {
905+
// Validating arclite library path when link-objc-runtime.
906+
// If the driver is just set up to retrieve the swift-frontend invocation,
907+
// we don't care about link-time, so we can skip this step, which may be
908+
// expensive since it might call to `xcrun` to find `clang` and `arclite`
909+
// relative to `clang`.
910+
validateLinkObjcRuntimeARCLiteLib(*this, diags, args);
911+
}
912+
907913
// Validating apple platforms deployment targets.
908914
validateDeploymentTarget(*this, diags, args);
909915
validateTargetVariant(*this, diags, args, defaultTarget);

lib/Driver/FrontendUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ bool swift::driver::getSingleFrontendInvocationFromDriverArguments(
7575
// CompilerInvocation may wish to remap inputs to source buffers.
7676
TheDriver.setCheckInputFilesExist(false);
7777

78+
TheDriver.setIsDummyDriverForFrontendInvocation(true);
79+
7880
std::unique_ptr<llvm::opt::InputArgList> ArgList =
7981
TheDriver.parseArgStrings(ArrayRef<const char *>(Args).slice(1));
8082
if (Diags.hadAnyError())

0 commit comments

Comments
 (0)