From f56a88be8101ce96973f4b573a7fd74a1b31d065 Mon Sep 17 00:00:00 2001 From: Elijah Semyonov Date: Wed, 21 Jun 2023 10:21:32 +0200 Subject: [PATCH] Export JAVA_HOME to xcodegen (#606) * Explicitly pass environmental variables to Xcode build script. * Integrate COMPOSE_DEMO_APPLE_TEAM_ID variable into xcodegen * Update prebuild script in project.template.yml Refactor the prebuild script for better readability and maintainability. Removed unnecessary environment variables and simplified Gradle command. * Update gradle CLI script in project.template.yml Refactor prebuildScripts in project.template.yml for better readability and maintainability. Separate relevant commands into distinct lines to improve code structure. * Add echo JAVA_HOME in build script --------- Co-authored-by: dima.avdeev --- compose/mpp/demo/.gitignore | 1 + .../{project.yml => project.template.yml} | 13 ++++++--- compose/mpp/demo/regenerate_xcode_project.sh | 27 +++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) rename compose/mpp/demo/{project.yml => project.template.yml} (61%) diff --git a/compose/mpp/demo/.gitignore b/compose/mpp/demo/.gitignore index 42ffd7beeac30..ea1111ec79650 100644 --- a/compose/mpp/demo/.gitignore +++ b/compose/mpp/demo/.gitignore @@ -1,2 +1,3 @@ *.xcodeproj plists +project.generated.yml \ No newline at end of file diff --git a/compose/mpp/demo/project.yml b/compose/mpp/demo/project.template.yml similarity index 61% rename from compose/mpp/demo/project.yml rename to compose/mpp/demo/project.template.yml index 69d067656f291..b05818a5d89a9 100644 --- a/compose/mpp/demo/project.yml +++ b/compose/mpp/demo/project.template.yml @@ -1,8 +1,9 @@ -name: ComposeDemo +# this YML is to be used as a template with %@PLACEHOLDER_VALUES@% replaced with actual ones within regenerate_xcode_project.sh +name: %@PROJECT_NAME@% options: bundleIdPrefix: org.jetbrains settings: - DEVELOPMENT_TEAM: N462MKSJ7M + DEVELOPMENT_TEAM: %@COMPOSE_DEMO_APPLE_TEAM_ID@% CODE_SIGN_IDENTITY: "iPhone Developer" CODE_SIGN_STYLE: Automatic MARKETING_VERSION: "1.0" @@ -14,7 +15,13 @@ targets: platform: iOS deploymentTarget: "12.0" prebuildScripts: - - script: cd "$SRCROOT" && OUT_DIR=`pwd`/out JAVA_TOOLS_JAR=/Users/jetbrains/jetpack_compose_ui/compose-jb/compose/scripts/../external/tools.jar ALLOW_PUBLIC_REPOS=1 ANDROIDX_PROJECTS=compose ../../../gradlew -i -Pandroidx.compose.multiplatformEnabled=true --no-daemon -Pkotlin.compiler.execution.strategy="in-process" -p . packForXCode + - script: | + cd "$SRCROOT" + export JAVA_HOME=%@JAVA_HOME@% + export OUT_DIR=`pwd`/../../../out + echo "JAVA_HOME: $JAVA_HOME" + echo "OUT_DIR: $OUT_DIR" + ../../../gradlew -i --no-daemon -p . packForXCode name: GradleCompile info: path: plists/Ios/Info.plist diff --git a/compose/mpp/demo/regenerate_xcode_project.sh b/compose/mpp/demo/regenerate_xcode_project.sh index 7189242fbbc60..a550caa5e4c7f 100755 --- a/compose/mpp/demo/regenerate_xcode_project.sh +++ b/compose/mpp/demo/regenerate_xcode_project.sh @@ -5,16 +5,33 @@ cd "$(dirname "$0")" || exit if command -v xcodegen >/dev/null 2>&1; then # xcodegen exists + PROJECT_NAME=ComposeDemo - projPath="ComposeDemo.xcodeproj" + if [[ -z "$COMPOSE_DEMO_APPLE_TEAM_ID" ]]; then + echo "COMPOSE_DEMO_APPLE_TEAM_ID is not set" + COMPOSE_DEMO_APPLE_TEAM_ID="N462MKSJ7M" + fi + + if [[ -z "$JAVA_HOME" ]]; then + echo "JAVA_HOME is not set" + exit 1 + fi - if [ -d "$projPath" ]; then + PROJECT_FILE_PATH="$PROJECT_NAME.xcodeproj" + + if [ -d "$PROJECT_FILE_PATH" ]; then echo "Removing existing project" - rm -rf "$projPath" + rm -rf "$PROJECT_FILE_PATH" fi - xcodegen - open $projPath + INPUT_FILE="project.template.yml" + OUTPUT_FILE="project.generated.yml" + + # replace template placeholders with actual values + sed -e "s|%@JAVA_HOME@%|$JAVA_HOME|g" -e "s|%@PROJECT_NAME@%|$PROJECT_NAME|g" -e "s|%@COMPOSE_DEMO_APPLE_TEAM_ID@%|$COMPOSE_DEMO_APPLE_TEAM_ID|g" $INPUT_FILE > $OUTPUT_FILE + + xcodegen --spec $OUTPUT_FILE + open $PROJECT_FILE_PATH else # xcodegen does not exist echo "Error: xcodegen not found. Please install it using 'brew install xcodegen'."