2014-01-21 17:19:26 +01:00
|
|
|
{stdenv, androidsdk, titaniumsdk, titanium, xcodewrapper, jdk, python}:
|
|
|
|
{ name, src, target, androidPlatformVersions ? [ "8" ], androidAbiVersions ? [ "armeabi" "armeabi-v7a" ], tiVersion ? null
|
2013-01-07 18:22:10 +01:00
|
|
|
, release ? false, androidKeyStore ? null, androidKeyAlias ? null, androidKeyStorePassword ? null
|
2014-01-21 17:19:26 +01:00
|
|
|
, iosMobileProvisioningProfile ? null, iosCertificateName ? null, iosCertificate ? null, iosCertificatePassword ? null
|
2013-01-07 18:22:10 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert (release && target == "android") -> androidKeyStore != null && androidKeyAlias != null && androidKeyStorePassword != null;
|
2014-01-13 15:22:11 +01:00
|
|
|
assert (release && target == "iphone") -> iosMobileProvisioningProfile != null && iosCertificateName != null && iosCertificate != null && iosCertificatePassword != null;
|
2013-01-07 18:22:10 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
androidsdkComposition = androidsdk {
|
|
|
|
platformVersions = androidPlatformVersions;
|
2013-08-06 10:41:13 +02:00
|
|
|
abiVersions = androidAbiVersions;
|
2013-01-07 18:22:10 +01:00
|
|
|
useGoogleAPIs = true;
|
|
|
|
};
|
2013-01-16 17:09:08 +01:00
|
|
|
|
|
|
|
deleteKeychain = "security delete-keychain $keychainName";
|
2013-01-07 18:22:10 +01:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
2013-01-18 17:34:01 +01:00
|
|
|
name = stdenv.lib.replaceChars [" "] [""] name;
|
|
|
|
inherit src;
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
buildInputs = [ titanium jdk python ] ++ stdenv.lib.optional (stdenv.system == "x86_64-darwin") xcodewrapper;
|
2014-01-15 15:25:50 +01:00
|
|
|
|
2013-01-07 18:22:10 +01:00
|
|
|
buildPhase = ''
|
|
|
|
export HOME=$TMPDIR
|
2014-01-21 17:19:26 +01:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString (tiVersion != null) ''
|
|
|
|
# Replace titanium version by the provided one
|
|
|
|
sed -i -e "s|<sdk-version>[0-9a-zA-Z\.]*</sdk-version>|<sdk-version>${tiVersion}</sdk-version>|" tiapp.xml
|
|
|
|
''}
|
|
|
|
|
|
|
|
# Simulate a login
|
|
|
|
mkdir -p $HOME/.titanium
|
|
|
|
cat > $HOME/.titanium/auth_session.json <<EOF
|
|
|
|
{ "loggedIn": true }
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "{}" > $TMPDIR/config.json
|
|
|
|
titanium --config-file $TMPDIR/config.json config sdk.defaultInstallLocation ${titaniumsdk}
|
2013-01-07 18:22:10 +01:00
|
|
|
|
|
|
|
mkdir -p $out
|
|
|
|
|
|
|
|
${if target == "android" then
|
2014-01-21 17:19:26 +01:00
|
|
|
''
|
|
|
|
titanium config --config-file $TMPDIR/config.json android.sdkPath ${androidsdkComposition}/libexec/android-sdk-*
|
|
|
|
|
|
|
|
${if release then
|
|
|
|
''titanium build --config-file $TMPDIR/config.json --force --platform android --target dist-playstore --keystore ${androidKeyStore} --alias ${androidKeyAlias} --password ${androidKeyStorePassword} --output-dir $out''
|
|
|
|
else
|
|
|
|
''titanium build --config-file $TMPDIR/config.json --force --platform android --target emulator --build-only --output $out''}
|
|
|
|
''
|
2013-01-07 18:22:10 +01:00
|
|
|
else if target == "iphone" then
|
2014-01-21 17:19:26 +01:00
|
|
|
''
|
|
|
|
export NIX_TITANIUM_WORKAROUND="--config-file $TMPDIR/config.json"
|
|
|
|
|
|
|
|
${if release then
|
|
|
|
''
|
|
|
|
export HOME=/Users/$(whoami)
|
|
|
|
export keychainName=$(basename $out)
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Create a keychain with the component hash name (should always be unique)
|
|
|
|
security create-keychain -p "" $keychainName
|
|
|
|
security default-keychain -s $keychainName
|
|
|
|
security unlock-keychain -p "" $keychainName
|
|
|
|
security import ${iosCertificate} -k $keychainName -P "${iosCertificatePassword}" -A
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
provisioningId=$(grep UUID -A1 -a ${iosMobileProvisioningProfile} | grep -o "[-A-Z0-9]\{36\}")
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Ensure that the requested provisioning profile can be found
|
|
|
|
|
|
|
|
if [ ! -f "$HOME/Library/MobileDevice/Provisioning Profiles/$provisioningId.mobileprovision" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$HOME/Library/MobileDevice/Provisioning Profiles"
|
|
|
|
cp ${iosMobileProvisioningProfile} "$HOME/Library/MobileDevice/Provisioning Profiles/$provisioningId.mobileprovision"
|
|
|
|
fi
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Make a copy of the Titanium SDK and fix its permissions. Without it,
|
|
|
|
# builds using the facebook module fail, because it needs to be writable
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
cp -av ${titaniumsdk} $TMPDIR/titaniumsdk
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
find $TMPDIR/titaniumsdk | while read i
|
|
|
|
do
|
|
|
|
chmod 755 "$i"
|
|
|
|
done
|
2014-01-23 15:11:46 +01:00
|
|
|
|
|
|
|
# Simulate a login
|
|
|
|
mkdir -p $HOME/.titanium
|
|
|
|
cat > $HOME/.titanium/auth_session.json <<EOF
|
|
|
|
{ "loggedIn": true }
|
|
|
|
EOF
|
2013-01-16 17:09:08 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Set the SDK to our copy
|
|
|
|
titanium --config-file $TMPDIR/config.json config sdk.defaultInstallLocation $TMPDIR/titaniumsdk
|
2013-01-16 17:09:08 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Do the actual build
|
|
|
|
titanium build --config-file $TMPDIR/config.json --force --platform ios --target dist-adhoc --pp-uuid $provisioningId --distribution-name "${iosCertificateName}" --keychain $HOME/Library/Keychains/$keychainName --device-family universal --output-dir $out
|
2013-01-16 17:09:08 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Remove our generated keychain
|
2013-01-16 17:09:08 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
${deleteKeychain}
|
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
|
|
|
# Copy all sources to the output store directory.
|
|
|
|
# Why? Debug application include *.js files, which are symlinked into their
|
|
|
|
# sources. If they are not copied, we have dangling references to the
|
|
|
|
# temp folder.
|
2013-01-16 17:09:08 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
cp -av * $out
|
|
|
|
cd $out
|
2013-01-07 18:22:10 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
titanium build --config-file $TMPDIR/config.json --force --platform ios --target simulator --build-only --device-family universal --output-dir $out
|
|
|
|
''}
|
|
|
|
''
|
2013-01-07 18:22:10 +01:00
|
|
|
|
|
|
|
else throw "Target: ${target} is not supported!"}
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
|
|
|
|
|
|
|
${if target == "android" && release then ""
|
|
|
|
else
|
|
|
|
if target == "android" then
|
|
|
|
''cp $(ls build/android/bin/*.apk | grep -v '\-unsigned.apk') $out''
|
|
|
|
else if target == "iphone" && release then
|
2013-03-21 14:11:58 +01:00
|
|
|
''
|
|
|
|
cp -av build/iphone/build/* $out
|
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "file binary-dist \"$(echo $out/Release-iphoneos/*.ipa)\"" > $out/nix-support/hydra-build-products
|
|
|
|
''
|
2013-01-07 18:22:10 +01:00
|
|
|
else if target == "iphone" then ""
|
|
|
|
else throw "Target: ${target} is not supported!"}
|
2013-03-05 15:39:51 +01:00
|
|
|
|
|
|
|
${if target == "android" then ''
|
|
|
|
mkdir -p $out/nix-support
|
2013-03-21 14:11:58 +01:00
|
|
|
echo "file binary-dist \"$(ls $out/*.apk)\"" > $out/nix-support/hydra-build-products
|
2013-03-05 15:39:51 +01:00
|
|
|
'' else ""}
|
2013-01-07 18:22:10 +01:00
|
|
|
'';
|
2013-01-16 17:09:08 +01:00
|
|
|
|
|
|
|
failureHook = stdenv.lib.optionalString (release && target == "iphone") deleteKeychain;
|
2013-01-07 18:22:10 +01:00
|
|
|
}
|