@@ -1,22 +1,47 @@
11{stdenv, xcodewrapper}:
2−{ name, appName ? null, app
3−, device ? "iPhone", baseDir ? ""
4−, sdkVersion ? "7.0"
5−}:
2+{name, bundleId, app}:
63
7−let
8− _appName = if appName == null then name else appName;
9−in
104stdenv.mkDerivation {
115 name = stdenv.lib.replaceChars [" "] [""] name;
126 buildCommand = ''
137 mkdir -p $out/bin
148 cat > $out/bin/run-test-simulator << "EOF"
159 #! ${stdenv.shell} -e
16−
17− cd "${app}/${baseDir}/${_appName}.app"
18− "$(readlink "${xcodewrapper}/bin/iPhone Simulator")" -SimulateApplication './${_appName}' -SimulateDevice '${device}' -currentSDKRoot "$(readlink "${xcodewrapper}/SDKs")/iPhoneSimulator${sdkVersion}.sdk"
10+
11+ if [ "$1" = "" ]
12+ then
13+ # Show the user the possibile UDIDs and let him pick one, if none is provided as a command-line parameter
14+ xcrun simctl list
15+
16+ echo "Please provide a UDID of a simulator:"
17+ read udid
18+ else
19+ # If a parameter has been provided, consider that a device UDID an use that
20+ udid="$1"
21+ fi
22+
23+ # Open the simulator instance
24+ open -a "$(readlink "${xcodewrapper}/bin/iOS Simulator")" --args -CurrentDeviceUDID $udid
25+
26+ # Copy the app and restore the write permissions
27+ appTmpDir=$(mktemp -d -t appTmpDir)
28+ cp -r "$(echo ${app}/*.app)" $appTmpDir
29+ chmod -R 755 "$(echo $appTmpDir/*.app)"
30+
31+ # Wait for the simulator to start
32+ echo "Press enter when the simulator is started..."
33+ read
34+
35+ # Install the app
36+ xcrun simctl install $udid "$(echo $appTmpDir/*.app)"
37+
38+ # Remove the app tempdir
39+ rm -Rf $appTmpDir
40+
41+ # Launch the app in the simulator
42+ xcrun simctl launch $udid "${bundleId}"
1943 EOF
44+
2045 chmod +x $out/bin/run-test-simulator
2146 '';
2247}