[gradle-plugin] Make dependency export non-transitive by default
Fix for KT-28936.
This commit is contained in:
committed by
Ilya Matveev
parent
8e97c94005
commit
8bc172b9c1
+1
-5
@@ -43,11 +43,7 @@ open class KotlinNativeDependenciesImpl @Inject constructor(
|
||||
implementationDependencies.extendsFrom(this)
|
||||
}
|
||||
|
||||
override var transitiveExport: Boolean
|
||||
get() = exportDependencies.isTransitive
|
||||
set(value) {
|
||||
exportDependencies.isTransitive = value
|
||||
}
|
||||
override var transitiveExport: Boolean = false
|
||||
|
||||
override fun export(notation: Any) {
|
||||
exportDependencies.dependencies.add(dependencyHandler.create(notation))
|
||||
|
||||
+1
@@ -60,6 +60,7 @@ open class KotlinNativeFrameworkImpl @Inject constructor(
|
||||
// A configuration containing exported klibs.
|
||||
override val export = configurations.create(names.withPrefix("export")).apply {
|
||||
isCanBeConsumed = false
|
||||
isTransitive = component.dependencies.transitiveExport
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, KotlinUsages.KOTLIN_API))
|
||||
attributes.attribute(CppBinary.DEBUGGABLE_ATTRIBUTE, debuggable)
|
||||
attributes.attribute(CppBinary.OPTIMIZED_ATTRIBUTE, optimized)
|
||||
|
||||
@@ -1143,18 +1143,32 @@ class ExperimentalPluginTests {
|
||||
@Test
|
||||
fun `Plugin should support symbol exporting for frameworks`() {
|
||||
assumeTrue(HostManager.hostIsMac)
|
||||
val transitiveDir = tmpFolder.newFolder("transitive")
|
||||
val transitiveProject = KonanProject.createEmpty(transitiveDir).apply {
|
||||
buildFile.writeText("""
|
||||
plugins { id 'kotlin-native' }
|
||||
components.main.targets = [ 'ios_x64' ]
|
||||
""")
|
||||
generateSrcFile("transitive.kt", "fun transitive() = 42")
|
||||
}
|
||||
|
||||
val libraryDir = tmpFolder.newFolder("library")
|
||||
val libraryProject = KonanProject.createEmpty(libraryDir).apply {
|
||||
buildFile.writeText("""
|
||||
plugins { id 'kotlin-native' }
|
||||
components.main.targets = [ 'ios_x64' ]
|
||||
|
||||
dependencies {
|
||||
implementation project(':transitive')
|
||||
}
|
||||
""".trimIndent())
|
||||
generateSrcFile("library.kt", "fun foo() = 42")
|
||||
generateSrcFile("library.kt", "fun foo() = transitive()")
|
||||
}
|
||||
|
||||
val project = KonanProject.createEmpty(projectDirectory).apply {
|
||||
settingsFile.writeText("""
|
||||
include ':library'
|
||||
include ':transitive'
|
||||
rootProject.name = 'test'
|
||||
""".trimIndent())
|
||||
buildFile.writeText("""
|
||||
@@ -1176,9 +1190,12 @@ class ExperimentalPluginTests {
|
||||
assertEquals(TaskOutcome.SUCCESS, task(":compileDebugKotlinNative")?.outcome)
|
||||
assertEquals(TaskOutcome.SUCCESS, task(":library:compileDebugKotlinNative")?.outcome)
|
||||
assertTrue(projectDirectory.resolve("build/lib/main/debug/test.framework").exists())
|
||||
|
||||
val header = projectDirectory.resolve("build/lib/main/debug/test.framework/Headers/test.h")
|
||||
assertTrue(header.exists())
|
||||
assertTrue(header.readText().contains("+ (int32_t)foo "))
|
||||
assertFalse(header.readText().contains("+ (int32_t)transitive")) // By default export is non-transitive.
|
||||
|
||||
checkFrameworkCompilationCommandLine {
|
||||
assertTrue(it.contains("-Xembed-bitcode-marker"))
|
||||
assertTrue(it.contains("-g"))
|
||||
@@ -1192,5 +1209,14 @@ class ExperimentalPluginTests {
|
||||
assertTrue(it.contains("-opt"))
|
||||
}
|
||||
}
|
||||
|
||||
// Check that transitive export works too.
|
||||
project.buildFile.appendText("\ncomponents.main.dependencies.transitiveExport = true")
|
||||
with(project.createRunner().withArguments("compileDebugKotlinNative").build()) {
|
||||
val header = projectDirectory.resolve("build/lib/main/debug/test.framework/Headers/test.h")
|
||||
assertTrue(header.exists())
|
||||
assertTrue(header.readText().contains("+ (int32_t)foo "))
|
||||
assertTrue(header.readText().contains("+ (int32_t)transitive"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user