Replace xcodeenv with new implementation

This commit is contained in:
Sander van der Burg 2018-11-17 21:55:49 +01:00
parent 74750dc67d
commit 907216a57d
5 changed files with 97 additions and 81 deletions

View File

@ -1,14 +1,13 @@
{stdenv, xcodewrapper}: {stdenv, composeXcodeWrapper}:
{ name { name
, src , src
, sdkVersion ? "11.2" , sdkVersion ? "11.3"
, target ? null , target ? null
, configuration ? null , configuration ? null
, scheme ? null , scheme ? null
, sdk ? null , sdk ? null
, xcodeFlags ? "" , xcodeFlags ? ""
, release ? false , release ? false
, codeSignIdentity ? null
, certificateFile ? null , certificateFile ? null
, certificatePassword ? null , certificatePassword ? null
, provisioningProfile ? null , provisioningProfile ? null
@ -18,13 +17,12 @@
, enableWirelessDistribution ? false , enableWirelessDistribution ? false
, installURL ? null , installURL ? null
, bundleId ? null , bundleId ? null
, version ? null , appVersion ? null
, title ? null , ...
, meta ? {} }@args:
}:
assert release -> codeSignIdentity != null && certificateFile != null && certificatePassword != null && provisioningProfile != null && signMethod != null; assert release -> certificateFile != null && certificatePassword != null && provisioningProfile != null && signMethod != null;
assert enableWirelessDistribution -> installURL != null && bundleId != null && version != null && title != null; assert enableWirelessDistribution -> installURL != null && bundleId != null && appVersion != null;
let let
# Set some default values here # Set some default values here
@ -46,11 +44,15 @@ let
security default-keychain -s login.keychain security default-keychain -s login.keychain
security delete-keychain $keychainName security delete-keychain $keychainName
''; '';
xcodewrapperFormalArgs = builtins.functionArgs composeXcodeWrapper;
xcodewrapperArgs = builtins.intersectAttrs xcodewrapperFormalArgs args;
xcodewrapper = composeXcodeWrapper xcodewrapperArgs;
extraArgs = removeAttrs args ([ "name" "scheme" "xcodeFlags" "release" "certificateFile" "certificatePassword" "provisioningProfile" "signMethod" "generateIPA" "generateXCArchive" "enableWirelessDistribution" "installURL" "bundleId" "version" ] ++ builtins.attrNames xcodewrapperFormalArgs);
in in
stdenv.mkDerivation { stdenv.mkDerivation ({
name = stdenv.lib.replaceChars [" "] [""] name; name = stdenv.lib.replaceChars [" "] [""] name; # iOS app names can contain spaces, but in the Nix store this is not allowed
inherit src;
inherit meta;
buildInputs = [ xcodewrapper ]; buildInputs = [ xcodewrapper ];
buildPhase = '' buildPhase = ''
${stdenv.lib.optionalString release '' ${stdenv.lib.optionalString release ''
@ -118,8 +120,9 @@ stdenv.mkDerivation {
echo "file binary-dist \"$(echo $out/*.ipa)\"" > $out/nix-support/hydra-build-products echo "file binary-dist \"$(echo $out/*.ipa)\"" > $out/nix-support/hydra-build-products
${stdenv.lib.optionalString enableWirelessDistribution '' ${stdenv.lib.optionalString enableWirelessDistribution ''
appname=$(basename $out/*.ipa .ipa) # Add another hacky build product that enables wireless adhoc installations
sed -e "s|@INSTALL_URL@|${installURL}?bundleId=${bundleId}\&version=${version}\&title=$appname|" ${./install.html.template} > $out/$appname.html appname="$(basename "$out/*.ipa" .ipa)"
sed -e "s|@INSTALL_URL@|${installURL}?bundleId=${bundleId}\&version=${appVersion}\&title=$appname|" ${./install.html.template} > $out/$appname.html
echo "doc install \"$out/$appname.html\"" >> $out/nix-support/hydra-build-products echo "doc install \"$out/$appname.html\"" >> $out/nix-support/hydra-build-products
''} ''}
''} ''}
@ -136,4 +139,4 @@ stdenv.mkDerivation {
failureHook = stdenv.lib.optionalString release deleteKeychain; failureHook = stdenv.lib.optionalString release deleteKeychain;
installPhase = "true"; installPhase = "true";
} } // extraArgs)

View File

@ -1,4 +1,7 @@
{stdenv, version, xcodeBaseDir}: {stdenv}:
{version ? "9.3", xcodeBaseDir ? "/Applications/Xcode.app"}:
assert stdenv.isDarwin;
stdenv.mkDerivation { stdenv.mkDerivation {
name = "xcode-wrapper-"+version; name = "xcode-wrapper-"+version;
@ -9,6 +12,7 @@ stdenv.mkDerivation {
ln -s /usr/bin/security ln -s /usr/bin/security
ln -s /usr/bin/codesign ln -s /usr/bin/codesign
ln -s /usr/bin/xcrun ln -s /usr/bin/xcrun
ln -s /usr/bin/plutil
ln -s "${xcodeBaseDir}/Contents/Developer/usr/bin/xcodebuild" ln -s "${xcodeBaseDir}/Contents/Developer/usr/bin/xcodebuild"
ln -s "${xcodeBaseDir}/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator" ln -s "${xcodeBaseDir}/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator"

View File

@ -1,15 +1,15 @@
{stdenv, version ? "9.2", xcodeBaseDir ? "/Applications/Xcode.app"}: {stdenv}:
rec { rec {
xcodewrapper = import ./xcodewrapper.nix { composeXcodeWrapper = import ./compose-xcodewrapper.nix {
inherit stdenv version xcodeBaseDir; inherit stdenv;
}; };
buildApp = import ./build-app.nix { buildApp = import ./build-app.nix {
inherit stdenv xcodewrapper; inherit stdenv composeXcodeWrapper;
}; };
simulateApp = import ./simulate-app.nix { simulateApp = import ./simulate-app.nix {
inherit stdenv xcodewrapper; inherit stdenv composeXcodeWrapper;
}; };
} }

View File

@ -1,6 +1,13 @@
{stdenv, xcodewrapper}: {stdenv, composeXcodeWrapper}:
{name, bundleId, app}: {name, app ? null, bundleId ? null, ...}@args:
assert app != null -> bundleId != null;
let
xcodewrapperArgs = builtins.intersectAttrs (builtins.functionArgs composeXcodeWrapper) args;
xcodewrapper = composeXcodeWrapper xcodewrapperArgs;
in
stdenv.mkDerivation { stdenv.mkDerivation {
name = stdenv.lib.replaceChars [" "] [""] name; name = stdenv.lib.replaceChars [" "] [""] name;
buildCommand = '' buildCommand = ''
@ -23,6 +30,7 @@ stdenv.mkDerivation {
# Open the simulator instance # Open the simulator instance
open -a "$(readlink "${xcodewrapper}/bin/Simulator")" --args -CurrentDeviceUDID $udid open -a "$(readlink "${xcodewrapper}/bin/Simulator")" --args -CurrentDeviceUDID $udid
${stdenv.lib.optionalString (app != null) ''
# Copy the app and restore the write permissions # Copy the app and restore the write permissions
appTmpDir=$(mktemp -d -t appTmpDir) appTmpDir=$(mktemp -d -t appTmpDir)
cp -r "$(echo ${app}/*.app)" "$appTmpDir" cp -r "$(echo ${app}/*.app)" "$appTmpDir"
@ -43,5 +51,6 @@ stdenv.mkDerivation {
EOF EOF
chmod +x $out/bin/run-test-simulator chmod +x $out/bin/run-test-simulator
''}
''; '';
} }