From db6a7779b841995a68a7dff25bf382acbd7ef2fb Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Wed, 20 Mar 2019 04:53:42 +0300 Subject: [PATCH] Check friend jars paths for exact match Fixes CompileKotlinAgainstCustomBinariesTest.testInternalFromForeignModule after unifying non-build-file mode and build-file mode. Previously when the compiler was run without -Xbuild-file argument, it was not using modules internally, so we were not checking if internal descriptors were contained in destination dir of current module (without -Xbuild-file we were returning false at `if (modules.isEmpty()) return false` in `ModuleVisibilityHelperImpl#isInFriendModule`). After switching to using modules for CLI compilation, any jar file contained in destination dir was considered friend, because only a prefix was checked. --- .../load/kotlin/moduleVisibilityUtils.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt index 4b3693cb13a..a5f850805f9 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt @@ -42,8 +42,8 @@ interface ModuleVisibilityManager { } } -fun isContainedByCompiledPartOfOurModule(descriptor: DeclarationDescriptor, outDirectory: File?): Boolean { - if (outDirectory == null) return false +fun isContainedByCompiledPartOfOurModule(descriptor: DeclarationDescriptor, friendPath: File?): Boolean { + if (friendPath == null) return false val packageFragment = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor::class.java, false) if (packageFragment !is LazyJavaPackageFragment) return false @@ -66,12 +66,16 @@ fun isContainedByCompiledPartOfOurModule(descriptor: DeclarationDescriptor, outD if (binaryClass is VirtualFileKotlinClass) { val file = binaryClass.file - val ioFile = when (file.fileSystem.protocol) { - StandardFileSystems.FILE_PROTOCOL -> VfsUtilCore.virtualToIoFile(file) - StandardFileSystems.JAR_PROTOCOL -> VfsUtilCore.getVirtualFileForJar(file)?.let(VfsUtilCore::virtualToIoFile) - else -> null + when (file.fileSystem.protocol) { + StandardFileSystems.FILE_PROTOCOL -> { + val ioFile = VfsUtilCore.virtualToIoFile(file) + return ioFile.toPath().startsWith(friendPath.toPath()) + } + StandardFileSystems.JAR_PROTOCOL -> { + val ioFile = VfsUtilCore.getVirtualFileForJar(file)?.let(VfsUtilCore::virtualToIoFile) + return ioFile != null && ioFile.toPath() == friendPath.toPath() + } } - return ioFile != null && ioFile.toPath().startsWith(outDirectory.toPath()) } return false