[gradle-plugin] Support custom entry points (#1996)
This commit is contained in:
committed by
Nikolay Igotti
parent
66732675e5
commit
88e86cbdd4
@@ -914,6 +914,9 @@ components.main {
|
||||
|
||||
// Set up output kinds
|
||||
outputKinds = [EXECUTABLE, KLIBRARY, FRAMEWORK, DYNAMIC, STATIC]
|
||||
|
||||
// Specify custom entry point for executables
|
||||
entryPoint = "org.test.myMain"
|
||||
|
||||
// Target-specific options
|
||||
target('linux_x64') {
|
||||
|
||||
+4
@@ -106,6 +106,10 @@ interface KotlinNativeComponent: ComponentWithBinaries, ComponentWithDependencie
|
||||
|
||||
val publishJavadoc: Boolean
|
||||
val publishSources: Boolean
|
||||
|
||||
/** Allows setting custom entry point for executables */
|
||||
var entryPoint: String?
|
||||
fun entryPoint(value: String)
|
||||
// endregion
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -155,5 +155,8 @@ abstract class AbstractKotlinNativeComponent @Inject constructor(
|
||||
action.execute(dependencies)
|
||||
}
|
||||
|
||||
override var entryPoint: String? = null
|
||||
override fun entryPoint(value: String) { entryPoint = value }
|
||||
|
||||
// endregion
|
||||
}
|
||||
+6
@@ -23,6 +23,7 @@ import org.gradle.api.file.FileSystemLocation
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.Optional
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
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>
|
||||
@Input get() = binary.linkerOpts
|
||||
|
||||
val entryPoint: String?
|
||||
@Optional @Input get() = binary.component.entryPoint
|
||||
|
||||
val outputFile: File
|
||||
get() = outputLocationProvider.get().asFile
|
||||
|
||||
@@ -113,6 +117,8 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
||||
|
||||
add("-Xmulti-platform")
|
||||
|
||||
addArgIfNotNull("-entry", entryPoint)
|
||||
|
||||
addAll(additionalCompilerOptions)
|
||||
|
||||
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
|
||||
fun `Plugin should support the konan tooling model`() {
|
||||
withProject {
|
||||
@@ -793,7 +826,7 @@ class ExperimentalPluginTests {
|
||||
val outputRoot = if (kind == OutputKind.EXECUTABLE) "exe" else "lib"
|
||||
val outputFile = file(
|
||||
"build/$outputRoot/main/$buildType/${kind.name.toLowerCase()}/${target.name}/" +
|
||||
"testProject${kind.compilerOutputKind.suffix(target)}"
|
||||
"testProject${kind.compilerOutputKind.suffix(target)}"
|
||||
)
|
||||
assertEquals(outputFile, artifact.file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user