2018-01-05 12:34:03 +01:00
|
|
|
{stdenv, androidsdk, titaniumsdk, titanium, alloy, xcodewrapper, jdk, python, nodejs, which, file, xcodeBaseDir}:
|
|
|
|
{ name, src, preBuild ? "", target, androidPlatformVersions ? [ "25" ], androidAbiVersions ? [ "armeabi" "armeabi-v7a" ], tiVersion ? null
|
2013-01-07 18:22:10 +01:00
|
|
|
, release ? false, androidKeyStore ? null, androidKeyAlias ? null, androidKeyStorePassword ? null
|
2018-01-05 12:34:03 +01:00
|
|
|
, iosMobileProvisioningProfile ? null, iosCertificateName ? null, iosCertificate ? null, iosCertificatePassword ? null, iosVersion ? "11.2"
|
2018-01-31 15:33:03 +01:00
|
|
|
, enableWirelessDistribution ? false, iosBuildStore ? false, installURL ? 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;
|
2014-08-04 11:26:14 +02:00
|
|
|
assert enableWirelessDistribution -> installURL != 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;
|
|
|
|
};
|
2018-03-20 17:39:45 +01:00
|
|
|
|
2014-10-27 17:30:08 +01:00
|
|
|
deleteKeychain = ''
|
|
|
|
security default-keychain -s login.keychain
|
|
|
|
security delete-keychain $keychainName
|
2018-01-09 13:24:30 +01:00
|
|
|
rm -f $HOME/lock-keychain
|
2014-10-27 17:30:08 +01:00
|
|
|
'';
|
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;
|
2018-03-20 17:22:32 +01:00
|
|
|
|
2018-01-05 12:34:03 +01:00
|
|
|
buildInputs = [ nodejs titanium alloy jdk python which file ] ++ 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 = ''
|
2018-01-05 12:34:03 +01:00
|
|
|
${preBuild}
|
|
|
|
|
2013-01-07 18:22:10 +01:00
|
|
|
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
|
2014-01-23 17:11:16 +01:00
|
|
|
titanium --config-file $TMPDIR/config.json --no-colors config sdk.defaultInstallLocation ${titaniumsdk}
|
2014-02-18 16:34:34 +01:00
|
|
|
titanium --config-file $TMPDIR/config.json --no-colors config paths.modules ${titaniumsdk}
|
|
|
|
|
2013-01-07 18:22:10 +01:00
|
|
|
mkdir -p $out
|
|
|
|
|
|
|
|
${if target == "android" then
|
2014-01-21 17:19:26 +01:00
|
|
|
''
|
2018-01-05 12:34:03 +01:00
|
|
|
titanium config --config-file $TMPDIR/config.json --no-colors android.sdkPath ${androidsdkComposition}/libexec
|
|
|
|
|
2016-09-01 15:25:46 +02:00
|
|
|
export PATH=$(echo ${androidsdkComposition}/libexec/tools):$(echo ${androidsdkComposition}/libexec/build-tools/android-*):$PATH
|
2018-03-20 17:22:32 +01:00
|
|
|
export GRADLE_USER_HOME=$TMPDIR/gradle
|
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
${if release then
|
2018-03-21 14:57:57 +01:00
|
|
|
''
|
|
|
|
${stdenv.lib.optionalString stdenv.isDarwin ''
|
|
|
|
# Signing the app does not work with OpenJDK on macOS, use host SDK instead
|
|
|
|
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
|
|
|
|
''}
|
|
|
|
titanium build --config-file $TMPDIR/config.json --no-colors --force --platform android --target dist-playstore --keystore ${androidKeyStore} --alias ${androidKeyAlias} --store-password ${androidKeyStorePassword} --output-dir $out
|
|
|
|
''
|
2014-01-21 17:19:26 +01:00
|
|
|
else
|
2014-07-15 16:05:25 +02:00
|
|
|
''titanium build --config-file $TMPDIR/config.json --no-colors --force --platform android --target emulator --build-only -B foo --output $out''}
|
2014-01-21 17:19:26 +01:00
|
|
|
''
|
2013-01-07 18:22:10 +01:00
|
|
|
else if target == "iphone" then
|
2014-01-21 17:19:26 +01:00
|
|
|
''
|
|
|
|
${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
|
2017-01-27 10:50:36 +01:00
|
|
|
security set-key-partition-list -S apple-tool:,apple: -s -k "" $keychainName
|
2014-07-18 16:40:15 +02:00
|
|
|
provisioningId=$(grep UUID -A1 -a ${iosMobileProvisioningProfile} | grep -o "[-A-Za-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-23 15:11:46 +01:00
|
|
|
# Simulate a login
|
|
|
|
mkdir -p $HOME/.titanium
|
|
|
|
cat > $HOME/.titanium/auth_session.json <<EOF
|
|
|
|
{ "loggedIn": true }
|
|
|
|
EOF
|
2014-10-14 14:57:11 +02:00
|
|
|
|
|
|
|
# Configure the path to Xcode
|
|
|
|
titanium --config-file $TMPDIR/config.json --no-colors config paths.xcode ${xcodeBaseDir}
|
|
|
|
|
2016-01-07 14:47:26 +01:00
|
|
|
# Make plutil available
|
|
|
|
mkdir -p $TMPDIR/bin
|
|
|
|
ln -s /usr/bin/plutil $TMPDIR/bin
|
|
|
|
export PATH=$TMPDIR/bin:$PATH
|
|
|
|
|
|
|
|
# Link the modules folder
|
|
|
|
if [ ! -e modules ]
|
|
|
|
then
|
|
|
|
ln -s ${titaniumsdk}/modules modules
|
|
|
|
fi
|
2018-01-09 13:24:30 +01:00
|
|
|
|
|
|
|
# Take precautions to prevent concurrent builds blocking the keychain
|
|
|
|
while [ -f $HOME/lock-keychain ]
|
|
|
|
do
|
|
|
|
echo "Keychain locked, waiting for a couple of seconds, or remove $HOME/lock-keychain to unblock..."
|
|
|
|
sleep 3
|
|
|
|
done
|
|
|
|
|
|
|
|
touch $HOME/lock-keychain
|
|
|
|
|
|
|
|
security default-keychain -s $keychainName
|
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Do the actual build
|
2018-01-31 15:33:03 +01:00
|
|
|
titanium build --config-file $TMPDIR/config.json --force --no-colors --platform ios --target ${if iosBuildStore then "dist-appstore" else "dist-adhoc"} --pp-uuid $provisioningId --distribution-name "${iosCertificateName}" --keychain $HOME/Library/Keychains/$keychainName-db --device-family universal --ios-version ${iosVersion} --output-dir $out
|
2013-01-16 17:09:08 +01:00
|
|
|
|
2014-01-21 17:19:26 +01:00
|
|
|
# Remove our generated keychain
|
|
|
|
${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
|
2016-01-07 14:47:26 +01:00
|
|
|
|
|
|
|
# We need to consult a real home directory to find the available simulators
|
|
|
|
export HOME=/Users/$(whoami)
|
|
|
|
|
2014-10-14 14:57:11 +02:00
|
|
|
# Configure the path to Xcode
|
|
|
|
titanium --config-file $TMPDIR/config.json --no-colors config paths.xcode ${xcodeBaseDir}
|
|
|
|
|
2016-01-07 14:47:26 +01:00
|
|
|
# Link the modules folder
|
|
|
|
if [ ! -e modules ]
|
|
|
|
then
|
|
|
|
ln -s ${titaniumsdk}/modules modules
|
|
|
|
createdModulesSymlink=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Execute the build
|
2014-10-14 18:59:31 +02:00
|
|
|
titanium build --config-file $TMPDIR/config.json --force --no-colors --platform ios --target simulator --build-only --device-family universal --ios-version ${iosVersion} --output-dir $out
|
2016-01-07 14:47:26 +01:00
|
|
|
|
|
|
|
# Remove the modules symlink
|
|
|
|
if [ "$createdModulesSymlink" = "1" ]
|
|
|
|
then
|
|
|
|
rm $out/modules
|
|
|
|
fi
|
2014-01-21 17:19:26 +01:00
|
|
|
''}
|
|
|
|
''
|
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
|
2014-02-21 16:20:27 +01:00
|
|
|
''cp "$(ls build/android/bin/*.apk | grep -v '\-unsigned.apk')" $out''
|
2013-01-07 18:22:10 +01:00
|
|
|
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
|
2018-01-09 12:30:34 +01:00
|
|
|
echo "file binary-dist \"$(echo $out/*.ipa)\"" > $out/nix-support/hydra-build-products
|
2014-08-04 11:26:14 +02:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString enableWirelessDistribution ''
|
2018-01-09 12:30:34 +01:00
|
|
|
appname=$(basename $out/*.ipa .ipa)
|
2014-08-04 11:26:14 +02:00
|
|
|
bundleId=$(grep '<id>[a-zA-Z0-9.]*</id>' tiapp.xml | sed -e 's|<id>||' -e 's|</id>||' -e 's/ //g')
|
|
|
|
version=$(grep '<version>[a-zA-Z0-9.]*</version>' tiapp.xml | sed -e 's|<version>||' -e 's|</version>||' -e 's/ //g')
|
|
|
|
|
2016-02-02 14:42:15 +01:00
|
|
|
sed -e "s|@INSTALL_URL@|${installURL}?bundleId=$bundleId\&version=$version\&title=$appname|" ${../xcodeenv/install.html.template} > "$out/$appname.html"
|
2014-08-04 11:26:14 +02:00
|
|
|
echo "doc install \"$out/$appname.html\"" >> $out/nix-support/hydra-build-products
|
|
|
|
''}
|
2013-03-21 14:11:58 +01:00
|
|
|
''
|
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
|
|
|
}
|