2018-11-17 22:13:44 +00:00
|
|
|
{stdenv, composeAndroidPackages, composeXcodeWrapper, titaniumsdk, titanium, alloy, jdk, python, nodejs, which, file}:
|
|
|
|
{ name, src, preBuild ? "", target, tiVersion ? null
|
2013-01-07 17:22:10 +00:00
|
|
|
, release ? false, androidKeyStore ? null, androidKeyAlias ? null, androidKeyStorePassword ? null
|
2019-02-04 21:50:36 +00:00
|
|
|
, iosMobileProvisioningProfile ? null, iosCertificateName ? null, iosCertificate ? null, iosCertificatePassword ? null, iosVersion ? "12.1", iosBuildStore ? false
|
2018-11-17 22:13:44 +00:00
|
|
|
, enableWirelessDistribution ? false, installURL ? null
|
|
|
|
, xcodeBaseDir ? "/Applications/Xcode.app"
|
|
|
|
, androidsdkArgs ? {}
|
|
|
|
, xcodewrapperArgs ? {}
|
|
|
|
, ...
|
|
|
|
}@args:
|
2013-01-07 17:22:10 +00:00
|
|
|
|
|
|
|
assert (release && target == "android") -> androidKeyStore != null && androidKeyAlias != null && androidKeyStorePassword != null;
|
2014-01-13 14:22:11 +00:00
|
|
|
assert (release && target == "iphone") -> iosMobileProvisioningProfile != null && iosCertificateName != null && iosCertificate != null && iosCertificatePassword != null;
|
2014-08-04 10:26:14 +01:00
|
|
|
assert enableWirelessDistribution -> installURL != null;
|
2013-01-07 17:22:10 +00:00
|
|
|
|
|
|
|
let
|
2018-11-17 22:13:44 +00:00
|
|
|
realAndroidsdkArgs = {
|
2019-02-04 21:50:36 +00:00
|
|
|
platformVersions = [ "28" ];
|
2018-11-17 22:13:44 +00:00
|
|
|
} // androidsdkArgs;
|
|
|
|
|
|
|
|
androidsdk = (composeAndroidPackages realAndroidsdkArgs).androidsdk;
|
|
|
|
|
|
|
|
xcodewrapper = composeXcodeWrapper xcodewrapperArgs;
|
2018-03-20 16:39:45 +00:00
|
|
|
|
2014-10-27 16:30:08 +00:00
|
|
|
deleteKeychain = ''
|
2018-11-17 22:13:44 +00:00
|
|
|
if [ -f $HOME/lock-keychain ]
|
|
|
|
then
|
|
|
|
security default-keychain -s login.keychain
|
|
|
|
security delete-keychain $keychainName
|
|
|
|
rm -f $HOME/lock-keychain
|
|
|
|
fi
|
2014-10-27 16:30:08 +00:00
|
|
|
'';
|
2018-11-17 22:13:44 +00:00
|
|
|
|
|
|
|
extraArgs = removeAttrs args [ "name" "preRebuild" "androidsdkArgs" "xcodewrapperArgs" ];
|
2013-01-07 17:22:10 +00:00
|
|
|
in
|
2018-11-17 22:13:44 +00:00
|
|
|
stdenv.mkDerivation ({
|
2013-01-18 16:34:01 +00:00
|
|
|
name = stdenv.lib.replaceChars [" "] [""] name;
|
2018-03-20 16:22:32 +00:00
|
|
|
|
2019-03-10 22:18:08 +00:00
|
|
|
buildInputs = [ nodejs titanium alloy python which file jdk ];
|
2018-11-17 22:13:44 +00:00
|
|
|
|
2013-01-07 17:22:10 +00:00
|
|
|
buildPhase = ''
|
2018-01-05 11:34:03 +00:00
|
|
|
${preBuild}
|
|
|
|
|
2019-02-04 21:50:36 +00:00
|
|
|
${stdenv.lib.optionalString stdenv.isDarwin ''
|
|
|
|
# Hack that provides a writable alloy package on macOS. Without it the build fails because of a file permission error.
|
|
|
|
alloy=$(dirname $(type -p alloy))/..
|
|
|
|
cp -rv $alloy/* alloy
|
|
|
|
chmod -R u+w alloy
|
|
|
|
export PATH=$(pwd)/alloy/bin:$PATH
|
|
|
|
''}
|
|
|
|
|
2018-11-17 22:13:44 +00:00
|
|
|
export HOME=${if target == "iphone" then "/Users/$(whoami)" else "$TMPDIR"}
|
|
|
|
|
2014-01-21 16:19:26 +00: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
|
|
|
|
''}
|
2018-11-17 22:13:44 +00:00
|
|
|
|
2014-01-21 16:19:26 +00:00
|
|
|
# Simulate a login
|
|
|
|
mkdir -p $HOME/.titanium
|
|
|
|
cat > $HOME/.titanium/auth_session.json <<EOF
|
|
|
|
{ "loggedIn": true }
|
|
|
|
EOF
|
2018-11-17 22:13:44 +00:00
|
|
|
|
|
|
|
# Configure the paths to the Titanium SDK and modules
|
2014-01-21 16:19:26 +00:00
|
|
|
echo "{}" > $TMPDIR/config.json
|
2014-01-23 16:11:16 +00:00
|
|
|
titanium --config-file $TMPDIR/config.json --no-colors config sdk.defaultInstallLocation ${titaniumsdk}
|
2014-02-18 15:34:34 +00:00
|
|
|
titanium --config-file $TMPDIR/config.json --no-colors config paths.modules ${titaniumsdk}
|
2018-11-17 22:13:44 +00:00
|
|
|
|
2013-01-07 17:22:10 +00:00
|
|
|
mkdir -p $out
|
2018-11-17 22:13:44 +00:00
|
|
|
|
|
|
|
${if target == "android" then ''
|
|
|
|
titanium config --config-file $TMPDIR/config.json --no-colors android.sdkPath ${androidsdk}/libexec/android-sdk
|
|
|
|
|
|
|
|
export PATH=${androidsdk}/libexec/android-sdk/tools:$(echo ${androidsdk}/libexec/android-sdk/build-tools/android-*):$PATH
|
|
|
|
export GRADLE_USER_HOME=$TMPDIR/gradle
|
|
|
|
|
|
|
|
${if release then ''
|
|
|
|
${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
|
|
|
|
'' else ''
|
|
|
|
titanium build --config-file $TMPDIR/config.json --no-colors --force --platform android --target emulator --build-only -B foo --output $out
|
|
|
|
''}
|
|
|
|
''
|
|
|
|
else if target == "iphone" then ''
|
2019-03-10 22:18:08 +00:00
|
|
|
# Be sure that the Xcode wrapper has priority over everything else.
|
|
|
|
# When using buildInputs this does not seem to be the case.
|
|
|
|
export PATH=${xcodewrapper}/bin:$PATH
|
|
|
|
|
2018-11-17 22:13:44 +00:00
|
|
|
# Configure the path to Xcode
|
|
|
|
titanium --config-file $TMPDIR/config.json --no-colors config paths.xcode ${xcodeBaseDir}
|
|
|
|
|
|
|
|
# Link the modules folder
|
|
|
|
if [ ! -e modules ]
|
|
|
|
then
|
|
|
|
ln -s ${titaniumsdk}/modules modules
|
|
|
|
createdModulesSymlink=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
${if release then ''
|
|
|
|
# Create a keychain with the component hash name (should always be unique)
|
|
|
|
export keychainName=$(basename $out)
|
|
|
|
|
|
|
|
security create-keychain -p "" $keychainName
|
|
|
|
security default-keychain -s $keychainName
|
|
|
|
security unlock-keychain -p "" $keychainName
|
|
|
|
security import ${iosCertificate} -k $keychainName -P "${iosCertificatePassword}" -A
|
|
|
|
security set-key-partition-list -S apple-tool:,apple: -s -k "" $keychainName
|
|
|
|
provisioningId=$(grep UUID -A1 -a ${iosMobileProvisioningProfile} | grep -o "[-A-Za-z0-9]\{36\}")
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Do the actual build
|
|
|
|
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
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
cp -av * $out
|
|
|
|
cd $out
|
|
|
|
|
|
|
|
# Execute the build
|
|
|
|
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
|
|
|
|
|
|
|
|
# Remove the modules symlink
|
|
|
|
if [ "$createdModulesSymlink" = "1" ]
|
|
|
|
then
|
|
|
|
rm $out/modules
|
|
|
|
fi
|
|
|
|
''}
|
|
|
|
'' else throw "Target: ${target} is not supported!"}
|
2013-01-07 17:22:10 +00:00
|
|
|
'';
|
2018-11-17 22:13:44 +00:00
|
|
|
|
2013-01-07 17:22:10 +00:00
|
|
|
installPhase = ''
|
2013-03-05 14:39:51 +00:00
|
|
|
${if target == "android" then ''
|
2018-11-17 22:13:44 +00:00
|
|
|
${if release then ""
|
|
|
|
else ''
|
|
|
|
cp "$(ls build/android/bin/*.apk | grep -v '\-unsigned.apk')" $out
|
|
|
|
''}
|
|
|
|
|
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "file binary-dist \"$(ls $out/*.apk)\"" > $out/nix-support/hydra-build-products
|
|
|
|
''
|
|
|
|
else if target == "iphone" then
|
|
|
|
if release then ''
|
2013-03-05 14:39:51 +00:00
|
|
|
mkdir -p $out/nix-support
|
2018-11-17 22:13:44 +00:00
|
|
|
echo "file binary-dist \"$(echo $out/*.ipa)\"" > $out/nix-support/hydra-build-products
|
|
|
|
|
|
|
|
${stdenv.lib.optionalString enableWirelessDistribution ''
|
2019-02-23 13:57:49 +00:00
|
|
|
appname="$(basename $out/*.ipa .ipa)"
|
2018-11-17 22:13:44 +00: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')
|
|
|
|
|
|
|
|
sed -e "s|@INSTALL_URL@|${installURL}?bundleId=$bundleId\&version=$version\&title=$appname|" ${../xcodeenv/install.html.template} > "$out/$appname.html"
|
|
|
|
echo "doc install \"$out/$appname.html\"" >> $out/nix-support/hydra-build-products
|
|
|
|
''}
|
|
|
|
''
|
|
|
|
else ""
|
|
|
|
else throw "Target: ${target} is not supported!"}
|
2013-01-07 17:22:10 +00:00
|
|
|
'';
|
2018-11-17 22:13:44 +00:00
|
|
|
|
2013-01-16 16:09:08 +00:00
|
|
|
failureHook = stdenv.lib.optionalString (release && target == "iphone") deleteKeychain;
|
2018-11-17 22:13:44 +00:00
|
|
|
} // extraArgs)
|