2021-01-17 17:28:51 +00:00
|
|
|
{stdenv, lib, composeXcodeWrapper}:
|
2018-11-17 20:55:49 +00:00
|
|
|
{name, app ? null, bundleId ? null, ...}@args:
|
2013-01-07 15:52:42 +00:00
|
|
|
|
2018-11-17 20:55:49 +00:00
|
|
|
assert app != null -> bundleId != null;
|
|
|
|
|
|
|
|
let
|
|
|
|
xcodewrapperArgs = builtins.intersectAttrs (builtins.functionArgs composeXcodeWrapper) args;
|
|
|
|
|
|
|
|
xcodewrapper = composeXcodeWrapper xcodewrapperArgs;
|
|
|
|
in
|
2013-01-07 15:52:42 +00:00
|
|
|
stdenv.mkDerivation {
|
2021-01-17 17:28:51 +00:00
|
|
|
name = lib.replaceChars [" "] [""] name;
|
2013-01-07 15:52:42 +00:00
|
|
|
buildCommand = ''
|
2014-06-30 12:56:10 +00:00
|
|
|
mkdir -p $out/bin
|
2013-01-07 15:52:42 +00:00
|
|
|
cat > $out/bin/run-test-simulator << "EOF"
|
|
|
|
#! ${stdenv.shell} -e
|
2018-11-17 20:55:49 +00:00
|
|
|
|
2014-10-15 15:10:35 +00:00
|
|
|
if [ "$1" = "" ]
|
|
|
|
then
|
|
|
|
# Show the user the possibile UDIDs and let him pick one, if none is provided as a command-line parameter
|
|
|
|
xcrun simctl list
|
2018-11-17 20:55:49 +00:00
|
|
|
|
2014-10-15 15:10:35 +00:00
|
|
|
echo "Please provide a UDID of a simulator:"
|
|
|
|
read udid
|
|
|
|
else
|
2018-05-06 21:34:05 +00:00
|
|
|
# If a parameter has been provided, consider that a device UDID and use that
|
2014-10-15 15:10:35 +00:00
|
|
|
udid="$1"
|
|
|
|
fi
|
2018-11-17 20:55:49 +00:00
|
|
|
|
2014-10-15 15:10:35 +00:00
|
|
|
# Open the simulator instance
|
2016-01-07 14:43:17 +00:00
|
|
|
open -a "$(readlink "${xcodewrapper}/bin/Simulator")" --args -CurrentDeviceUDID $udid
|
2018-11-17 20:55:49 +00:00
|
|
|
|
2021-01-17 17:28:51 +00:00
|
|
|
${lib.optionalString (app != null) ''
|
2018-11-17 20:55:49 +00:00
|
|
|
# Copy the app and restore the write permissions
|
|
|
|
appTmpDir=$(mktemp -d -t appTmpDir)
|
|
|
|
cp -r "$(echo ${app}/*.app)" "$appTmpDir"
|
|
|
|
chmod -R 755 "$(echo $appTmpDir/*.app)"
|
|
|
|
|
|
|
|
# Wait for the simulator to start
|
|
|
|
echo "Press enter when the simulator is started..."
|
|
|
|
read
|
|
|
|
|
|
|
|
# Install the app
|
|
|
|
xcrun simctl install "$udid" "$(echo $appTmpDir/*.app)"
|
|
|
|
|
|
|
|
# Remove the app tempdir
|
|
|
|
rm -Rf $appTmpDir
|
|
|
|
|
|
|
|
# Launch the app in the simulator
|
|
|
|
xcrun simctl launch $udid "${bundleId}"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod +x $out/bin/run-test-simulator
|
|
|
|
''}
|
2013-01-07 15:52:42 +00:00
|
|
|
'';
|
|
|
|
}
|