A configurable zephyr board support.
This commit is contained in:
committed by
alexander-gorshenev
parent
d968fafec0
commit
9789420ed3
+7
-8
@@ -27,9 +27,8 @@ import org.gradle.api.plugins.BasePlugin
|
||||
import org.gradle.internal.reflect.Instantiator
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanBuildingTask
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.util.visibleName
|
||||
import java.io.File
|
||||
|
||||
/** Base class for all Kotlin/Native artifacts. */
|
||||
@@ -47,11 +46,11 @@ abstract class KonanBuildingConfig<T: KonanBuildingTask>(private val name_: Stri
|
||||
internal val aggregateBuildTask: Task
|
||||
|
||||
private val konanTargets: Iterable<KonanTarget>
|
||||
get() = targets.map { TargetManager(it).target }.distinct()
|
||||
get() = project.platformManager.toKonanTargets(targets).distinct()
|
||||
|
||||
init {
|
||||
for (target in konanTargets) {
|
||||
if (!target.enabled) {
|
||||
if (!project.platformManager.isEnabled(target)) {
|
||||
project.logger.warn("The target is not enabled on the current host: ${target.visibleName}")
|
||||
continue
|
||||
}
|
||||
@@ -109,7 +108,7 @@ abstract class KonanBuildingConfig<T: KonanBuildingTask>(private val name_: Stri
|
||||
}
|
||||
|
||||
protected fun createHostTaskIfDeclared(): Task? =
|
||||
this[TargetManager.host]?.let { hostBuild ->
|
||||
this[HostManager.host]?.let { hostBuild ->
|
||||
project.tasks.create(generateHostTaskName()) {
|
||||
it.group = BasePlugin.BUILD_GROUP
|
||||
it.description = generateHostTaskDescription(it, hostBuild.konanTarget)
|
||||
@@ -120,7 +119,7 @@ abstract class KonanBuildingConfig<T: KonanBuildingTask>(private val name_: Stri
|
||||
internal operator fun get(target: KonanTarget) = targetToTask[target]
|
||||
|
||||
fun getByTarget(target: String) = findByTarget(target) ?: throw NoSuchElementException("No such target for artifact $name: ${target}")
|
||||
fun findByTarget(target: String) = this[TargetManager(target).target]
|
||||
fun findByTarget(target: String) = this[project.platformManager.targetByName(target)]
|
||||
|
||||
fun getArtifactByTarget(target: String) = getByTarget(target).artifact
|
||||
fun findArtifactByTarget(target: String) = findByTarget(target)?.artifact
|
||||
@@ -145,9 +144,9 @@ abstract class KonanBuildingConfig<T: KonanBuildingTask>(private val name_: Stri
|
||||
fun dependsOn(vararg dependencies: Any?) = forEach { it.dependsOn(*dependencies) }
|
||||
|
||||
fun target(targetString: String, configureAction: T.() -> Unit) {
|
||||
val target = TargetManager(targetString).target
|
||||
val target = project.platformManager.targetByName(targetString)
|
||||
|
||||
if (!target.enabled) {
|
||||
if (!project.platformManager.isEnabled(target)) {
|
||||
project.logger.warn("Target '$targetString' of artifact '$name' is not supported on the current host")
|
||||
return
|
||||
}
|
||||
|
||||
+9
-7
@@ -24,8 +24,8 @@ import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanPlugin.Companion.COMPILE_ALL_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.tasks.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.util.visibleName
|
||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||
import org.jetbrains.kotlin.konan.target.customerDistribution
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -74,8 +74,14 @@ internal val Project.konanArtifactsContainer: NamedDomainObjectContainer<KonanBu
|
||||
get() = extensions.getByName(KonanPlugin.ARTIFACTS_CONTAINER_NAME)
|
||||
as NamedDomainObjectContainer<KonanBuildingConfig<*>>
|
||||
|
||||
internal val Project.platformManager: PlatformManager
|
||||
get() = findProperty("platformManager") as PlatformManager? ?:
|
||||
PlatformManager(customerDistribution(konanHome))
|
||||
|
||||
internal val Project.konanTargets: List<KonanTarget>
|
||||
get() = konanExtension.konanTargets
|
||||
get() = platformManager.toKonanTargets(konanExtension.targets)
|
||||
.filter{ platformManager.isEnabled(it) }
|
||||
.distinct()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
internal val Project.konanExtension: KonanExtension
|
||||
@@ -227,11 +233,7 @@ open class KonanExtension {
|
||||
var targets = mutableListOf("host")
|
||||
var languageVersion: String? = null
|
||||
var apiVersion: String? = null
|
||||
|
||||
val jvmArgs = mutableListOf<String>()
|
||||
|
||||
internal val konanTargets: List<KonanTarget>
|
||||
get() = targets.map { TargetManager(it).target }.distinct()
|
||||
}
|
||||
|
||||
class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderRegistry)
|
||||
|
||||
+5
-8
@@ -28,16 +28,16 @@ import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanArtifactSpec
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanArtifactWithLibrariesSpec
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanLibrariesSpec
|
||||
import org.jetbrains.kotlin.gradle.plugin.konanTargets
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.util.visibleName
|
||||
import java.io.File
|
||||
|
||||
internal val Project.host
|
||||
get() = TargetManager.host.visibleName
|
||||
get() = HostManager.host.visibleName
|
||||
|
||||
internal val Project.simpleOsName
|
||||
get() = TargetManager.simpleOsName()
|
||||
get() = HostManager.simpleOsName()
|
||||
|
||||
/** A task with a KonanTarget specified. */
|
||||
abstract class KonanTargetableTask: DefaultTask() {
|
||||
@@ -48,11 +48,8 @@ abstract class KonanTargetableTask: DefaultTask() {
|
||||
this.konanTarget = target
|
||||
}
|
||||
|
||||
val targetIsSupported: Boolean
|
||||
@Internal get() = konanTarget.enabled
|
||||
|
||||
val isCrossCompile: Boolean
|
||||
@Internal get() = (konanTarget != TargetManager.host)
|
||||
@Internal get() = (konanTarget != HostManager.host)
|
||||
|
||||
val target: String
|
||||
@Internal get() = konanTarget.visibleName
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ open class KonanCompilerDownloadTask : DefaultTask() {
|
||||
// Download dependencies if a user said so.
|
||||
if (downloadDependencies) {
|
||||
val runner = KonanCompilerRunner(project)
|
||||
project.konanExtension.konanTargets.forEach {
|
||||
project.konanTargets.forEach {
|
||||
runner.run("--check_dependencies", "-target", it.visibleName)
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.gradle.plugin.KonanLibrary
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanProgram
|
||||
import org.jetbrains.kotlin.gradle.plugin.konanArtifactsContainer
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import java.io.File
|
||||
|
||||
open class KonanGenerateCMakeTask : DefaultTask() {
|
||||
@@ -48,6 +48,8 @@ open class KonanGenerateCMakeTask : DefaultTask() {
|
||||
.mkdir()
|
||||
}
|
||||
|
||||
private val host = HostManager.host
|
||||
|
||||
private fun generateCMakeLists(
|
||||
projectName: String,
|
||||
interops: List<KonanInteropLibrary>,
|
||||
@@ -67,7 +69,7 @@ open class KonanGenerateCMakeTask : DefaultTask() {
|
||||
appendln()
|
||||
|
||||
for (interop in interops) {
|
||||
val task = interop[TargetManager.host] ?: continue
|
||||
val task = interop[host] ?: continue
|
||||
appendln(
|
||||
Call("cinterop")
|
||||
.arg("NAME", interop.name)
|
||||
@@ -77,7 +79,7 @@ open class KonanGenerateCMakeTask : DefaultTask() {
|
||||
}
|
||||
|
||||
for (library in libraries) {
|
||||
val task = library[TargetManager.host] ?: continue
|
||||
val task = library[host] ?: continue
|
||||
appendln(
|
||||
Call("konanc_library")
|
||||
.arg("NAME", library.name)
|
||||
@@ -87,7 +89,7 @@ open class KonanGenerateCMakeTask : DefaultTask() {
|
||||
}
|
||||
|
||||
for (program in programs) {
|
||||
val task = program[TargetManager.host] ?: continue
|
||||
val task = program[host] ?: continue
|
||||
appendln(
|
||||
Call("konanc_executable")
|
||||
.arg("NAME", program.name)
|
||||
@@ -101,7 +103,7 @@ open class KonanGenerateCMakeTask : DefaultTask() {
|
||||
private val File.relativePath get() = relativeTo(project.projectDir)
|
||||
|
||||
private val String.crossPlatformPath get() =
|
||||
if (TargetManager.host.family == Family.WINDOWS) replace('\\', '/') else this
|
||||
if (host.family == Family.WINDOWS) replace('\\', '/') else this
|
||||
|
||||
private val FileCollection.asCMakeSourceList: List<String>
|
||||
get() = files.map { it.relativePath.toString().crossPlatformPath }
|
||||
|
||||
-2
@@ -62,8 +62,6 @@ open class KonanInteropTask: KonanBuildingTask(), KonanInteropSpec {
|
||||
@InputFiles val linkFiles = mutableSetOf<FileCollection>()
|
||||
|
||||
override fun buildArgs() = mutableListOf<String>().apply {
|
||||
addArg("-properties", "${project.konanHome}/konan/konan.properties")
|
||||
|
||||
addArg("-o", artifact.canonicalPath)
|
||||
|
||||
addArgIfNotNull("-target", konanTarget.visibleName)
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
|
||||
class CMakeSpecification extends BaseKonanSpecification {
|
||||
def 'Plugin should generate CMake from project without additional settings'() {
|
||||
when:
|
||||
def sdlIncludePath
|
||||
def sdlLinkOptions
|
||||
switch (TargetManager.host.family) {
|
||||
switch (HostManager.host.family) {
|
||||
case Family.WINDOWS:
|
||||
sdlIncludePath = "C:/SDL2/include"
|
||||
sdlLinkOptions = "C:/SDL2/lib"
|
||||
@@ -22,7 +22,7 @@ class CMakeSpecification extends BaseKonanSpecification {
|
||||
sdlLinkOptions = "-L/usr/lib/x86_64-linux-gnu"
|
||||
break
|
||||
default:
|
||||
throw IllegalStateException("Unknown host: $TargetManager.host")
|
||||
throw IllegalStateException("Unknown host: ${HostManager.hostName}")
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
@@ -25,7 +25,7 @@ class KonanProject {
|
||||
static String DEFAULT_ARTIFACT_NAME = 'main'
|
||||
static String DEFAULT_INTEROP_NAME = "stdio"
|
||||
|
||||
static String HOST = TargetManager.hostName
|
||||
static String HOST = HostManager.hostName
|
||||
|
||||
File projectDir
|
||||
Path projectPath
|
||||
|
||||
+8
-7
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||
|
||||
class PathSpecification extends BaseKonanSpecification {
|
||||
|
||||
@@ -9,14 +9,13 @@ class PathSpecification extends BaseKonanSpecification {
|
||||
project.konanBuildDir.toPath().resolve(path).toFile().exists()
|
||||
}
|
||||
|
||||
def platformManager = new PlatformManager()
|
||||
|
||||
def 'Plugin should provide a correct path to the artifacts created'() {
|
||||
expect:
|
||||
def project = KonanProject.createEmpty(
|
||||
projectDirectory,
|
||||
new TargetManager('host')
|
||||
.getTargets()
|
||||
.findAll { k, v -> v.enabled }
|
||||
.collect { k, v -> k }
|
||||
platformManager.enabled.collect { t -> t.visibleName }
|
||||
) { KonanProject it ->
|
||||
it.generateSrcFile("main.kt")
|
||||
it.generateDefFile("interop.def", "")
|
||||
@@ -71,9 +70,10 @@ class PathSpecification extends BaseKonanSpecification {
|
||||
def project = KonanProject.create(projectDirectory)
|
||||
project.propertiesFile.write("konan.home=fakepath")
|
||||
def result = project.createRunner().withArguments('build').buildAndFail()
|
||||
def task = result.task(project.defaultCompilationTask())
|
||||
|
||||
then:
|
||||
result.task(project.defaultCompilationTask()).outcome == TaskOutcome.FAILED
|
||||
task == null || task.outcome == TaskOutcome.FAILED
|
||||
}
|
||||
|
||||
def 'Plugin should stop building if the stub generator classpath is empty'() {
|
||||
@@ -81,9 +81,10 @@ class PathSpecification extends BaseKonanSpecification {
|
||||
def project = KonanProject.createWithInterop(projectDirectory)
|
||||
project.propertiesFile.write("konan.home=fakepath")
|
||||
def result = project.createRunner().withArguments('build').buildAndFail()
|
||||
def task = result.task(project.compilationTask(KonanProject.DEFAULT_INTEROP_NAME))
|
||||
|
||||
then:
|
||||
result.task(project.compilationTask(KonanProject.DEFAULT_INTEROP_NAME)).outcome == TaskOutcome.FAILED
|
||||
task == null || task.outcome == TaskOutcome.FAILED
|
||||
}
|
||||
|
||||
def 'Plugin should remove custom output directories'() {
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.gradle.plugin.test
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import spock.lang.Requires
|
||||
import spock.lang.Unroll
|
||||
|
||||
@@ -58,7 +58,7 @@ class TaskSpecification extends BaseKonanSpecification {
|
||||
"includeDirs" | ""
|
||||
}
|
||||
|
||||
@Requires({ TargetManager.host == KonanTarget.MACBOOK })
|
||||
@Requires({ HostManager.host instanceof KonanTarget.MACBOOK })
|
||||
def 'Plugin should create framework tasks only for Apple targets'() {
|
||||
when:
|
||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
||||
@@ -91,7 +91,7 @@ class TaskSpecification extends BaseKonanSpecification {
|
||||
""".stripIndent())
|
||||
}
|
||||
def result = project.createRunner().withArguments('tasks', '--all').build()
|
||||
def hostName = TargetManager.getHostName()
|
||||
def hostName = HostManager.hostName
|
||||
|
||||
then:
|
||||
compilationTaskExists (result, 'defaultTarget', hostName)
|
||||
|
||||
Reference in New Issue
Block a user