Skip to content

Commit

Permalink
Merge pull request #4562 from wix/new-xcuitest-build
Browse files Browse the repository at this point in the history
build(ios): new XCUITest runner build.
  • Loading branch information
asafkorem authored Aug 25, 2024
2 parents f6ed49e + bb2cf59 commit 407d55d
Showing 1 changed file with 64 additions and 11 deletions.
75 changes: 64 additions & 11 deletions detox/scripts/build_xcuitest.ios.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,71 @@
#!/bin/bash -e
#!/usr/bin/env bash

XCODEPROJ=$1
XCUITEST_OUTPUT_DIR=$2
CONFIGURATION=Release
PROJECT_NAME=DetoxXCUITestRunner
set -euo pipefail

# Clean up the output directory
CONFIGURATION="Release"
PROJECT_NAME="DetoxXCUITestRunner"

rm -fr "${XCUITEST_OUTPUT_DIR}"
print_usage() {
echo "Usage: $0 <xcodeproj_path> <xcuitest_output_dir>"
exit 1
}

# Make sure the output directory exists
setup_output_dir() {
local output_dir="$1"
rm -rf "${output_dir}"
mkdir -p "${output_dir}"
}

mkdir -p "${XCUITEST_OUTPUT_DIR}"
create_temp_dir() {
local temp_dir
temp_dir=$(mktemp -d)
echo "${temp_dir}"
}

# Build Simulator version
build_for_simulator() {
local xcodeproj="$1"
local temp_dir="$2"

env -i bash -c "xcodebuild -project \"${XCODEPROJ}\" -scheme \"${PROJECT_NAME}\" -UseNewBuildSystem=\"YES\" -configuration \"${CONFIGURATION}\" -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' -derivedDataPath \"${XCUITEST_OUTPUT_DIR}\" build-for-testing -quiet"
env -i xcodebuild \
-project "${xcodeproj}" \
-scheme "${PROJECT_NAME}" \
-UseNewBuildSystem="YES" \
-configuration "${CONFIGURATION}" \
-sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath "${temp_dir}" \
build-for-testing \
-quiet
}

process_xctestrun() {
local temp_dir="$1"
local output_dir="$2"

local xctestrun_file
xctestrun_file=$(find "${temp_dir}" -name "*.xctestrun")

# Copy the parent directory of the .xctestrun file, which contains the .xctestrun file and its associated binaries
cp -r "$(dirname "${xctestrun_file}")" "${output_dir}"
}

main() {
if [ $# -ne 2 ]; then
print_usage
fi

local xcodeproj="$1"
local output_dir="$2"

setup_output_dir "${output_dir}"
local temp_dir
temp_dir=$(create_temp_dir)

# Ensure cleanup happens on script exit
trap "[[ -d ${temp_dir} ]] && rm -rf ${temp_dir}" EXIT

build_for_simulator "${xcodeproj}" "${temp_dir}"
process_xctestrun "${temp_dir}" "${output_dir}"
}

main "$@"

0 comments on commit 407d55d

Please sign in to comment.