diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppCInteropDependencyTransformationIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppCInteropDependencyTransformationIT.kt index 3aaeb743aa6..747d357db12 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppCInteropDependencyTransformationIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppCInteropDependencyTransformationIT.kt @@ -24,246 +24,327 @@ import org.junit.Test * - dependency-mode=project: In this case p2 will just declare a regular project dependency on p1 * - dependency-mode=repository: In this case p2 will rely on a previously published version of p1 */ -class MppCInteropDependencyTransformationIT : BaseGradleIT() { +open class MppCInteropDependencyTransformationIT : BaseGradleIT() { - private val baseBuildOptions = defaultBuildOptions().copy( - forceOutputToStdout = true, - warningMode = WarningMode.Fail, - parallelTasksInProject = true, - freeCommandLineArgs = defaultBuildOptions().freeCommandLineArgs + "-s" - ) + protected val baseBuildOptions + get() = defaultBuildOptions().copy( + forceOutputToStdout = true, + warningMode = WarningMode.Fail, + parallelTasksInProject = true, + freeCommandLineArgs = defaultBuildOptions().freeCommandLineArgs + "-s" + ) - private val projectDependencyOptions = baseBuildOptions.copy( - freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=project" - ) + protected val projectDependencyOptions + get() = baseBuildOptions.copy( + freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=project" + ) - private val repositoryDependencyOptions = baseBuildOptions.copy( - freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=repository" - ) + protected val repositoryDependencyOptions + get() = baseBuildOptions.copy( + freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=repository" + ) - private val project by lazy { Project("cinterop-MetadataDependencyTransformation") } + class ComplexProject : MppCInteropDependencyTransformationIT() { - @Test - fun `test - compile project - dependencyMode=project`() { - testCompileProject(projectDependencyOptions) { - assertProjectDependencyMode() - assertTasksExecuted(":p1:commonizeCInterop") + private val project by lazy { Project("cinterop-MetadataDependencyTransformation") } + + @Test + fun `test - compile project - dependencyMode=project`() { + testCompileProject(projectDependencyOptions) { + assertProjectDependencyMode() + assertTasksExecuted(":p1:commonizeCInterop") + } } - } - @Test - fun `test - compile project - dependencyMode=repository`() { - publishP1ToBuildRepository() - testCompileProject(repositoryDependencyOptions) { - assertRepositoryDependencyMode() + @Test + fun `test - compile project - dependencyMode=repository`() { + publishP1ToBuildRepository() + testCompileProject(repositoryDependencyOptions) { + assertRepositoryDependencyMode() + } } - } - private fun testCompileProject(options: BuildOptions, check: CompiledProject.() -> Unit = {}) { - project.build("compileAll", options = options) { - check() - assertSuccessful() + private fun testCompileProject(options: BuildOptions, check: CompiledProject.() -> Unit = {}) { + project.build("compileAll", options = options) { + check() + assertSuccessful() - /* Assert p2 & p3 compiled metadata */ - assertTasksExecuted(":p2:compileNativeMainKotlinMetadata") - assertTasksExecuted(":p2:compileLinuxMainKotlinMetadata") - assertTasksExecuted(":p3:compileNativeMainKotlinMetadata") + /* Assert p2 & p3 compiled metadata */ + assertTasksExecuted(":p2:compileNativeMainKotlinMetadata") + assertTasksExecuted(":p2:compileLinuxMainKotlinMetadata") + assertTasksExecuted(":p3:compileNativeMainKotlinMetadata") + + if (HostManager.hostIsMac) { + assertTasksExecuted(":p2:compileAppleMainKotlinMetadata") + assertTasksExecuted(":p2:compileIosMainKotlinMetadata") + assertTasksExecuted(":p3:compileAppleAndLinuxMainKotlinMetadata") + assertTasksExecuted(":p3:compileIosMainKotlinMetadata") + } + + if (HostManager.hostIsMingw || HostManager.hostIsMac) { + assertTasksExecuted(":p2:compileWindowsMainKotlinMetadata") + assertTasksExecuted(":p3:compileWindowsMainKotlinMetadata") + } + + /* Assert p2 & p3 transformed cinterop dependencies */ + assertTasksExecuted(":p2:transformNativeMainCInteropDependenciesMetadata") + assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") + + /* Assert p2 & p3 compiled tests */ + assertTasksExecuted(":p2:compileTestKotlinLinuxX64") + assertTasksExecuted(":p3:compileTestKotlinLinuxX64") + } + } + + @Test + fun `test - source set dependencies - dependencyMode=project`() { + reportSourceSetCommonizerDependencies(project, "p2", projectDependencyOptions) { + it.assertProjectDependencyMode() + it.assertTasksExecuted(":p2:transformNativeMainCInteropDependenciesMetadataForIde") + it.assertTasksNotExecuted(".*[cC]ompile.*") + assertP2SourceSetDependencies() + } + + reportSourceSetCommonizerDependencies(project, "p3", projectDependencyOptions) { + it.assertProjectDependencyMode() + it.assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadataForIde") + it.assertTasksNotExecuted(".*[cC]ompile.*") + assertP3SourceSetDependencies() + } + } + + @Test + fun `test - source set dependencies - dependencyMode=repository`() { + publishP1ToBuildRepository() + + reportSourceSetCommonizerDependencies(project, "p2", repositoryDependencyOptions) { + it.assertRepositoryDependencyMode() + it.assertTasksExecuted(":p2:transformNativeMainCInteropDependenciesMetadataForIde") + it.assertTasksNotExecuted(".*[cC]ompile.*") + assertP2SourceSetDependencies() + } + + reportSourceSetCommonizerDependencies(project, "p3", repositoryDependencyOptions) { + it.assertRepositoryDependencyMode() + it.assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadataForIde") + it.assertTasksNotExecuted(".*[cC]ompile.*") + assertP3SourceSetDependencies() + } + } + + private fun WithSourceSetCommonizerDependencies.assertP2SourceSetDependencies() { + listOf("nativeMain", "nativeTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies( + CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64, MINGW_X64, MINGW_X86) + ) + } if (HostManager.hostIsMac) { - assertTasksExecuted(":p2:compileAppleMainKotlinMetadata") - assertTasksExecuted(":p2:compileIosMainKotlinMetadata") - assertTasksExecuted(":p3:compileAppleAndLinuxMainKotlinMetadata") - assertTasksExecuted(":p3:compileIosMainKotlinMetadata") + listOf("appleAndLinuxMain", "appleAndLinuxTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64)) + } + + listOf("appleMain", "appleTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(IOS_ARM64, IOS_X64, MACOS_X64)) + } + + listOf("iosMain", "iosTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(IOS_ARM64, IOS_X64)) + } } if (HostManager.hostIsMingw || HostManager.hostIsMac) { - assertTasksExecuted(":p2:compileWindowsMainKotlinMetadata") - assertTasksExecuted(":p3:compileWindowsMainKotlinMetadata") - } + listOf("windowsMain", "windowsTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(MINGW_X64, MINGW_X86)) + } - /* Assert p2 & p3 transformed cinterop dependencies */ - assertTasksExecuted(":p2:transformNativeMainCInteropDependenciesMetadata") - assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") - - /* Assert p2 & p3 compiled tests */ - assertTasksExecuted(":p2:compileTestKotlinLinuxX64") - assertTasksExecuted(":p3:compileTestKotlinLinuxX64") - } - } - - @Test - fun `test - source set dependencies - dependencyMode=project`() { - reportSourceSetCommonizerDependencies(project, "p2", projectDependencyOptions) { - it.assertProjectDependencyMode() - it.assertTasksExecuted(":p2:transformNativeMainCInteropDependenciesMetadataForIde") - it.assertTasksNotExecuted(".*[cC]ompile.*") - assertP2SourceSetDependencies() - } - - reportSourceSetCommonizerDependencies(project, "p3", projectDependencyOptions) { - it.assertProjectDependencyMode() - it.assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadataForIde") - it.assertTasksNotExecuted(".*[cC]ompile.*") - assertP3SourceSetDependencies() - } - } - - @Test - fun `test - source set dependencies - dependencyMode=repository`() { - publishP1ToBuildRepository() - - reportSourceSetCommonizerDependencies(project, "p2", repositoryDependencyOptions) { - it.assertRepositoryDependencyMode() - it.assertTasksExecuted(":p2:transformNativeMainCInteropDependenciesMetadataForIde") - it.assertTasksNotExecuted(".*[cC]ompile.*") - assertP2SourceSetDependencies() - } - - reportSourceSetCommonizerDependencies(project, "p3", repositoryDependencyOptions) { - it.assertRepositoryDependencyMode() - it.assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadataForIde") - it.assertTasksNotExecuted(".*[cC]ompile.*") - assertP3SourceSetDependencies() - } - } - - private fun WithSourceSetCommonizerDependencies.assertP2SourceSetDependencies() { - listOf("nativeMain", "nativeTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies( - CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64, MINGW_X64, MINGW_X86) - ) - } - - if (HostManager.hostIsMac) { - listOf("appleAndLinuxMain", "appleAndLinuxTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64)) - } - - listOf("appleMain", "appleTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(IOS_ARM64, IOS_X64, MACOS_X64)) - } - - listOf("iosMain", "iosTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(IOS_ARM64, IOS_X64)) + listOf("linuxMain", "linuxTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(LINUX_ARM64, LINUX_X64)) + } } } - if (HostManager.hostIsMingw || HostManager.hostIsMac) { - listOf("windowsMain", "windowsTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(MINGW_X64, MINGW_X86)) - } - - listOf("linuxMain", "linuxTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(LINUX_ARM64, LINUX_X64)) - } - } - } - - private fun WithSourceSetCommonizerDependencies.assertP3SourceSetDependencies() { - /* + private fun WithSourceSetCommonizerDependencies.assertP3SourceSetDependencies() { + /* windowsAndLinuxMain / windowsAndLinuxTest will not have a 'perfect target match' in p1. They will choose cinterops associated with 'nativeMain' */ - listOf("nativeMain", "nativeTest", "windowsAndLinuxMain", "windowsAndLinuxTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies( - CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64, MINGW_X64, MINGW_X86) - ) - } - - if (HostManager.hostIsMac) { - listOf("appleAndLinuxMain", "appleAndLinuxTest").forEach { sourceSetName -> + listOf("nativeMain", "nativeTest", "windowsAndLinuxMain", "windowsAndLinuxTest").forEach { sourceSetName -> getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64)) + .assertTargetOnAllDependencies( + CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64, MINGW_X64, MINGW_X86) + ) } - listOf("iosMain", "iosTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(IOS_ARM64, IOS_X64)) + if (HostManager.hostIsMac) { + listOf("appleAndLinuxMain", "appleAndLinuxTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(LINUX_ARM64, LINUX_X64, IOS_ARM64, IOS_X64, MACOS_X64)) + } + + listOf("iosMain", "iosTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(IOS_ARM64, IOS_X64)) + } + } + + if (HostManager.hostIsMingw || HostManager.hostIsMac) { + listOf("windowsMain", "windowsTest").forEach { sourceSetName -> + getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() + .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") + .assertTargetOnAllDependencies(CommonizerTarget(MINGW_X64, MINGW_X86)) + } } } - if (HostManager.hostIsMingw || HostManager.hostIsMac) { - listOf("windowsMain", "windowsTest").forEach { sourceSetName -> - getCommonizerDependencies(sourceSetName).withoutNativeDistributionDependencies() - .assertDependencyFilesMatches(".*cinterop-simple.*", ".*cinterop-withPosix.*") - .assertTargetOnAllDependencies(CommonizerTarget(MINGW_X64, MINGW_X86)) + @Test + fun `test - transformation - UP-TO-DATE behaviour - on p3`() { + publishP1ToBuildRepository() + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { + assertSuccessful() + assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") + } + + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { + assertSuccessful() + assertTasksNotExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") + assertTasksUpToDate(":p3:transformNativeMainCInteropDependenciesMetadata") + } + + val p3BuildGradleKts = project.projectDir.resolve("p3/build.gradle.kts") + val p3BuildGradleKtsContent = p3BuildGradleKts.readText() + + // Remove dependency on p2 | Task should re-run + p3BuildGradleKts.writeText(p3BuildGradleKtsContent.replace("""implementation(project(":p2"))""", "")) + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { + assertSuccessful() + assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") + } + + // Re-add dependency on p3 | Task should re-run for the next invocation + p3BuildGradleKts.writeText(p3BuildGradleKtsContent) + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { + assertSuccessful() + assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") + } + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { + assertSuccessful() + assertTasksNotExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") + assertTasksUpToDate(":p3:transformNativeMainCInteropDependenciesMetadata") + } + + // Replace dependency to :p2 with coordinates directly + p3BuildGradleKts.writeText( + p3BuildGradleKtsContent.replace("""project(":p2")""", """"kotlin-multiplatform-projects:p1:1.0.0-SNAPSHOT"""") + ) + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { + assertSuccessful() + assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") + } + } + + + @Test + fun `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2 - dependencyMode=repository`() { + publishP1ToBuildRepository() + `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2`(repositoryDependencyOptions) + } + + @Test + private fun `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2 - dependencyMode=project`() { + `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2`(projectDependencyOptions) + } + + private fun `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2`(options: BuildOptions) { + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = options) { + assertSuccessful() + } + + project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = options) { + assertTasksUpToDate(":p3:transformNativeMainCInteropDependenciesMetadata") + } + } + + private fun publishP1ToBuildRepository() = project.publishP1ToBuildRepository() + } + + class KT46198 : MppCInteropDependencyTransformationIT() { + private val project by lazy { Project("cinterop-MetadataDependencyTransformation-kt-50952") } + + @Test + fun `test UP-TO-DATE - when changing consumer targets - dependencyMode=repository`() { + project.publishP1ToBuildRepository() + `test UP-TO-DATE - when changing consumer targets`(repositoryDependencyOptions) + } + + @Test + fun `test UP-TO-DATE - when changing consumer targets - dependencyMode=project`() { + `test UP-TO-DATE - when changing consumer targets`(projectDependencyOptions) + } + + private fun `test UP-TO-DATE - when changing consumer targets`(options: BuildOptions) { + project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) { + assertSuccessful() + } + + project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) { + assertSuccessful() + assertTasksNotExecuted(":p2:transformCommonMainCInteropDependenciesMetadata") + assertTasksUpToDate(":p2:transformCommonMainCInteropDependenciesMetadata") + } + + val optionsWithAdditionalTargetEnabled = options.withFreeCommandLineArgument("-Pp2.enableLinuxArm32Hfp") + + project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = optionsWithAdditionalTargetEnabled) { + assertSuccessful() + assertTasksExecuted(":p2:transformCommonMainCInteropDependenciesMetadata") + } + + project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = optionsWithAdditionalTargetEnabled) { + assertSuccessful() + assertTasksNotExecuted(":p2:transformCommonMainCInteropDependenciesMetadata") + assertTasksUpToDate(":p2:transformCommonMainCInteropDependenciesMetadata") + } + + project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) { + assertSuccessful() + assertTasksExecuted(":p2:transformCommonMainCInteropDependenciesMetadata") + } + + project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) { + assertSuccessful() + assertTasksNotExecuted(":p2:transformCommonMainCInteropDependenciesMetadata") + assertTasksUpToDate(":p2:transformCommonMainCInteropDependenciesMetadata") } } } - @Test - fun `test - transformation - UP-TO-DATE behaviour`() { - publishP1ToBuildRepository() - project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { - assertSuccessful() - assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") - } - - project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { - assertSuccessful() - assertTasksNotExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") - assertTasksUpToDate(":p3:transformNativeMainCInteropDependenciesMetadata") - } - - val p3BuildGradleKts = project.projectDir.resolve("p3/build.gradle.kts") - val p3BuildGradleKtsContent = p3BuildGradleKts.readText() - - // Remove dependency on p2 | Task should re-run - p3BuildGradleKts.writeText(p3BuildGradleKtsContent.replace("""implementation(project(":p2"))""", "")) - project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { - assertSuccessful() - assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") - } - - // Re-add dependency on p3 | Task should re-run for the next invocation - p3BuildGradleKts.writeText(p3BuildGradleKtsContent) - project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { - assertSuccessful() - assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") - } - project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { - assertSuccessful() - assertTasksNotExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") - assertTasksUpToDate(":p3:transformNativeMainCInteropDependenciesMetadata") - } - - // Replace dependency to :p2 with coordinates directly - p3BuildGradleKts.writeText( - p3BuildGradleKtsContent.replace("""project(":p2")""", """"kotlin-multiplatform-projects:p1:1.0.0-SNAPSHOT"""") - ) - project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) { - assertSuccessful() - assertTasksExecuted(":p3:transformNativeMainCInteropDependenciesMetadata") - } - } - - private fun publishP1ToBuildRepository() { - project.build(":p1:publishAllPublicationsToBuildRepository", options = repositoryDependencyOptions) { - assertSuccessful() - } - } - - private fun CompiledProject.assertProjectDependencyMode() { + protected fun CompiledProject.assertProjectDependencyMode() { assertContains("dependencyMode = 'project'") } - private fun CompiledProject.assertRepositoryDependencyMode() { + protected fun CompiledProject.assertRepositoryDependencyMode() { assertContains("dependencyMode = 'repository'") } + + protected fun Project.publishP1ToBuildRepository() { + build(":p1:publishAllPublicationsToBuildRepository", options = repositoryDependencyOptions) { + assertSuccessful() + } + } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/build.gradle.kts new file mode 100644 index 00000000000..bd6d45f98c8 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + kotlin("multiplatform") apply false +} + +allprojects { + repositories { + mavenLocal() + mavenCentral() + google() + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/gradle.properties b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/gradle.properties new file mode 100644 index 00000000000..8c16cf3d552 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/gradle.properties @@ -0,0 +1 @@ +kotlin.mpp.enableCInteropCommonization=true diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/build.gradle.kts new file mode 100644 index 00000000000..a435cdc8f55 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/build.gradle.kts @@ -0,0 +1,49 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.konan.target.HostManager + +plugins { + kotlin("multiplatform") + `maven-publish` +} + +version = "1.0.0-SNAPSHOT" + +publishing { + repositories { + maven { + name = "build" + url = rootProject.buildDir.resolve("repo").toURI() + } + } +} + +kotlin { + linuxArm32Hfp() + val targetsWithInterop = listOf(linuxX64(), linuxArm64()) + + targets.withType().forEach { target -> + if (!HostManager().isEnabled(target.konanTarget)) { + error("Expected all targets to be supported. ${target.konanTarget} is disabled on this host!") + } + } + + val commonMain by sourceSets.getting + val withInteropMain by sourceSets.creating + val linuxX64Main by sourceSets.getting + val linuxArm64Main by sourceSets.getting + + withInteropMain.dependsOn(commonMain) + linuxX64Main.dependsOn(withInteropMain) + linuxArm64Main.dependsOn(withInteropMain) + + targetsWithInterop.forEach { target -> + target.compilations.getByName("main").cinterops.create("withPosix") { + this.packageName = "withPosix" + header(file("libs/withPosix.h")) + } + target.compilations.getByName("main").cinterops.create("simple") { + header(file("libs/simple.h")) + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/libs/simple.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/libs/simple.h new file mode 100644 index 00000000000..2cdd9eae399 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/libs/simple.h @@ -0,0 +1 @@ +void simpleInterop(); diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/libs/withPosix.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/libs/withPosix.h new file mode 100644 index 00000000000..d71048f7049 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/libs/withPosix.h @@ -0,0 +1,43 @@ +#include +#include +#include + +struct stat getStructFromPosix(); + +struct stat* getStructPointerFromPosix(); + +struct MyStruct getMyStruct(); + +struct MyStruct* getMyStructPointer(); + +struct MyStruct { + struct stat posixProperty; + + #if _WIN32 + long long longProperty; + #else + long longProperty; + #endif + + double doubleProperty; + + int32_t int32tProperty; + + int64_t int64tProperty; + + #if __linux__ + bool linuxOnlyProperty; + #endif + + #if __APPLE__ + bool appleOnlyProperty; + #include "TargetConditionals.h" + #if TARGET_OS_IPHONE + bool iosOnlyProperty; + #endif + #endif + + #if _WIN32 + bool windowsOnlyProperty; + #endif +}; diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/src/commonMain/kotlin/P1CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/src/commonMain/kotlin/P1CommonMain.kt new file mode 100644 index 00000000000..3944b3bce40 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/src/commonMain/kotlin/P1CommonMain.kt @@ -0,0 +1,7 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +object P1CommonMain + diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/src/nativeInterop/cinterop/simple.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/src/nativeInterop/cinterop/simple.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/src/nativeInterop/cinterop/withPosix.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p1/src/nativeInterop/cinterop/withPosix.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p2/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p2/build.gradle.kts new file mode 100644 index 00000000000..5af131d8b79 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/p2/build.gradle.kts @@ -0,0 +1,46 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.konan.target.HostManager + +repositories { + maven { + url = rootProject.buildDir.resolve("repo").toURI() + } +} + +plugins { + kotlin("multiplatform") +} + +kotlin { + linuxX64() + linuxArm64() + + if (properties.containsKey("p2.enableLinuxArm32Hfp")) { + linuxArm32Hfp() + } + + targets.withType().configureEach { + if (!HostManager().isEnabled(konanTarget)) { + error("Expected all targets to be supported. $konanTarget is disabled on this host!") + } + } + + sourceSets.commonMain.get().dependencies { + when (project.properties["dependencyMode"]?.toString()) { + null -> { + logger.warn("dependencyMode = null -> Using 'project'") + implementation(project(":p1")) + } + + "project" -> { + logger.quiet("dependencyMode = 'project'") + implementation(project(":p1")) + } + + "repository" -> { + logger.quiet("dependencyMode = 'repository'") + implementation("kotlin-multiplatform-projects:p1:1.0.0-SNAPSHOT") + } + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/settings.gradle.kts new file mode 100644 index 00000000000..178de6c40c2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/cinterop-MetadataDependencyTransformation-kt-50952/settings.gradle.kts @@ -0,0 +1,4 @@ +rootProject.name = "kotlin-multiplatform-projects" + +include(":p1") +include(":p2")