Skip to content

Commit 00a171f

Browse files
Optimize iOS build process by increasing VM RAM and skipping redundant Cocoapods installation.
- Increased ByteCodeTranslator heap size to 2048MB in IPhoneBuilder. - Made `pod install` conditional in IPhoneBuilder to avoid unnecessary execution for projects without pods. - Added support for `ios.pods.skipInstall` build hint to allow external scripts to handle pod installation. - Updated `scripts/build-ios-app.sh` and `scripts/run-ios-ui-tests.sh` to support building directly from `.xcodeproj` when no `.xcworkspace` is present.
1 parent d33315b commit 00a171f

File tree

3 files changed

+67
-34
lines changed

3 files changed

+67
-34
lines changed

maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/IPhoneBuilder.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,12 @@ public boolean build(File sourceZip, BuildRequest request) throws BuildException
305305
iosPods += (((iosPods.length() > 0) ? ",":"") + "FBSDKCoreKit "+fbPodsVersion+",FBSDKLoginKit "+fbPodsVersion+",FBSDKShareKit "+fbPodsVersion);
306306
}
307307

308-
runPods = true;
309-
310-
311308
String googleAdUnitId = request.getArg("ios.googleAdUnitId", request.getArg("google.adUnitId", null));
309+
runPods = (iosPods.length() > 0) ||
310+
(googleAdUnitId != null && googleAdUnitId.length() > 0) ||
311+
"true".equals(request.getArg("ios.useCocoapods", "false")) ||
312+
"true".equals(request.getArg("ios.pods.alwaysRun", "false"));
313+
312314
boolean usePodsForGoogleAds = runPods && googleAdUnitId != null && googleAdUnitId.length() > 0;
313315
if (usePodsForGoogleAds) {
314316
iosPods += (((iosPods.length() > 0) ? ",":"") + "Firebase/Core,Firebase/AdMob");
@@ -1527,7 +1529,7 @@ public void usesClassMethod(String cls, String method) {
15271529

15281530
debug("Building using addLibs="+addLibs);
15291531
try {
1530-
if (!exec(userDir, env, 420000, "java", "-DsaveUnitTests=" + isUnitTestMode(), "-DfieldNullChecks=" + fieldNullChecks, "-DINCLUDE_NPE_CHECKS=" + includeNullChecks, "-DbundleVersionNumber=" + bundleVersionNumber, "-Xmx384m",
1532+
if (!exec(userDir, env, 420000, "java", "-DsaveUnitTests=" + isUnitTestMode(), "-DfieldNullChecks=" + fieldNullChecks, "-DINCLUDE_NPE_CHECKS=" + includeNullChecks, "-DbundleVersionNumber=" + bundleVersionNumber, "-Xmx2048m",
15311533
"-jar", parparVMCompilerJar, "ios",
15321534
classesDir.getAbsolutePath() + ";" + resDir.getAbsolutePath() + ";" +
15331535
buildinRes.getAbsolutePath(),
@@ -1810,9 +1812,12 @@ public void usesClassMethod(String cls, String method) {
18101812
return false;
18111813
}
18121814

1813-
if (!exec(new File(tmpFile, "dist"), podTimeout, pod, "init")) {
1814-
log("Failed to run "+pod+" init. Make sure you have Cocoapods installed.");
1815-
return false;
1815+
boolean skipPodInstall = "true".equals(request.getArg("ios.pods.skipInstall", "false"));
1816+
if (!skipPodInstall) {
1817+
if (!exec(new File(tmpFile, "dist"), podTimeout, pod, "init")) {
1818+
log("Failed to run "+pod+" init. Make sure you have Cocoapods installed.");
1819+
return false;
1820+
}
18161821
}
18171822
File podFile = new File(new File(tmpFile, "dist"), "Podfile");
18181823
if (!podFile.exists()) {
@@ -1909,23 +1914,25 @@ public void usesClassMethod(String cls, String method) {
19091914
Map<String,String> podEnv = new HashMap<String,String>();
19101915
podEnv.put("LANG", "en_US.UTF-8");
19111916

1912-
if (!exec(new File(tmpFile, "dist"), (File)null, podTimeout, podEnv, pod, "install")) {
1913-
// Perhaps we need to update the master repo
1914-
log("Failed to exec cocoapods. Trying to update master repo...");
1915-
if (!exec(new File(tmpFile, "dist"), podTimeout * 3, pod, "repo", "update")) {
1916-
log("Failed to update cocoapods master repo. Trying to clean up spec repos");
1917+
if (!skipPodInstall) {
1918+
if (!exec(new File(tmpFile, "dist"), (File)null, podTimeout, podEnv,pod, "install")) {
1919+
// Perhaps we need to update the master repo
1920+
log("Failed to exec cocoapods. Trying to update master repo...");
19171921
if (!exec(new File(tmpFile, "dist"), podTimeout * 3, pod, "repo", "update")) {
1918-
log("Failed to update cocoapods master repo event after cleaning spec repos.");
1919-
return false;
1922+
log("Failed to update cocoapods master repo. Trying to clean up spec repos");
1923+
if (!exec(new File(tmpFile, "dist"), podTimeout * 3, pod, "repo", "update")) {
1924+
log("Failed to update cocoapods master repo event after cleaning spec repos.");
1925+
return false;
1926+
}
19201927
}
1921-
}
19221928

1923-
if (!exec(new File(tmpFile, "dist"), (File)null, podTimeout, podEnv,pod, "install")) {
1924-
log("Cocoapods failed even after updating master repo");
1925-
log("Trying to cleanup spec repos");
19261929
if (!exec(new File(tmpFile, "dist"), (File)null, podTimeout, podEnv,pod, "install")) {
1927-
log("Cocoapods failed even after cleaning up spec repos.");
1928-
return false;
1930+
log("Cocoapods failed even after updating master repo");
1931+
log("Trying to cleanup spec repos");
1932+
if (!exec(new File(tmpFile, "dist"), (File)null, podTimeout, podEnv,pod, "install")) {
1933+
log("Cocoapods failed even after cleaning up spec repos.");
1934+
return false;
1935+
}
19291936
}
19301937
}
19311938
}

scripts/build-ios-app.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,44 @@ for candidate in "$PROJECT_DIR"/*.xcworkspace; do
120120
break
121121
fi
122122
done
123-
if [ -z "$WORKSPACE" ]; then
124-
bia_log "Failed to locate xcworkspace in $PROJECT_DIR" >&2
125-
ls "$PROJECT_DIR" >&2 || true
126-
exit 1
123+
124+
if [ -n "$WORKSPACE" ]; then
125+
bia_log "Found xcworkspace: $WORKSPACE"
126+
PROJECT_ARG="-workspace \"$WORKSPACE\""
127+
OUTPUT_PATH="$WORKSPACE"
128+
else
129+
bia_log "No xcworkspace found; looking for xcodeproj"
130+
PROJECT=""
131+
for candidate in "$PROJECT_DIR"/*.xcodeproj; do
132+
if [ -d "$candidate" ]; then
133+
PROJECT="$candidate"
134+
break
135+
fi
136+
done
137+
if [ -z "$PROJECT" ]; then
138+
bia_log "Failed to locate xcworkspace or xcodeproj in $PROJECT_DIR" >&2
139+
ls "$PROJECT_DIR" >&2 || true
140+
exit 1
141+
fi
142+
bia_log "Found xcodeproj: $PROJECT"
143+
PROJECT_ARG="-project \"$PROJECT\""
144+
OUTPUT_PATH="$PROJECT"
127145
fi
128-
bia_log "Found xcworkspace: $WORKSPACE"
129146

130147

131148
# Make these visible to the next GH Actions step
132149
if [ -n "${GITHUB_OUTPUT:-}" ]; then
133150
{
134-
echo "workspace=$WORKSPACE"
151+
echo "workspace=$OUTPUT_PATH"
135152
echo "scheme=HelloCodenameOne"
136153
} >> "$GITHUB_OUTPUT"
137154
fi
138155

139-
bia_log "Emitted outputs -> workspace=$WORKSPACE, scheme=HelloCodenameOne"
156+
bia_log "Emitted outputs -> workspace=$OUTPUT_PATH, scheme=HelloCodenameOne"
140157

141158
# (Optional) dump xcodebuild -list for debugging
142159
ARTIFACTS_DIR="${ARTIFACTS_DIR:-$REPO_ROOT/artifacts}"
143160
mkdir -p "$ARTIFACTS_DIR"
144-
xcodebuild -workspace "$WORKSPACE" -list > "$ARTIFACTS_DIR/xcodebuild-list.txt" 2>&1 || true
161+
eval xcodebuild $PROJECT_ARG -list > "$ARTIFACTS_DIR/xcodebuild-list.txt" 2>&1 || true
145162

146163
exit 0

scripts/run-ios-ui-tests.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ if [ -z "$REQUESTED_SCHEME" ]; then
8282
if [[ "$WORKSPACE_PATH" == *.xcworkspace ]]; then
8383
REQUESTED_SCHEME="$(basename "$WORKSPACE_PATH" .xcworkspace)"
8484
else
85-
REQUESTED_SCHEME="$(basename "$WORKSPACE_PATH")"
85+
REQUESTED_SCHEME="$(basename "$WORKSPACE_PATH" .xcodeproj)"
8686
fi
8787
fi
8888
SCHEME="$REQUESTED_SCHEME"
@@ -97,8 +97,17 @@ mkdir -p "$SCREENSHOT_RAW_DIR" "$SCREENSHOT_PREVIEW_DIR"
9797
export CN1SS_OUTPUT_DIR="$SCREENSHOT_RAW_DIR"
9898
export CN1SS_PREVIEW_DIR="$SCREENSHOT_PREVIEW_DIR"
9999

100+
# Determine build argument (workspace vs project)
101+
if [[ "$WORKSPACE_PATH" == *.xcodeproj ]]; then
102+
BUILD_ARG="-project \"$WORKSPACE_PATH\""
103+
# For project files, shared schemes are inside the .xcodeproj directory
104+
SCHEME_FILE="$WORKSPACE_PATH/xcshareddata/xcschemes/$SCHEME.xcscheme"
105+
else
106+
BUILD_ARG="-workspace \"$WORKSPACE_PATH\""
107+
SCHEME_FILE="$WORKSPACE_PATH/xcshareddata/xcschemes/$SCHEME.xcscheme"
108+
fi
109+
100110
# Patch scheme env vars to point to our runtime dirs
101-
SCHEME_FILE="$WORKSPACE_PATH/xcshareddata/xcschemes/$SCHEME.xcscheme"
102111
if [ -f "$SCHEME_FILE" ]; then
103112
if sed --version >/dev/null 2>&1; then
104113
# GNU sed
@@ -163,7 +172,7 @@ normalize_destination() {
163172
auto_select_destination() {
164173
local show_dest rc=0 best_line="" best_key="" line payload platform id name os priority key part value
165174
set +e
166-
show_dest="$(xcodebuild -workspace "$WORKSPACE_PATH" -scheme "$SCHEME" -sdk iphonesimulator -showdestinations 2>/dev/null)"
175+
show_dest="$(eval xcodebuild $BUILD_ARG -scheme "$SCHEME" -sdk iphonesimulator -showdestinations 2>/dev/null)"
167176
rc=$?
168177
set -e
169178

@@ -347,8 +356,8 @@ BUILD_LOG="$ARTIFACTS_DIR/xcodebuild-build.log"
347356

348357
ri_log "Building simulator app with xcodebuild"
349358
COMPILE_START=$(date +%s)
350-
if ! xcodebuild \
351-
-workspace "$WORKSPACE_PATH" \
359+
if ! eval xcodebuild \
360+
$BUILD_ARG \
352361
-scheme "$SCHEME" \
353362
-sdk iphonesimulator \
354363
-configuration Debug \
@@ -363,7 +372,7 @@ COMPILE_END=$(date +%s)
363372
COMPILATION_TIME=$((COMPILE_END - COMPILE_START))
364373
ri_log "Compilation time: ${COMPILATION_TIME}s"
365374

366-
BUILD_SETTINGS="$(xcodebuild -workspace "$WORKSPACE_PATH" -scheme "$SCHEME" -sdk iphonesimulator -configuration Debug -showBuildSettings 2>/dev/null || true)"
375+
BUILD_SETTINGS="$(eval xcodebuild $BUILD_ARG -scheme "$SCHEME" -sdk iphonesimulator -configuration Debug -showBuildSettings 2>/dev/null || true)"
367376
TARGET_BUILD_DIR="$(printf '%s\n' "$BUILD_SETTINGS" | awk -F' = ' '/ TARGET_BUILD_DIR /{print $2; exit}')"
368377
WRAPPER_NAME="$(printf '%s\n' "$BUILD_SETTINGS" | awk -F' = ' '/ WRAPPER_NAME /{print $2; exit}')"
369378
if [ -z "$WRAPPER_NAME" ]; then

0 commit comments

Comments
 (0)