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.
This commit is contained in:
Alexey Tsvetkov
2019-03-20 04:53:42 +03:00
parent 0687b8eac3
commit db6a7779b8
@@ -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