[Gradle, K/N] Add release binaries to generate binaries tests

This commit is contained in:
Alexander.Likhachev
2020-10-13 22:37:34 +03:00
parent 08ee702d19
commit 4b68678a36
5 changed files with 55 additions and 46 deletions
@@ -147,17 +147,21 @@ class GeneralNativeIT : BaseGradleIT() {
val sharedSuffix = CompilerOutputKind.DYNAMIC.suffix(HostManager.host) val sharedSuffix = CompilerOutputKind.DYNAMIC.suffix(HostManager.host)
val sharedPaths = listOf( val sharedPaths = listOf(
"build/bin/host/debugShared/$sharedPrefix$baseName$sharedSuffix", "build/bin/host/debugShared/$sharedPrefix$baseName$sharedSuffix",
"build/bin/host/releaseShared/$sharedPrefix$baseName$sharedSuffix",
) )
val staticPrefix = CompilerOutputKind.STATIC.prefix(HostManager.host) val staticPrefix = CompilerOutputKind.STATIC.prefix(HostManager.host)
val staticSuffix = CompilerOutputKind.STATIC.suffix(HostManager.host) val staticSuffix = CompilerOutputKind.STATIC.suffix(HostManager.host)
val staticPaths = listOf( val staticPaths = listOf(
"build/bin/host/debugStatic/$staticPrefix$baseName$staticSuffix", "build/bin/host/debugStatic/$staticPrefix$baseName$staticSuffix",
"build/bin/host/releaseStatic/$staticPrefix$baseName$staticSuffix",
) )
val headerPaths = listOf( val headerPaths = listOf(
"build/bin/host/debugShared/$sharedPrefix${baseName}_api.h", "build/bin/host/debugShared/$sharedPrefix${baseName}_api.h",
"build/bin/host/debugStatic/$staticPrefix${baseName}_api.h", "build/bin/host/debugStatic/$staticPrefix${baseName}_api.h",
"build/bin/host/releaseShared/$sharedPrefix${baseName}_api.h",
"build/bin/host/releaseStatic/$staticPrefix${baseName}_api.h",
) )
val klibPrefix = CompilerOutputKind.LIBRARY.prefix(HostManager.host) val klibPrefix = CompilerOutputKind.LIBRARY.prefix(HostManager.host)
@@ -167,6 +171,8 @@ class GeneralNativeIT : BaseGradleIT() {
val linkTasks = listOf( val linkTasks = listOf(
":linkDebugSharedHost", ":linkDebugSharedHost",
":linkDebugStaticHost", ":linkDebugStaticHost",
":linkReleaseSharedHost",
":linkReleaseStaticHost",
) )
val klibTask = ":compileKotlinHost" val klibTask = ":compileKotlinHost"
@@ -201,10 +207,6 @@ class GeneralNativeIT : BaseGradleIT() {
assertTasksExecuted(linkTasks[0]) assertTasksExecuted(linkTasks[0])
} }
// Check that plugin doesn't allow exporting dependencies not added in the API configuration.
gradleBuildScript().modify {
it.replace("api(project(\":exported\"))", "")
}
build(":assemble") { build(":assemble") {
assertFailed() assertFailed()
val failureMsg = "Following dependencies exported in the debugShared binary " + val failureMsg = "Following dependencies exported in the debugShared binary " +
@@ -214,35 +216,52 @@ class GeneralNativeIT : BaseGradleIT() {
} }
@Test @Test
fun testCanProduceNativeFrameworks() = with(transformNativeTestProjectWithPluginDsl("frameworks", directoryPrefix = "native-binaries")) { fun testCanProduceNativeFrameworks() = with(
transformNativeTestProjectWithPluginDsl("frameworks", directoryPrefix = "native-binaries")
) {
Assume.assumeTrue(HostManager.hostIsMac) Assume.assumeTrue(HostManager.hostIsMac)
data class BinaryMeta(val name: String, val isStatic: Boolean = false)
val baseName = "main" val baseName = "main"
val frameworkPrefix = CompilerOutputKind.FRAMEWORK.prefix(HostManager.host) val frameworkPrefix = CompilerOutputKind.FRAMEWORK.prefix(HostManager.host)
val frameworkSuffix = CompilerOutputKind.FRAMEWORK.suffix(HostManager.host) val frameworkSuffix = CompilerOutputKind.FRAMEWORK.suffix(HostManager.host)
val frameworkPaths = listOf( val targets = listOf("ios", "iosSim")
"build/bin/ios/mainDebugFramework/$frameworkPrefix$baseName$frameworkSuffix.dSYM", val binaries = mapOf(
"build/bin/ios/mainDebugFramework/$frameworkPrefix$baseName$frameworkSuffix", "ios" to listOf(BinaryMeta("main"), BinaryMeta("custom", true)),
"build/bin/ios/mainReleaseFramework/$frameworkPrefix$baseName$frameworkSuffix", "iosSim" to listOf(BinaryMeta("main"))
"build/bin/iosSim/mainDebugFramework/$frameworkPrefix$baseName$frameworkSuffix.dSYM",
"build/bin/iosSim/mainDebugFramework/$frameworkPrefix$baseName$frameworkSuffix",
"build/bin/iosSim/mainReleaseFramework/$frameworkPrefix$baseName$frameworkSuffix",
) )
val frameworkPaths = targets.flatMap { target ->
binaries.getValue(target).flatMap {
val list = listOf(
"build/bin/$target/${it.name}DebugFramework/$frameworkPrefix${it.name}$frameworkSuffix",
"build/bin/$target/${it.name}ReleaseFramework/$frameworkPrefix${it.name}$frameworkSuffix",
)
if (it.isStatic) {
list
} else {
list + "build/bin/$target/${it.name}DebugFramework/$frameworkPrefix${it.name}$frameworkSuffix.dSYM"
}
}
}
val headerPaths = listOf( val headerPaths = targets.flatMap { target ->
"build/bin/ios/mainDebugFramework/$frameworkPrefix$baseName$frameworkSuffix/headers/$baseName.h", binaries.getValue(target).flatMap {
"build/bin/ios/mainReleaseFramework/$frameworkPrefix$baseName$frameworkSuffix/headers/$baseName.h", listOf(
"build/bin/iosSim/mainDebugFramework/$frameworkPrefix$baseName$frameworkSuffix/headers/$baseName.h", "build/bin/$target/${it.name}DebugFramework/$frameworkPrefix${it.name}$frameworkSuffix/headers/${it.name}.h",
"build/bin/iosSim/mainReleaseFramework/$frameworkPrefix$baseName$frameworkSuffix/headers/$baseName.h", "build/bin/$target/${it.name}ReleaseFramework/$frameworkPrefix${it.name}$frameworkSuffix/headers/${it.name}.h",
) )
}
}
val frameworkTasks = listOf( val frameworkTasks = targets.flatMap { target ->
":linkMainDebugFrameworkIos", binaries.getValue(target).flatMap {
":linkMainReleaseFrameworkIos", listOf(
":linkCustomDebugFrameworkIos", ":link${it.name.capitalize()}DebugFramework${target.capitalize()}",
":linkMainDebugFrameworkIosSim", ":link${it.name.capitalize()}ReleaseFramework${target.capitalize()}",
":linkMainReleaseFrameworkIosSim", )
) }
}
// Check building // Check building
// Check dependency exporting and bitcode embedding in frameworks. // Check dependency exporting and bitcode embedding in frameworks.
@@ -263,6 +282,7 @@ class GeneralNativeIT : BaseGradleIT() {
assertTrue(it.contains("-Xembed-bitcode-marker")) assertTrue(it.contains("-Xembed-bitcode-marker"))
assertTrue(it.contains("-g")) assertTrue(it.contains("-g"))
} }
// Check that bitcode can be disabled by setting custom compiler options
checkNativeCommandLineFor(":linkCustomDebugFrameworkIos") { checkNativeCommandLineFor(":linkCustomDebugFrameworkIos") {
assertTrue(it.contains("-linker-option -L.")) assertTrue(it.contains("-linker-option -L."))
assertTrue(it.contains("-Xtime")) assertTrue(it.contains("-Xtime"))
@@ -325,10 +345,7 @@ class GeneralNativeIT : BaseGradleIT() {
val binaries = mutableListOf( val binaries = mutableListOf(
"debugExecutable" to "native-binary", "debugExecutable" to "native-binary",
"releaseExecutable" to "native-binary", "releaseExecutable" to "native-binary",
"fooDebugExecutable" to "foo", "bazDebugExecutable" to "my-baz",
"fooReleaseExecutable" to "foo",
"barReleaseExecutable" to "bar",
"bazReleaseExecutable" to "my-baz",
) )
val linkTasks = binaries.map { (name, _) -> "link${name.capitalize()}Host" } val linkTasks = binaries.map { (name, _) -> "link${name.capitalize()}Host" }
val outputFiles = binaries.map { (name, fileBaseName) -> val outputFiles = binaries.map { (name, fileBaseName) ->
@@ -341,10 +358,7 @@ class GeneralNativeIT : BaseGradleIT() {
val runTasks = listOf( val runTasks = listOf(
"runDebugExecutable", "runDebugExecutable",
"runReleaseExecutable", "runReleaseExecutable",
"runFooDebugExecutable", "runBazDebugExecutable",
"runFooReleaseExecutable",
"runBarReleaseExecutable",
"runBazReleaseExecutable",
).map { it + "Host" }.toMutableList() ).map { it + "Host" }.toMutableList()
// Check building // Check building
@@ -371,7 +385,7 @@ class GeneralNativeIT : BaseGradleIT() {
assertTrue(output.contains("<root>.main")) assertTrue(output.contains("<root>.main"))
} }
build("runBazReleaseExecutableHost") { build("runBazDebugExecutableHost") {
assertSuccessful() assertSuccessful()
assertTrue(output.contains("foo.main")) assertTrue(output.contains("foo.main"))
} }
@@ -16,12 +16,10 @@ kotlin {
<SingleNativeTarget>("host") { <SingleNativeTarget>("host") {
binaries { binaries {
executable() // Executable with default name. executable() // Executable with default name.
executable("foo") // Custom binary name.
executable("bar", listOf(RELEASE)) // Custom build types.
// Configure a binary. // Configure a binary.
executable("baz") { executable("baz", listOf(DEBUG)) {
// Rename an output binary: baz.kexe -> my-baz.kexe. // Rename an output binary: baz.kexe -> my-baz.kexe.
baseName = "my-baz" baseName = "my-baz"
// Use a custom entry point. // Use a custom entry point.
@@ -17,10 +17,10 @@ kotlin {
iosArm64("ios") { iosArm64("ios") {
binaries { binaries {
framework("main", listOf(RELEASE, DEBUG)) { framework("main") {
export(project(":exported")) export(project(":exported"))
} }
framework("custom", listOf(DEBUG)) { framework("custom") {
embedBitcode("disable") embedBitcode("disable")
linkerOpts = mutableListOf("-L.") linkerOpts = mutableListOf("-L.")
freeCompilerArgs = mutableListOf("-Xtime") freeCompilerArgs = mutableListOf("-Xtime")
@@ -30,11 +30,8 @@ kotlin {
} }
iosX64("iosSim") { iosX64("iosSim") {
compilations["main"].defaultSourceSet {
dependsOn(sourceSets["iosMain"])
}
binaries { binaries {
framework("main", listOf(RELEASE, DEBUG)) { framework("main") {
export(project(":exported")) export(project(":exported"))
} }
} }
@@ -17,10 +17,10 @@ kotlin {
<SingleNativeTarget>("host") { <SingleNativeTarget>("host") {
binaries { binaries {
sharedLib(listOf(DEBUG)) { sharedLib() {
export(project(":exported")) export(project(":exported"))
} }
staticLib(listOf(DEBUG)) { staticLib() {
export(project(":exported")) export(project(":exported"))
} }
} }