From aecf6bb9a1b945f7088f5a8b7b69e150c116d3f9 Mon Sep 17 00:00:00 2001 From: Nikita Lipsky Date: Mon, 17 Oct 2022 16:50:16 +0300 Subject: [PATCH] Fix compose gradle plugin for iOS device deployment: (#2407) - Move cleaning up build directory from packComposeUikitApplicationForXCode Gradle task to registerConnectedDeviceTasks as the first one runs during xcode build and could delete files placed by xcode in parallel before (such as Info.plist). - Remove workaround of running xcodebuild twice as the original problem the most probably was provoded by incorrect build directory cleanup - Remove sources from xcodegen configuratiom as we do not need them in the resulting .app --- .../configureTaskToGenerateXcodeProject.kt | 10 ----- .../internal/registerConnectedDeviceTasks.kt | 41 ++++++++++--------- ...entalPackComposeApplicationForXCodeTask.kt | 12 +++--- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/configureTaskToGenerateXcodeProject.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/configureTaskToGenerateXcodeProject.kt index f66db808..20fb089a 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/configureTaskToGenerateXcodeProject.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/configureTaskToGenerateXcodeProject.kt @@ -42,16 +42,6 @@ internal fun Project.configureTaskToGenerateXcodeProject( name: GradleCompile info: path: plists/Ios/Info.plist - properties: - UILaunchStoryboardName: "" - method: "development" - sources: - - path: "../../../src/" - excludes: - - "jvm*/**" - - "desktop*/**" - - "android*/**" - - "*Test/**" settings: LIBRARY_SEARCH_PATHS: "$(inherited)" ENABLE_BITCODE: "YES" diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerConnectedDeviceTasks.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerConnectedDeviceTasks.kt index 70a98797..6c41e4c0 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerConnectedDeviceTasks.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerConnectedDeviceTasks.kt @@ -53,26 +53,27 @@ fun Project.registerConnectedDeviceTasks( // xcrun xcodebuild -showsdks (list all sdk) val sdk = SDK_PREFIX_IPHONEOS + getSimctlListData().runtimes.first().version val scheme = projectName // xcrun xcodebuild -list -project . (list all schemes) - repeat(2) { - // todo repeat(2) is workaround of error (domain=NSPOSIXErrorDomain, code=22) - // The bundle identifier of the application could not be determined - // Ensure that the application's Info.plist contains a value for CFBundleIdentifier. - runExternalTool( - MacUtils.xcrun, - listOf( - "xcodebuild", - "-scheme", scheme, - "-project", ".", - "-configuration", configName, - "-derivedDataPath", "build", - "-arch", "arm64", - "-sdk", sdk, - "-allowProvisioningUpdates", - "-allowProvisioningDeviceRegistration", - ), - workingDir = xcodeProjectDir - ) - } + + val buildDir = "build" + + // cleanup build directory as xcodebuild does not do it (provoking unexpected side effects). + project.delete(xcodeProjectDir.resolve(buildDir)) + + runExternalTool( + MacUtils.xcrun, + listOf( + "xcodebuild", + "-scheme", scheme, + "-project", ".", + "-configuration", configName, + "-derivedDataPath", buildDir, + "-arch", "arm64", + "-sdk", sdk, + "-allowProvisioningUpdates", + "-allowProvisioningDeviceRegistration", + ), + workingDir = xcodeProjectDir + ) } } diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/tasks/ExperimentalPackComposeApplicationForXCodeTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/tasks/ExperimentalPackComposeApplicationForXCodeTask.kt index d6c7866f..5b308cb5 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/tasks/ExperimentalPackComposeApplicationForXCodeTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/tasks/ExperimentalPackComposeApplicationForXCodeTask.kt @@ -12,6 +12,8 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.* import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType import java.io.File +import java.nio.file.Files +import java.nio.file.StandardCopyOption abstract class ExperimentalPackComposeApplicationForXCodeTask : DefaultTask() { @get:Input @@ -32,8 +34,6 @@ abstract class ExperimentalPackComposeApplicationForXCodeTask : DefaultTask() { @TaskAction fun run() { val destinationDir = destinationDir.get().asFile - project.delete(destinationDir) - project.mkdir(destinationDir) val executableSource = kotlinBinary.get().asFile val dsymSource = File(executableSource.absolutePath + ".dSYM") @@ -46,14 +46,14 @@ abstract class ExperimentalPackComposeApplicationForXCodeTask : DefaultTask() { val destFile = dsymDestination.resolve(relativePath) destFile.parentFile.mkdirs() if (sourceFile.name == executableSource.name) { - sourceFile.copyTo(destFile.resolveSibling(executableDestination.name)) + sourceFile.copyTo(destFile.resolveSibling(executableDestination.name), true) } else { - sourceFile.copyTo(destFile) + sourceFile.copyTo(destFile, true) } } - executableDestination.parentFile.mkdirs() - executableSource.copyTo(executableDestination) + // We need to preserve executable flag for resulting executable, "FileKt.copyTo" extension method does not allow this. + Files.copy(executableSource.toPath(), executableDestination.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING) } internal enum class UikitTarget(val simulator: Boolean, val targetName: String) {