IDE: Add a flag to disable native libraries propagation
This commit is contained in:
+36
-2
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.ide.konan.gradle
|
|||||||
import com.intellij.openapi.roots.DependencyScope
|
import com.intellij.openapi.roots.DependencyScope
|
||||||
import org.jetbrains.kotlin.gradle.ModuleInfo
|
import org.jetbrains.kotlin.gradle.ModuleInfo
|
||||||
import org.jetbrains.kotlin.gradle.checkProjectStructure
|
import org.jetbrains.kotlin.gradle.checkProjectStructure
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase
|
|
||||||
import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion
|
import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion
|
||||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -63,12 +62,47 @@ class GradleNativeLibrariesPropagationTest : TestCaseWithFakeKotlinNative() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCommonIOSWithDisabledPropagation() {
|
||||||
|
configureProject()
|
||||||
|
importProject()
|
||||||
|
|
||||||
|
// No dependencies should be propagated.
|
||||||
|
checkProjectStructure(
|
||||||
|
myProject,
|
||||||
|
projectPath,
|
||||||
|
exhaustiveModuleList = false,
|
||||||
|
exhaustiveSourceSourceRootList = false,
|
||||||
|
exhaustiveDependencyList = false,
|
||||||
|
exhaustiveTestsList = false
|
||||||
|
) {
|
||||||
|
|
||||||
|
module("project_commonMain") {
|
||||||
|
noPlatformLibrary("Foundation")
|
||||||
|
noPlatformLibrary("CFNetwork")
|
||||||
|
noPlatformLibrary("WatchKit")
|
||||||
|
}
|
||||||
|
|
||||||
|
module("project_appleMain") {
|
||||||
|
noPlatformLibrary("Foundation")
|
||||||
|
noPlatformLibrary("CFNetwork")
|
||||||
|
noPlatformLibrary("WatchKit")
|
||||||
|
}
|
||||||
|
|
||||||
|
module("project_iosMain") {
|
||||||
|
noPlatformLibrary("Foundation")
|
||||||
|
noPlatformLibrary("CFNetwork")
|
||||||
|
noPlatformLibrary("WatchKit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val ModuleInfo.kotlinVersion: String
|
private val ModuleInfo.kotlinVersion: String
|
||||||
get() = requireNotNull(module.externalCompilerVersion) { "External compiler version should not be null" }
|
get() = requireNotNull(module.externalCompilerVersion) { "External compiler version should not be null" }
|
||||||
|
|
||||||
private fun ModuleInfo.noPlatformLibrary(libraryName: String, targets: Collection<String> = testedTargets) {
|
private fun ModuleInfo.noPlatformLibrary(libraryName: String, targets: Collection<String> = testedTargets) {
|
||||||
targets.forEach { target ->
|
targets.forEach { target ->
|
||||||
assertNoDepForModule(module.name,"Kotlin/Native $kotlinVersion - $libraryName [$target]")
|
assertNoLibraryDepForModule(module.name, "Kotlin/Native $kotlinVersion - $libraryName [$target]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-8
@@ -577,12 +577,13 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
val mergedDependencies = LinkedHashSet<KotlinDependency>().apply {
|
val mergedDependencies = LinkedHashSet<KotlinDependency>().apply {
|
||||||
addAll(sourceSet.dependencies.mapNotNull { mppModel.dependencyMap[it] })
|
addAll(sourceSet.dependencies.mapNotNull { mppModel.dependencyMap[it] })
|
||||||
dependeeSourceSets.flatMapTo(this) { it.dependencies.mapNotNull { mppModel.dependencyMap[it] } }
|
dependeeSourceSets.flatMapTo(this) { it.dependencies.mapNotNull { mppModel.dependencyMap[it] } }
|
||||||
if (sourceSet.actualPlatforms.getSinglePlatform() == KotlinPlatform.NATIVE) {
|
if (mppModel.extraFeatures.isNativeDependencyPropagationEnabled
|
||||||
sourceSetToCompilations[sourceSet.name]
|
&& mppModel.extraFeatures.isHMPPEnabled
|
||||||
?.takeIf { it.size > 1 }
|
&& sourceSet.actualPlatforms.getSinglePlatform() == KotlinPlatform.NATIVE
|
||||||
?.let { compilations ->
|
) {
|
||||||
addAll(propagatedDependencies(compilations))
|
sourceSetToCompilations[sourceSet.name]?.let { compilations ->
|
||||||
}
|
addAll(propagatedNativeDependencies(compilations))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildDependencies(
|
buildDependencies(
|
||||||
@@ -609,8 +610,8 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
// Currently such special casing is available for Apple platforms
|
// Currently such special casing is available for Apple platforms
|
||||||
// (iOS, watchOS and tvOS) and native Android (ARM, X86).
|
// (iOS, watchOS and tvOS) and native Android (ARM, X86).
|
||||||
// TODO: Do we need to support user's interop libraries too?
|
// TODO: Do we need to support user's interop libraries too?
|
||||||
private fun propagatedDependencies(compilations: List<CompilationWithDependencies>): List<ExternalDependency> {
|
private fun propagatedNativeDependencies(compilations: List<CompilationWithDependencies>): List<ExternalDependency> {
|
||||||
if (compilations.isEmpty()) {
|
if (compilations.size <= 1) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -86,8 +86,8 @@ class MultiplatformProjectImportingTest : MultiplePluginVersionGradleImportingTe
|
|||||||
assertModuleModuleDepScope("jvm_test", "common2_test", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("jvm_test", "common2_test", DependencyScope.COMPILE)
|
||||||
assertModuleModuleDepScope("js_main", "common1_main", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("js_main", "common1_main", DependencyScope.COMPILE)
|
||||||
assertModuleModuleDepScope("js_test", "common1_test", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("js_test", "common1_test", DependencyScope.COMPILE)
|
||||||
assertNoDepForModule("js_main", "common2_main")
|
assertNoModuleDepForModule("js_main", "common2_main")
|
||||||
assertNoDepForModule("js_test", "common2_test")
|
assertNoModuleDepForModule("js_test", "common2_test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -190,7 +190,7 @@ class MultiplatformProjectImportingTest : MultiplePluginVersionGradleImportingTe
|
|||||||
|
|
||||||
assertModuleModuleDepScope("project2_main", "project1_main", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("project2_main", "project1_main", DependencyScope.COMPILE)
|
||||||
assertModuleModuleDepScope("project3_main", "project2_main", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("project3_main", "project2_main", DependencyScope.COMPILE)
|
||||||
assertNoDepForModule("project3_main", "project1_main")
|
assertNoModuleDepForModule("project3_main", "project1_main")
|
||||||
|
|
||||||
TestCase.assertEquals(
|
TestCase.assertEquals(
|
||||||
listOf("jar:///project2/build/libs/project2-jar.jar!/"),
|
listOf("jar:///project2/build/libs/project2-jar.jar!/"),
|
||||||
|
|||||||
+6
-5
@@ -32,10 +32,7 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
|||||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
|
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
|
||||||
import com.intellij.openapi.module.Module;
|
import com.intellij.openapi.module.Module;
|
||||||
import com.intellij.openapi.module.ModuleManager;
|
import com.intellij.openapi.module.ModuleManager;
|
||||||
import com.intellij.openapi.roots.DependencyScope;
|
import com.intellij.openapi.roots.*;
|
||||||
import com.intellij.openapi.roots.ModuleOrderEntry;
|
|
||||||
import com.intellij.openapi.roots.ModuleRootManager;
|
|
||||||
import com.intellij.openapi.roots.OrderEntry;
|
|
||||||
import com.intellij.openapi.util.Couple;
|
import com.intellij.openapi.util.Couple;
|
||||||
import com.intellij.openapi.util.Ref;
|
import com.intellij.openapi.util.Ref;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
@@ -247,10 +244,14 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest
|
|||||||
expectedScopes, actualScopes);
|
expectedScopes, actualScopes);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertNoDepForModule(String moduleName, String depName) {
|
protected void assertNoModuleDepForModule(String moduleName, String depName) {
|
||||||
assertEmpty("No dependency '" + depName + "' was expected", collectModuleDeps(moduleName, depName, ModuleOrderEntry.class));
|
assertEmpty("No dependency '" + depName + "' was expected", collectModuleDeps(moduleName, depName, ModuleOrderEntry.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void assertNoLibraryDepForModule(String moduleName, String depName) {
|
||||||
|
assertEmpty("No dependency '" + depName + "' was expected", collectModuleDeps(moduleName, depName, LibraryOrderEntry.class));
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<ModuleOrderEntry> getModuleModuleDeps(@NotNull String moduleName, @NotNull String depName) {
|
private List<ModuleOrderEntry> getModuleModuleDeps(@NotNull String moduleName, @NotNull String depName) {
|
||||||
return getModuleDep(moduleName, depName, ModuleOrderEntry.class);
|
return getModuleDep(moduleName, depName, ModuleOrderEntry.class);
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ interface KotlinTestTask : Serializable {
|
|||||||
interface ExtraFeatures : Serializable {
|
interface ExtraFeatures : Serializable {
|
||||||
val coroutinesState: String?
|
val coroutinesState: String?
|
||||||
val isHMPPEnabled: Boolean
|
val isHMPPEnabled: Boolean
|
||||||
|
val isNativeDependencyPropagationEnabled: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KotlinMPPGradleModel : Serializable {
|
interface KotlinMPPGradleModel : Serializable {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
return KotlinMPPGradleModelImpl(
|
return KotlinMPPGradleModelImpl(
|
||||||
filterOrphanSourceSets(sourceSetMap, targets, project),
|
filterOrphanSourceSets(sourceSetMap, targets, project),
|
||||||
targets,
|
targets,
|
||||||
ExtraFeaturesImpl(coroutinesState, isHMPPEnabled(project)),
|
ExtraFeaturesImpl(coroutinesState, isHMPPEnabled(project), isNativeDependencyPropagationEnabled(project)),
|
||||||
kotlinNativeHome,
|
kotlinNativeHome,
|
||||||
dependencyMapper.toDependencyMap()
|
dependencyMapper.toDependencyMap()
|
||||||
)
|
)
|
||||||
@@ -83,6 +83,10 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
return (project.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false
|
return (project.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isNativeDependencyPropagationEnabled(project: Project): Boolean {
|
||||||
|
return (project.findProperty("kotlin.native.enableDependencyPropagation") as? String)?.toBoolean() ?: true
|
||||||
|
}
|
||||||
|
|
||||||
private fun reportUnresolvedDependencies(targets: Collection<KotlinTarget>) {
|
private fun reportUnresolvedDependencies(targets: Collection<KotlinTarget>) {
|
||||||
targets
|
targets
|
||||||
.asSequence()
|
.asSequence()
|
||||||
|
|||||||
@@ -168,7 +168,8 @@ data class KotlinTestTaskImpl(
|
|||||||
|
|
||||||
data class ExtraFeaturesImpl(
|
data class ExtraFeaturesImpl(
|
||||||
override val coroutinesState: String?,
|
override val coroutinesState: String?,
|
||||||
override val isHMPPEnabled: Boolean
|
override val isHMPPEnabled: Boolean,
|
||||||
|
override val isNativeDependencyPropagationEnabled: Boolean
|
||||||
) : ExtraFeatures
|
) : ExtraFeatures
|
||||||
|
|
||||||
data class KotlinMPPGradleModelImpl(
|
data class KotlinMPPGradleModelImpl(
|
||||||
@@ -191,7 +192,11 @@ data class KotlinMPPGradleModelImpl(
|
|||||||
cloningCache[initialTarget] = it
|
cloningCache[initialTarget] = it
|
||||||
}
|
}
|
||||||
}.toList(),
|
}.toList(),
|
||||||
ExtraFeaturesImpl(mppModel.extraFeatures.coroutinesState, mppModel.extraFeatures.isHMPPEnabled),
|
ExtraFeaturesImpl(
|
||||||
|
mppModel.extraFeatures.coroutinesState,
|
||||||
|
mppModel.extraFeatures.isHMPPEnabled,
|
||||||
|
mppModel.extraFeatures.isNativeDependencyPropagationEnabled
|
||||||
|
),
|
||||||
mppModel.kotlinNativeHome,
|
mppModel.kotlinNativeHome,
|
||||||
mppModel.dependencyMap.map { it.key to it.value.deepCopy(cloningCache) }.toMap()
|
mppModel.dependencyMap.map { it.key to it.value.deepCopy(cloningCache) }.toMap()
|
||||||
)
|
)
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform") version "1.3.60-dev-2515"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-dev") }
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
val jvm = jvm()
|
||||||
|
val iosDev = iosArm64()
|
||||||
|
val iosSim = iosX64()
|
||||||
|
val watchDev = watchosArm32()
|
||||||
|
val watchSim = watchosX86()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
val commonMain by getting
|
||||||
|
val appleMain by creating {
|
||||||
|
dependsOn(commonMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
val iosMain by creating {
|
||||||
|
dependsOn(appleMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
configure(listOf(watchDev, watchSim)) {
|
||||||
|
compilations["main"].defaultSourceSet.dependsOn(appleMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
configure(listOf(iosDev, iosSim)) {
|
||||||
|
compilations["main"].defaultSourceSet.dependsOn(iosMain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
org.jetbrains.kotlin.native.home=../kotlin-native-data-dir/kotlin-native-PLATFORM-VERSION
|
||||||
|
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||||
|
kotlin.native.enableDependencyPropagation=false
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
gradlePluginPortal()
|
||||||
|
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-dev") }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user