override suspend fun run()

in sources/amper-cli/src/org/jetbrains/amper/tasks/ios/IosBuildTask.kt [64:145]


    override suspend fun run(dependenciesResult: List<TaskResult>, executionContext: TaskGraphExecutionContext): TaskResult {
        val projectInitialInfo = dependenciesResult.requireSingleDependency<ManageXCodeProjectTask.Result>()
        val prebuildResult = dependenciesResult.requireSingleDependency<IosPreBuildTask.Result>()
        val xcodeSettings = projectInitialInfo.getResolvedXcodeSettings(buildType)

        val workingDir = taskOutputPath.path.createDirectories()
        val derivedDataPath = workingDir / "derivedData"
        val objRootPath = workingDir / "tmp"
        val symRootPath = workingDir / "bin"

        val xcodebuildArgs = buildList {
            this += "xcrun"
            this += "xcodebuild"
            this += "-project"; this += projectInitialInfo.projectDir.pathString
            this += "-scheme"; this += projectInitialInfo.targetName
            this += "-configuration"; this += buildType.name
            this += "-arch"; this += platform.architecture
            this += "-derivedDataPath"; this += derivedDataPath.pathString
            this += "-sdk"; this += platform.sdk
            this += "${BuildSettingNames.OBJROOT}=${objRootPath.pathString}"
            this += "${BuildSettingNames.SYMROOT}=${symRootPath.pathString}"
            this += "AMPER_WRAPPER_PATH=${CliContext.wrapperScriptPath.absolutePathString()}"
            if (!platform.isIosSimulator && !xcodeSettings.hasTeamId && !xcodeSettings.isSigningDisabled) {
                logger.warn("`DEVELOPMENT_TEAM` build setting is not detected in the Xcode project. " +
                        "Adding `CODE_SIGNING_ALLOWED=NO` to disable signing. " +
                        "You can still sign the app manually later.")
                this += "CODE_SIGNING_ALLOWED=NO"
            }
            this += "build"
        }

        coroutineScope {
            val executable = prepareLogParsingUtility()
            val pipe = ProcessInput.Pipe()

            logger.info("Using xcbeautify ($XCBEAUTIFY_VERSION) to parse xcodebuild output.")

            // Need to launch log parser in parallel
            val parserProcessJob = launch {
                runProcess(
                    workingDir = workingDir,
                    command = listOf(
                        executable.pathString,
                        "--disable-logging", // disable big version banner - we do it ourselves
                    ),
                    outputListener = LoggingProcessOutputListener(logger),
                    input = pipe,
                )
            }

            val fullXcodebuildLog = taskOutputPath.path / "xcodebuild.log"
            val outputListener = pipe.pipeInListener + FileLoggingProcessOutputListener(fullXcodebuildLog)
            spanBuilder("xcodebuild")
                .setAmperModule(module)
                .setListAttribute("args", xcodebuildArgs)
                .use { span ->
                    val result = processRunner.runProcessAndGetOutput(
                        workingDir = workingDir,
                        command = xcodebuildArgs,
                        span = span,
                        environment = mapOf(
                            IosPreBuildTask.Result.ENV_JSON_NAME to Json.encodeToString(prebuildResult),
                        ),
                        redirectErrorStream = true,
                        outputListener = outputListener,
                    )

                    // Ensure the parser is done to avoid putting the final log entries into the middle of the log
                    parserProcessJob.join()

                    logger.info("Full xcodebuild log can be found at file://${fullXcodebuildLog.absolutePathString()}")
                    if (result.exitCode != 0) {
                        userReadableError("xcodebuild invocation failed, check the log above.")
                    }
                }
        }

        return Result(
            bundleId = xcodeSettings.bundleId,
            appPath = symRootPath / "${buildType.name}-${platform.sdk}" / "${xcodeSettings.productName}.app",
        )
    }