Move out codesign to utils to be used not only for framework tests
This commit is contained in:
committed by
Pavel Punegov
parent
f517d5b4a3
commit
b99cc25e70
@@ -2612,6 +2612,9 @@ if (isMac()) {
|
||||
args "-lobjc", '-fobjc-arc'
|
||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcsmoke.dylib"
|
||||
}
|
||||
if (project.testTarget == 'ios_x64') {
|
||||
UtilsKt.codesign(project, "$buildDir/libobjcsmoke.dylib")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.gradle.api.Project
|
||||
import org.gradle.process.ExecResult
|
||||
import org.gradle.process.ExecSpec
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.konan.target.AppleConfigurables
|
||||
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||
@@ -123,6 +124,12 @@ fun runProcess(executor: (Action<in ExecSpec>) -> ExecResult?,
|
||||
fun runProcess(executor: (Action<in ExecSpec>) -> ExecResult?,
|
||||
executable: String, vararg args: String) = runProcess(executor, executable, args.toList())
|
||||
|
||||
/**
|
||||
* Returns Project's process executor
|
||||
* @see Project.exec
|
||||
*/
|
||||
fun localExecutor(project: Project) = { a: Action<in ExecSpec> -> project.exec(a) }
|
||||
|
||||
/**
|
||||
* Executes a given action with iPhone Simulator.
|
||||
*
|
||||
@@ -144,11 +151,22 @@ private fun simulator(project: Project) : ExecutorService = object : ExecutorSer
|
||||
out.toString("UTF-8").trim()
|
||||
}
|
||||
|
||||
private val iosDevice = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
|
||||
private val list by lazy {
|
||||
val out = ByteArrayOutputStream()
|
||||
val result = project.exec {
|
||||
it.commandLine(simctl, "list")
|
||||
it.standardOutput = out
|
||||
}
|
||||
result.assertNormalExitValue()
|
||||
out.toString("UTF-8").trim()
|
||||
}
|
||||
|
||||
private val iosDevice = project.findProperty("iosDevice")?.toString() ?: "iPhone 6"
|
||||
|
||||
override fun execute(action: Action<in ExecSpec>): ExecResult? = project.exec { execSpec ->
|
||||
println(list)
|
||||
action.execute(execSpec)
|
||||
with(execSpec) { commandLine = listOf(simctl, "spawn", iosDevice, executable) + args }
|
||||
with(execSpec) { commandLine = listOf("/usr/bin/xcrun", "simctl", "spawn", "iPhone 6", executable) + args }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,15 +40,7 @@ open class FrameworkTest : DefaultTask() {
|
||||
fun run() {
|
||||
val frameworkPath = "$testOutput/$frameworkName/${project.testTarget().name}"
|
||||
|
||||
// Sign framework
|
||||
val (stdOut, stdErr, exitCode) = runProcess(executor = localExecutor, executable = "/usr/bin/codesign",
|
||||
args = listOf("--verbose", "-s", "-", Paths.get(frameworkPath, "$frameworkName.framework").toString()))
|
||||
check(exitCode == 0, { """
|
||||
|Codesign failed with exitCode: $exitCode
|
||||
|stdout: $stdOut
|
||||
|stderr: $stdErr
|
||||
""".trimMargin()
|
||||
})
|
||||
codesign(project, Paths.get(frameworkPath, "$frameworkName.framework").toString())
|
||||
|
||||
// create a test provider and get main entry point
|
||||
val provider = Paths.get(testOutput, frameworkName, "provider.swift")
|
||||
@@ -88,13 +80,6 @@ open class FrameworkTest : DefaultTask() {
|
||||
check(exitCode == 0, { "Execution failed with exit code: $exitCode "})
|
||||
}
|
||||
|
||||
private val localExecutor = { a: Action<in ExecSpec> -> project.exec(a) }
|
||||
|
||||
private fun Project.platformManager() = rootProject.findProperty("platformManager") as PlatformManager
|
||||
|
||||
private fun Project.testTarget() = platformManager()
|
||||
.targetManager(project.findProperty("testTarget") as String?).target
|
||||
|
||||
private fun swiftc(sources: List<String>, options: List<String>, output: Path) {
|
||||
val target = project.testTarget()
|
||||
val platform = project.platformManager().platform(target)
|
||||
@@ -112,7 +97,7 @@ open class FrameworkTest : DefaultTask() {
|
||||
val args = listOf("-sdk", configs.absoluteTargetSysRoot, "-target", swiftTarget) +
|
||||
options + "-o" + output.toString() + sources
|
||||
|
||||
val (stdOut, stdErr, exitCode) = runProcess(executor = localExecutor, executable = compiler, args = args)
|
||||
val (stdOut, stdErr, exitCode) = runProcess(executor = localExecutor(project), executable = compiler, args = args)
|
||||
|
||||
println("""
|
||||
|$compiler finished with exit code: $exitCode
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||
|
||||
fun Project.platformManager() = rootProject.findProperty("platformManager") as PlatformManager
|
||||
|
||||
fun Project.testTarget() = platformManager().targetManager(project.findProperty("testTarget") as String?).target
|
||||
|
||||
/**
|
||||
* Ad-hoc signing of the specified path
|
||||
*/
|
||||
fun codesign(project: Project, path: String) {
|
||||
check(HostManager.hostIsMac, { "Apple specific code signing" } )
|
||||
val (stdOut, stdErr, exitCode) = runProcess(executor = localExecutor(project), executable = "/usr/bin/codesign",
|
||||
args = listOf("--verbose", "-s", "-", path))
|
||||
check(exitCode == 0, { """
|
||||
|Codesign failed with exitCode: $exitCode
|
||||
|stdout: $stdOut
|
||||
|stderr: $stdErr
|
||||
""".trimMargin()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user