2013-01-07 15:52:42 +00:00
|
|
|
{stdenv, xcodewrapper}:
|
|
|
|
{ name
|
|
|
|
, src
|
2013-03-13 12:02:19 +00:00
|
|
|
, sdkVersion ? "6.1"
|
2013-01-07 15:52:42 +00:00
|
|
|
, target ? null
|
|
|
|
, configuration ? null
|
|
|
|
, scheme ? null
|
|
|
|
, sdk ? null
|
|
|
|
, arch ? null
|
|
|
|
, xcodeFlags ? ""
|
|
|
|
, release ? false
|
|
|
|
, codeSignIdentity ? null
|
|
|
|
, certificateFile ? null
|
|
|
|
, certificatePassword ? null
|
|
|
|
, provisioningProfile ? null
|
|
|
|
, generateIPA ? false
|
|
|
|
, generateXCArchive ? false
|
2014-08-01 17:34:18 +01:00
|
|
|
, enableWirelessDistribution ? false
|
|
|
|
, installURL ? null
|
|
|
|
, bundleId ? null
|
|
|
|
, version ? null
|
|
|
|
, title ? null
|
2013-01-07 15:52:42 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert release -> codeSignIdentity != null && certificateFile != null && certificatePassword != null && provisioningProfile != null;
|
2014-08-01 17:34:18 +01:00
|
|
|
assert enableWirelessDistribution -> installURL != null && bundleId != null && version != null && title != null;
|
2013-01-07 15:52:42 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
# Set some default values here
|
|
|
|
|
|
|
|
_target = if target == null then name else target;
|
|
|
|
|
|
|
|
_configuration = if configuration == null
|
|
|
|
then
|
|
|
|
if release then "Release" else "Debug"
|
|
|
|
else configuration;
|
|
|
|
|
|
|
|
_arch = if arch == null
|
|
|
|
then
|
|
|
|
if release then "armv7" else "i386"
|
|
|
|
else arch;
|
|
|
|
|
|
|
|
_sdk = if sdk == null
|
|
|
|
then
|
2013-03-13 12:02:19 +00:00
|
|
|
if release then "iphoneos" + sdkVersion else "iphonesimulator" + sdkVersion
|
2013-01-07 15:52:42 +00:00
|
|
|
else sdk;
|
|
|
|
|
|
|
|
# The following is to prevent repetition
|
|
|
|
deleteKeychain = "security delete-keychain $keychainName";
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
2013-03-21 13:11:58 +00:00
|
|
|
name = stdenv.lib.replaceChars [" "] [""] name;
|
|
|
|
inherit src;
|
2013-01-07 15:52:42 +00:00
|
|
|
buildInputs = [ xcodewrapper ];
|
|
|
|
buildPhase = ''
|
|
|
|
${stdenv.lib.optionalString release ''
|
|
|
|
export HOME=/Users/$(whoami)
|
|
|
|
keychainName="$(basename $out)"
|
|
|
|
|
|
|
|
# Create a keychain
|
|
|
|
security create-keychain -p "" $keychainName
|
|
|
|
security default-keychain -s $keychainName
|
|
|
|
security unlock-keychain -p "" $keychainName
|
|
|
|
|
|
|
|
# Import the certificate into the keychain
|
|
|
|
security import ${certificateFile} -k $keychainName -P "${certificatePassword}" -A
|
|
|
|
|
|
|
|
# Determine provisioning ID
|
2014-07-18 15:40:15 +01:00
|
|
|
PROVISIONING_PROFILE=$(grep UUID -A1 -a ${provisioningProfile} | grep -o "[-A-Za-z0-9]\{36\}")
|
2013-01-07 15:52:42 +00:00
|
|
|
|
|
|
|
if [ ! -f "$HOME/Library/MobileDevice/Provisioning Profiles/$PROVISIONING_PROFILE.mobileprovision" ]
|
|
|
|
then
|
|
|
|
# Copy provisioning profile into the home directory
|
|
|
|
mkdir -p "$HOME/Library/MobileDevice/Provisioning Profiles"
|
|
|
|
cp ${provisioningProfile} "$HOME/Library/MobileDevice/Provisioning Profiles/$PROVISIONING_PROFILE.mobileprovision"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check whether the identity can be found
|
|
|
|
security find-identity -p codesigning $keychainName
|
|
|
|
''}
|
|
|
|
|
|
|
|
# Do the building
|
2013-07-15 10:32:12 +01:00
|
|
|
xcodebuild -target ${_target} -configuration ${_configuration} ${stdenv.lib.optionalString (scheme != null) "-scheme ${scheme}"} -sdk ${_sdk} -arch ${_arch} ONLY_ACTIVE_ARCH=NO CONFIGURATION_TEMP_DIR=$TMPDIR CONFIGURATION_BUILD_DIR=$out ${if generateXCArchive then "archive" else ""} ${xcodeFlags} ${if release then ''"CODE_SIGN_IDENTITY=${codeSignIdentity}" PROVISIONING_PROFILE=$PROVISIONING_PROFILE OTHER_CODE_SIGN_FLAGS="--keychain $HOME/Library/Keychains/$keychainName"'' else ""}
|
2013-01-07 15:52:42 +00:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString release ''
|
|
|
|
${stdenv.lib.optionalString generateIPA ''
|
|
|
|
# Produce an IPA file
|
2013-03-21 13:11:58 +00:00
|
|
|
xcrun -sdk iphoneos PackageApplication -v $out/*.app -o "$out/${name}.ipa"
|
2013-03-15 15:18:45 +00:00
|
|
|
|
|
|
|
# Add IPA to Hydra build products
|
|
|
|
mkdir -p $out/nix-support
|
2013-03-21 13:11:58 +00:00
|
|
|
echo "file binary-dist \"$(echo $out/*.ipa)\"" > $out/nix-support/hydra-build-products
|
2014-08-01 17:34:18 +01:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString enableWirelessDistribution ''
|
|
|
|
appname=$(basename $out/*.ipa .ipa)
|
|
|
|
sed -e "s|@INSTALL_URL@|${installURL}?bundleId=${bundleId}\&version=${version}\&title=$appname|" ${./install.html.template} > $out/$appname.html
|
|
|
|
echo "doc install $out/$appname.html" >> $out/nix-support/hydra-build-products
|
|
|
|
''}
|
2013-01-07 15:52:42 +00:00
|
|
|
''}
|
|
|
|
|
|
|
|
# Delete our temp keychain
|
|
|
|
${deleteKeychain}
|
|
|
|
''}
|
|
|
|
'';
|
|
|
|
|
|
|
|
failureHook = stdenv.lib.optionalString release deleteKeychain;
|
|
|
|
|
|
|
|
installPhase = "true";
|
|
|
|
}
|