[gradle-plugin] Support custom entry points (#1996)
This commit is contained in:
committed by
Nikolay Igotti
parent
66732675e5
commit
88e86cbdd4
@@ -915,6 +915,9 @@ components.main {
|
|||||||
// Set up output kinds
|
// Set up output kinds
|
||||||
outputKinds = [EXECUTABLE, KLIBRARY, FRAMEWORK, DYNAMIC, STATIC]
|
outputKinds = [EXECUTABLE, KLIBRARY, FRAMEWORK, DYNAMIC, STATIC]
|
||||||
|
|
||||||
|
// Specify custom entry point for executables
|
||||||
|
entryPoint = "org.test.myMain"
|
||||||
|
|
||||||
// Target-specific options
|
// Target-specific options
|
||||||
target('linux_x64') {
|
target('linux_x64') {
|
||||||
linkerOpts '-L/linux/lib/path'
|
linkerOpts '-L/linux/lib/path'
|
||||||
|
|||||||
+4
@@ -106,6 +106,10 @@ interface KotlinNativeComponent: ComponentWithBinaries, ComponentWithDependencie
|
|||||||
|
|
||||||
val publishJavadoc: Boolean
|
val publishJavadoc: Boolean
|
||||||
val publishSources: Boolean
|
val publishSources: Boolean
|
||||||
|
|
||||||
|
/** Allows setting custom entry point for executables */
|
||||||
|
var entryPoint: String?
|
||||||
|
fun entryPoint(value: String)
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
@@ -155,5 +155,8 @@ abstract class AbstractKotlinNativeComponent @Inject constructor(
|
|||||||
action.execute(dependencies)
|
action.execute(dependencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var entryPoint: String? = null
|
||||||
|
override fun entryPoint(value: String) { entryPoint = value }
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
+6
@@ -23,6 +23,7 @@ import org.gradle.api.file.FileSystemLocation
|
|||||||
import org.gradle.api.provider.Provider
|
import org.gradle.api.provider.Provider
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.api.tasks.InputFiles
|
import org.gradle.api.tasks.InputFiles
|
||||||
|
import org.gradle.api.tasks.Optional
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.AbstractKotlinNativeBinary
|
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.AbstractKotlinNativeBinary
|
||||||
@@ -59,6 +60,9 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
|||||||
val linkerOpts: List<String>
|
val linkerOpts: List<String>
|
||||||
@Input get() = binary.linkerOpts
|
@Input get() = binary.linkerOpts
|
||||||
|
|
||||||
|
val entryPoint: String?
|
||||||
|
@Optional @Input get() = binary.component.entryPoint
|
||||||
|
|
||||||
val outputFile: File
|
val outputFile: File
|
||||||
get() = outputLocationProvider.get().asFile
|
get() = outputLocationProvider.get().asFile
|
||||||
|
|
||||||
@@ -113,6 +117,8 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
|||||||
|
|
||||||
add("-Xmulti-platform")
|
add("-Xmulti-platform")
|
||||||
|
|
||||||
|
addArgIfNotNull("-entry", entryPoint)
|
||||||
|
|
||||||
addAll(additionalCompilerOptions)
|
addAll(additionalCompilerOptions)
|
||||||
|
|
||||||
libraries.files.forEach {library ->
|
libraries.files.forEach {library ->
|
||||||
|
|||||||
@@ -730,6 +730,39 @@ class ExperimentalPluginTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Plugin should support custom entry points`() {
|
||||||
|
val hostSuffix = CompilerOutputKind.PROGRAM.suffix(HostManager.host)
|
||||||
|
val exePath = "build/exe/main/release/entry-point$hostSuffix"
|
||||||
|
val project = KonanProject.createEmpty(projectDirectory).apply {
|
||||||
|
buildFile.writeText("""
|
||||||
|
plugins { id 'kotlin-native' }
|
||||||
|
|
||||||
|
components.main {
|
||||||
|
outputKinds = [EXECUTABLE]
|
||||||
|
entryPoint = 'org.test.myMain'
|
||||||
|
}
|
||||||
|
|
||||||
|
task run(type: Exec) {
|
||||||
|
commandLine file('$exePath').absolutePath
|
||||||
|
}
|
||||||
|
""".trimIndent())
|
||||||
|
settingsFile.appendText("rootProject.name = 'entry-point'")
|
||||||
|
|
||||||
|
generateSrcFile("main.kt", """
|
||||||
|
package org.test
|
||||||
|
|
||||||
|
fun myMain(args: Array<String>) {
|
||||||
|
println("myMain called!")
|
||||||
|
}
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
|
project.createRunner().withArguments(":assemble").build()
|
||||||
|
assertFileExists(exePath)
|
||||||
|
val result = project.createRunner().withArguments(":run").build()
|
||||||
|
assertTrue(result.output.contains("myMain called!"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Plugin should support the konan tooling model`() {
|
fun `Plugin should support the konan tooling model`() {
|
||||||
withProject {
|
withProject {
|
||||||
@@ -793,7 +826,7 @@ class ExperimentalPluginTests {
|
|||||||
val outputRoot = if (kind == OutputKind.EXECUTABLE) "exe" else "lib"
|
val outputRoot = if (kind == OutputKind.EXECUTABLE) "exe" else "lib"
|
||||||
val outputFile = file(
|
val outputFile = file(
|
||||||
"build/$outputRoot/main/$buildType/${kind.name.toLowerCase()}/${target.name}/" +
|
"build/$outputRoot/main/$buildType/${kind.name.toLowerCase()}/${target.name}/" +
|
||||||
"testProject${kind.compilerOutputKind.suffix(target)}"
|
"testProject${kind.compilerOutputKind.suffix(target)}"
|
||||||
)
|
)
|
||||||
assertEquals(outputFile, artifact.file)
|
assertEquals(outputFile, artifact.file)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user