From b1b3020007ed7e6ab9ebca47bfae544ff453fe79 Mon Sep 17 00:00:00 2001 From: archinamon Date: Thu, 13 Jun 2019 18:03:17 +0300 Subject: [PATCH 1/2] implementing manual selector of target arch to build binaries for --- .../cocoapods/gradle/plugin/CocoapodsCompileTask.kt | 8 +++++--- .../cocoapods/gradle/plugin/CocoapodsExtension.kt | 5 ++++- .../alecstrong/cocoapods/gradle/plugin/CocoapodsPlugin.kt | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt index 8a1f55b..91412c0 100644 --- a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt +++ b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt @@ -14,6 +14,7 @@ import java.io.File open class CocoapodsCompileTask : DefaultTask() { @InputFiles lateinit var inputs: FileCollection + @Input internal lateinit var buildDeviceArchTarget: Architecture @Input internal var buildType: NativeBuildType? = null set(value) { val outputs = mutableListOf("${project.buildDir.path}/${project.name}.framework") @@ -58,7 +59,7 @@ open class CocoapodsCompileTask : DefaultTask() { binaryPath: String, bundleName: String ) { - logger.debug("Creating fat binary for $binaryPath $bundleName") + logger.info("Creating fat binary for $binaryPath $bundleName") val finalContainerPath = "${project.buildDir.path}/$bundleName" val finalOutputPath = "$finalContainerPath/$binaryPath" @@ -72,11 +73,12 @@ open class CocoapodsCompileTask : DefaultTask() { compilations.forEach { compilation -> val output = compilation.outputFile.get().parentFile.absolutePath val target = compilation.binary.target.konanTarget - if (target.architecture == Architecture.ARM64) { + if (target.architecture == buildDeviceArchTarget) { + logger.info("Selected device arch target: ${target.architecture}") deviceParentDir = output } - logger.debug("Lipo'ing for arch ${target.architecture} with path $output/$bundleName/$binaryPath") + logger.info("Lipo'ing for arch ${target.architecture} with path $output/$bundleName/$binaryPath") args.addAll(listOf( "-arch", target.architecture(), "$output/$bundleName/$binaryPath" )) diff --git a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsExtension.kt b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsExtension.kt index b60bbb4..2f49f5a 100644 --- a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsExtension.kt +++ b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsExtension.kt @@ -1,9 +1,12 @@ package com.alecstrong.cocoapods.gradle.plugin +import org.jetbrains.kotlin.konan.target.Architecture + open class CocoapodsExtension( var version: String = "1.0.0-LOCAL", - var homepage: String? = null, var deploymentTarget: String = "10.0", + var buildDeviceArchTarget: Architecture = Architecture.ARM64, + var homepage: String? = null, var authors: String? = null, var license: String? = null, var summary: String? = null, diff --git a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsPlugin.kt b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsPlugin.kt index ee1abfd..d200f2f 100644 --- a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsPlugin.kt +++ b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsPlugin.kt @@ -49,6 +49,7 @@ open class CocoapodsPlugin : Plugin { CocoapodsCompileTask::class.java ) { task -> task.dependsOn(compilations) + task.buildDeviceArchTarget = extension.buildDeviceArchTarget task.buildType = buildType task.compilations = compilations task.group = GROUP From 1588d78565dd2620935da0e3abfe4f0801a80262 Mon Sep 17 00:00:00 2001 From: archinamon Date: Thu, 13 Jun 2019 18:04:23 +0300 Subject: [PATCH 2/2] do not fail PlistBuddy if Delete cmd not succeeded --- .../gradle/plugin/CocoapodsCompileTask.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt index 91412c0..9569721 100644 --- a/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt +++ b/gradle-plugin/src/main/kotlin/com/alecstrong/cocoapods/gradle/plugin/CocoapodsCompileTask.kt @@ -1,11 +1,14 @@ package com.alecstrong.cocoapods.gradle.plugin import org.gradle.api.DefaultTask +import org.gradle.api.Project import org.gradle.api.file.FileCollection import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.OutputDirectories import org.gradle.api.tasks.TaskAction +import org.gradle.process.ExecSpec +import org.gradle.process.internal.ExecException import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import org.jetbrains.kotlin.konan.target.Architecture @@ -109,16 +112,16 @@ open class CocoapodsCompileTask : DefaultTask() { // clean plist (only works for frameworks) val plistPath = "$finalContainerPath/Info.plist" if (File(plistPath).exists()) { - project.exec { exec -> + project.tryExec { exec -> exec.executable = "/usr/libexec/PlistBuddy" exec.args = listOf("-c", "Delete :UIRequiredDeviceCapabilities", plistPath) - }.rethrowFailure().assertNormalExitValue().exitValue + } // Clear supported platforms - project.exec { exec -> + project.tryExec { exec -> exec.executable = "/usr/libexec/PlistBuddy" exec.args = listOf("-c", "Delete :CFBundleSupportedPlatforms:0", plistPath) - }.rethrowFailure().assertNormalExitValue() + } // only add iPhoneOS as supported platform project.exec { exec -> @@ -127,4 +130,11 @@ open class CocoapodsCompileTask : DefaultTask() { }.rethrowFailure().assertNormalExitValue() } } + + private fun Project.tryExec(action: (ExecSpec) -> Unit) = try { + exec(action::invoke).exitValue + } catch (exc: ExecException) { + logger.info("Silent error: ${exc.message}") + exc.printStackTrace() + } } \ No newline at end of file