Skip to content

Commit da1a43c

Browse files
committed
[sourcekit] Pass -resource-dir when parsing driver arguments
... instead of overriding it after the driver is done. This improves the fidelity of anything that looks at the resource directory inside the driver or frontend argument parsing. In particular, it fixes an issue where sourcekit requests would fail if they included the -sanitize= option because the driver would fail to find the runtime libraries. Even though this should be *more correct* for all uses, in the interests of understanding all possible immediate effects of this change, I manually audited all the code that looks at the resource directory in between when it is parsed as and argument and when createCompilerInvocation returns. I claim that the only changes are: 1. The sanitizer library check that we wanted to change 2. The DWARFDebugFlags, which are for IRGen so don't affect SourceKit 3. The Migrator data paths, which also don't affect SourceKit For now, I put the -resource-dir option at the end of the arguments so that it overrides any existing option, which mimics how it behaved before. We might want to move it to the beginning so that we honour a user-provided resource directory, but that should be a separate change. rdar://40147839
1 parent 500face commit da1a43c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

test/SourceKit/Misc/ignored-flags.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ s.
1515
// RUN: %sourcekitd-test -req=complete -pos=2:3 %s -- -use-ld=blah %s | %FileCheck %s
1616
// RUN: %sourcekitd-test -req=complete -pos=2:3 %s -- -incremental %s | %FileCheck %s
1717
// RUN: %sourcekitd-test -req=complete -pos=2:3 %s -- -driver-time-compilation %s | %FileCheck %s
18+
// RUN: %sourcekitd-test -req=complete -pos=2:3 %s -- -sanitize=address,fuzzer -sanitize-coverage=func %s | %FileCheck %s
1819

1920

2021
// Mode flags

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,14 @@ resolveSymbolicLinksInInputs(FrontendInputsAndOutputs &inputsAndOutputs,
414414
}
415415

416416
bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
417-
ArrayRef<const char *> Args,
417+
ArrayRef<const char *> OrigArgs,
418418
DiagnosticEngine &Diags,
419419
StringRef UnresolvedPrimaryFile,
420420
std::string &Error) {
421+
SmallVector<const char *, 16> Args(OrigArgs.begin(), OrigArgs.end());
422+
Args.push_back("-resource-dir");
423+
Args.push_back(Impl.RuntimeResourcePath.c_str());
424+
421425
if (auto driverInvocation = driver::createCompilerInvocation(Args, Diags)) {
422426
Invocation = *driverInvocation;
423427
} else {
@@ -426,8 +430,6 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
426430
return true;
427431
}
428432

429-
Invocation.setRuntimeResourcePath(Impl.RuntimeResourcePath);
430-
431433
Invocation.getFrontendOptions().InputsAndOutputs =
432434
resolveSymbolicLinksInInputs(
433435
Invocation.getFrontendOptions().InputsAndOutputs,

0 commit comments

Comments
 (0)