xcodeenv: allow versions higher than specified

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 <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2022-12-03 13:29:16 +01:00
parent 65277def0f
commit ae08ff7b71
No known key found for this signature in database
GPG Key ID: FE65CD384D5BF7B4
2 changed files with 18 additions and 15 deletions

View File

@ -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
'';

View File

@ -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; };
}