From ae08ff7b7172d3d99c95fb94b79489c39b3db78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Sat, 3 Dec 2022 13:29:16 +0100 Subject: [PATCH] xcodeenv: allow versions higher than specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `allowHigher` option to let higher versions of Xcode. This is useful when xcodeenv is used for `nix-shell` for developers and their xcode version might be a bit newer than required one. Signed-off-by: Jakub SokoĊ‚owski --- .../mobile/xcodeenv/compose-xcodewrapper.nix | 19 ++++++++++++++----- pkgs/development/mobile/xcodeenv/default.nix | 14 ++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix b/pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix index 0a469da418a1..fa9e89337615 100644 --- a/pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix +++ b/pkgs/development/mobile/xcodeenv/compose-xcodewrapper.nix @@ -1,10 +1,13 @@ -{stdenv}: -{version ? "11.1", xcodeBaseDir ? "/Applications/Xcode.app"}: +{ stdenv, lib }: +{ version ? "11.1" +, allowHigher ? false +, xcodeBaseDir ? "/Applications/Xcode.app" }: assert stdenv.isDarwin; stdenv.mkDerivation { - name = "xcode-wrapper-"+version; + pname = "xcode-wrapper${lib.optionalString allowHigher "-plus"}"; + inherit version; buildCommand = '' mkdir -p $out/bin cd $out/bin @@ -24,9 +27,15 @@ stdenv.mkDerivation { 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}')" ] + currVer=$($out/bin/xcodebuild -version | head -n1) + ${if allowHigher then '' + if [ -z "$(printf '%s\n' "${version}" "$currVer" | sort -V | head -n1)""" != "${version}" ] + '' else '' + if [ -z "$(echo $currVer | grep -x 'Xcode ${version}')" ] + ''} then - echo "We require xcodebuild version: ${version}" + echo "We require xcodebuild version${if allowHigher then " or higher" else ""}: ${version}" + echo "Instead what was found: $currVer" exit 1 fi ''; diff --git a/pkgs/development/mobile/xcodeenv/default.nix b/pkgs/development/mobile/xcodeenv/default.nix index 90642ca7d9ac..f63ed63c0479 100644 --- a/pkgs/development/mobile/xcodeenv/default.nix +++ b/pkgs/development/mobile/xcodeenv/default.nix @@ -1,15 +1,9 @@ -{ stdenv, lib }: +{ callPackage }: rec { - composeXcodeWrapper = import ./compose-xcodewrapper.nix { - inherit stdenv; - }; + composeXcodeWrapper = callPackage ./compose-xcodewrapper.nix { }; - buildApp = import ./build-app.nix { - inherit stdenv lib composeXcodeWrapper; - }; + buildApp = callPackage ./build-app.nix { inherit composeXcodeWrapper; }; - simulateApp = import ./simulate-app.nix { - inherit stdenv lib composeXcodeWrapper; - }; + simulateApp = callPackage ./simulate-app.nix { inherit composeXcodeWrapper; }; }