Skip to content

Commit a313d4f

Browse files
authored
Merge pull request #77120 from ahoppen/sdk-symlink
[SourceKit] Check if the realpath of a module is inside the SDK to decide if it's system
2 parents 5190d98 + a287e2a commit a313d4f

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/AST/Module.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,8 +4004,27 @@ bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) con
40044004
auto sdkOrPlatform = searchPathOpts.getSDKPlatformPath(FS).value_or(sdkPath);
40054005

40064006
StringRef runtimePath = searchPathOpts.RuntimeResourcePath;
4007-
return (!runtimePath.empty() && pathStartsWith(runtimePath, modulePath)) ||
4008-
(!sdkOrPlatform.empty() && pathStartsWith(sdkOrPlatform, modulePath));
4007+
if (!runtimePath.empty() && pathStartsWith(runtimePath, modulePath)) {
4008+
return true;
4009+
}
4010+
if (!sdkOrPlatform.empty() && pathStartsWith(sdkOrPlatform, modulePath)) {
4011+
return true;
4012+
}
4013+
4014+
// `getSDKPlatformPath` returns a real path but the module might have path
4015+
// inside a symlink pointing to that real path. To catch this case, also check
4016+
// whether the module's real path is inside the SDK's real path.
4017+
llvm::SmallString<128> moduleRealPath;
4018+
if (FS->getRealPath(modulePath, moduleRealPath)) {
4019+
modulePath = moduleRealPath;
4020+
}
4021+
if (!runtimePath.empty() && pathStartsWith(runtimePath, moduleRealPath)) {
4022+
return true;
4023+
}
4024+
if (!sdkOrPlatform.empty() && pathStartsWith(sdkOrPlatform, moduleRealPath)) {
4025+
return true;
4026+
}
4027+
return false;
40094028
}
40104029

40114030
version::Version ModuleDecl::getLanguageVersionBuiltWith() const {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// UNSUPPORTED: OS=windows-msvc
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: ln -s %sdk %t/sdk
5+
// RUN: ln -s %test-resource-dir %t/test_resource_dir
6+
7+
// RUN: %batch-code-completion -sdk %t/sdk -resource-dir %t/test_resource_dir
8+
9+
#^COMPLETE^#
10+
// COMPLETE: Decl[FreeFunction]/OtherModule[Swift]/IsSystem: print

0 commit comments

Comments
 (0)