From 907216a57d1c478486d71f8b085f7019114c6fce Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Sat, 17 Nov 2018 21:55:49 +0100 Subject: Replace xcodeenv with new implementation --- pkgs/development/mobile/xcodeenv/build-app.nix | 101 +++++++++++---------- .../mobile/xcodeenv/compose-xcodewrapper.nix | 29 ++++++ pkgs/development/mobile/xcodeenv/default.nix | 10 +- .../mobile/xcodeenv/install.html.template | 6 +- pkgs/development/mobile/xcodeenv/simulate-app.nix | 61 +++++++------ pkgs/development/mobile/xcodeenv/xcodewrapper.nix | 25 ----- 6 files changed, 124 insertions(+), 108 deletions(-) create mode 100644 pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix delete mode 100644 pkgs/development/mobile/xcodeenv/xcodewrapper.nix (limited to 'pkgs/development/mobile/xcodeenv') diff --git a/pkgs/development/mobile/xcodeenv/build-app.nix b/pkgs/development/mobile/xcodeenv/build-app.nix index d7dd2d1190d8..90fa307fbf23 100644 --- a/pkgs/development/mobile/xcodeenv/build-app.nix +++ b/pkgs/development/mobile/xcodeenv/build-app.nix @@ -1,14 +1,13 @@ -{stdenv, xcodewrapper}: +{stdenv, composeXcodeWrapper}: { name , src -, sdkVersion ? "11.2" +, sdkVersion ? "11.3" , target ? null , configuration ? null , scheme ? null , sdk ? null , xcodeFlags ? "" , release ? false -, codeSignIdentity ? null , certificateFile ? null , certificatePassword ? null , provisioningProfile ? null @@ -18,24 +17,23 @@ , enableWirelessDistribution ? false , installURL ? null , bundleId ? null -, version ? null -, title ? null -, meta ? {} -}: +, appVersion ? null +, ... +}@args: -assert release -> codeSignIdentity != null && certificateFile != null && certificatePassword != null && provisioningProfile != null && signMethod != null; -assert enableWirelessDistribution -> installURL != null && bundleId != null && version != null && title != null; +assert release -> certificateFile != null && certificatePassword != null && provisioningProfile != null && signMethod != null; +assert enableWirelessDistribution -> installURL != null && bundleId != null && appVersion != null; 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; - + _sdk = if sdk == null then if release then "iphoneos" + sdkVersion else "iphonesimulator" + sdkVersion @@ -46,41 +44,45 @@ let security default-keychain -s login.keychain 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 -stdenv.mkDerivation { - name = stdenv.lib.replaceChars [" "] [""] name; - inherit src; - inherit meta; +stdenv.mkDerivation ({ + name = stdenv.lib.replaceChars [" "] [""] name; # iOS app names can contain spaces, but in the Nix store this is not allowed 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 - - # Grant the codesign utility permissions to read from the keychain - security set-key-partition-list -S apple-tool:,apple: -s -k "" $keychainName - - # Determine provisioning ID - PROVISIONING_PROFILE=$(grep UUID -A1 -a ${provisioningProfile} | grep -o "[-A-Za-z0-9]\{36\}") - - 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 - ''} + 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 + + # Grant the codesign utility permissions to read from the keychain + security set-key-partition-list -S apple-tool:,apple: -s -k "" $keychainName + + # Determine provisioning ID + PROVISIONING_PROFILE=$(grep UUID -A1 -a ${provisioningProfile} | grep -o "[-A-Za-z0-9]\{36\}") + + 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 export LD=clang # To avoid problem with -isysroot parameter that is unrecognized by the stock ld. Comparison with an impure build shows that it uses clang instead. Ugly, but it works @@ -116,10 +118,11 @@ stdenv.mkDerivation { # Add IPA to Hydra build products mkdir -p $out/nix-support echo "file binary-dist \"$(echo $out/*.ipa)\"" > $out/nix-support/hydra-build-products - + ${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 + # Add another hacky build product that enables wireless adhoc installations + 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 ''} ''} @@ -127,13 +130,13 @@ stdenv.mkDerivation { mkdir -p $out mv "${name}.xcarchive" $out ''} - + # Delete our temp keychain ${deleteKeychain} ''} ''; - + failureHook = stdenv.lib.optionalString release deleteKeychain; - + installPhase = "true"; -} +} // extraArgs) diff --git a/pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix b/pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix new file mode 100644 index 000000000000..d0093ffac91b --- /dev/null +++ b/pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix @@ -0,0 +1,29 @@ +{stdenv}: +{version ? "9.3", xcodeBaseDir ? "/Applications/Xcode.app"}: + +assert stdenv.isDarwin; + +stdenv.mkDerivation { + name = "xcode-wrapper-"+version; + buildCommand = '' + mkdir -p $out/bin + cd $out/bin + ln -s /usr/bin/xcode-select + ln -s /usr/bin/security + ln -s /usr/bin/codesign + ln -s /usr/bin/xcrun + ln -s /usr/bin/plutil + ln -s "${xcodeBaseDir}/Contents/Developer/usr/bin/xcodebuild" + ln -s "${xcodeBaseDir}/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator" + + cd .. + ln -s "${xcodeBaseDir}/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs" + + # Check if we have the xcodebuild version that we want + if [ -z "$($out/bin/xcodebuild -version | grep -x 'Xcode ${version}')" ] + then + echo "We require xcodebuild version: ${version}" + exit 1 + fi + ''; +} diff --git a/pkgs/development/mobile/xcodeenv/default.nix b/pkgs/development/mobile/xcodeenv/default.nix index b3b9dbdf07ac..47686e6d69e9 100644 --- a/pkgs/development/mobile/xcodeenv/default.nix +++ b/pkgs/development/mobile/xcodeenv/default.nix @@ -1,15 +1,15 @@ -{stdenv, version ? "9.2", xcodeBaseDir ? "/Applications/Xcode.app"}: +{stdenv}: rec { - xcodewrapper = import ./xcodewrapper.nix { - inherit stdenv version xcodeBaseDir; + composeXcodeWrapper = import ./compose-xcodewrapper.nix { + inherit stdenv; }; buildApp = import ./build-app.nix { - inherit stdenv xcodewrapper; + inherit stdenv composeXcodeWrapper; }; simulateApp = import ./simulate-app.nix { - inherit stdenv xcodewrapper; + inherit stdenv composeXcodeWrapper; }; } diff --git a/pkgs/development/mobile/xcodeenv/install.html.template b/pkgs/development/mobile/xcodeenv/install.html.template index 833b1994162c..d48fda7f38b9 100644 --- a/pkgs/development/mobile/xcodeenv/install.html.template +++ b/pkgs/development/mobile/xcodeenv/install.html.template @@ -4,14 +4,14 @@ Install IPA - + Go to the install page or wait a second - +