Print a friendlier message when Xcode/iPhone SDK are not installed

Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
Pedro Pombeiro 2019-05-09 18:16:15 +02:00
parent a09ff50583
commit 4041a12612
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
7 changed files with 60 additions and 18 deletions

View File

@ -1,5 +1,5 @@
{ buildGoPackage, go, xcodeWrapper, pkgs, stdenv }:
{ buildGoPackage, go, xcodeWrapper, pkgs, stdenv, utils }:
{ owner, repo, rev, version, goPackagePath, src, host,
@ -11,7 +11,7 @@
with stdenv;
let
buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper; };
buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper utils; };
args = removeAttrs args' [ "goBuildFlags" "goBuildLdFlags" "outputFileName" "hostSystem" ]; # Remove desktop-only arguments from args
buildStatusGoDesktopLib = buildStatusGo (args // {

View File

@ -1,5 +1,5 @@
{ buildGoPackage, go, gomobile, openjdk, xcodeWrapper, pkgs, stdenv }:
{ buildGoPackage, go, gomobile, openjdk, xcodeWrapper, pkgs, stdenv, utils }:
{ owner, repo, rev, version, goPackagePath, src, host,
@ -11,7 +11,7 @@ with stdenv;
let
targetConfig = config;
buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper; };
buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper utils; };
args = removeAttrs args' [ "config" "goBuildFlags" "goBuildLdFlags" ]; # Remove mobile-only arguments from args
buildStatusGoMobileLib = buildStatusGo (args // {

View File

@ -1,4 +1,4 @@
{ buildGoPackage, go, xcodeWrapper, stdenv }:
{ buildGoPackage, go, xcodeWrapper, stdenv, utils }:
{ owner, repo, rev, version, goPackagePath, src, host,
nativeBuildInputs ? [],
@ -40,10 +40,8 @@ let
"var EnabledStr = \"true\""
'';
# we print out the version so that we fail fast in case there's any problem running xcrun, instead of failing at the end of the build
preConfigure = lib.optionalString isDarwin ''
xcrun xcodebuild -version
'';
# Ensure XCode is present, instead of failing at the end of the build
preConfigure = lib.optionalString isDarwin utils.enforceXCodeAvailable;
buildPhase = ''
runHook preBuild

View File

@ -4,9 +4,10 @@ with stdenv;
let
platform = pkgs.callPackage ../platform.nix { inherit target-os; };
gomobile = pkgs.callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit composeXcodeWrapper xcodewrapperArgs; };
buildStatusGoDesktopLib = pkgs.callPackage ./build-desktop-status-go.nix { inherit buildGoPackage go pkgs xcodeWrapper; };
buildStatusGoMobileLib = pkgs.callPackage ./build-mobile-status-go.nix { inherit buildGoPackage go gomobile pkgs xcodeWrapper; };
utils = pkgs.callPackage ../utils.nix { inherit xcodeWrapper; };
gomobile = pkgs.callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit composeXcodeWrapper xcodewrapperArgs utils; };
buildStatusGoDesktopLib = pkgs.callPackage ./build-desktop-status-go.nix { inherit buildGoPackage go pkgs xcodeWrapper utils; };
buildStatusGoMobileLib = pkgs.callPackage ./build-mobile-status-go.nix { inherit buildGoPackage go gomobile pkgs xcodeWrapper utils; };
extractStatusGoConfig = f: lib.last (lib.splitString "\n" (lib.fileContents f));
owner = lib.fileContents ../../STATUS_GO_OWNER;
version = extractStatusGoConfig ../../STATUS_GO_VERSION; # TODO: Simplify this path search with lib.locateDominatingFile

View File

@ -1,4 +1,4 @@
{ stdenv, pkgs, buildGoPackage, fetchgit,
{ stdenv, pkgs, utils, buildGoPackage, fetchgit,
glibc, ncurses5, zlib, makeWrapper, patchelf,
platform-tools, composeXcodeWrapper, xcodewrapperArgs ? {}
}:
@ -20,10 +20,8 @@ in buildGoPackage rec {
buildInputs = [ makeWrapper ]
++ lib.optional isDarwin xcodeWrapper;
# we print out the version so that we fail fast in case there's any problem running xcrun, instead of failing at the end of the build
preConfigure = lib.optionalString isDarwin ''
PATH=${lib.makeBinPath [ xcodeWrapper ]}:$PATH xcrun xcodebuild -version
'';
# Ensure XCode and the iPhone SDK are present, instead of failing at the end of the build
preConfigure = lib.optionalString isDarwin utils.enforceiPhoneSDKAvailable;
patches = [ ./ndk-search-path.patch ./resolve-nix-android-sdk.patch ]
++ lib.optional isDarwin ./ignore-nullability-error-on-ios.patch;

45
nix/utils.nix Normal file
View File

@ -0,0 +1,45 @@
{ xcodeWrapper }:
let
RED = "\\033[0;31m";
GREEN="\\033[0;32m";
NC = "\\033[0m";
_xcodeToolsTest = ''
xcode=0
iPhoneSDK=0
export PATH=${xcodeWrapper}/bin:$PATH
[[ "$(xcrun xcodebuild -version)" == "Xcode ${_xcodeVersion}"* ]] && xcode=1
[ $xcode -eq 1 ] && xcrun --sdk iphoneos --show-sdk-version > /dev/null && iPhoneSDK=1
'';
_xcodeToolReportScript = tool-name: ''[ $SELECTED -eq 0 ] && echo -e "${NC}- ${RED}[ ] ${tool-name}" || echo -e "${NC}- ${GREEN}[] ${tool-name}${RED}"'';
_xcodeToolsReportScript = ''
echo -e "${RED}There are some required tools missing in the system:"
export SELECTED=$xcode; ${_xcodeToolReportScript "Xcode ${_xcodeVersion}"}
export SELECTED=$iPhoneSDK; ${_xcodeToolReportScript "iPhone SDK"}
'';
_xcodeVersion = builtins.replaceStrings ["xcode-wrapper-"] [""] xcodeWrapper.name;
enforceXCodeAvailable = ''
${_xcodeToolsTest}
if [ $xcode -eq 0 ]; then
${_xcodeToolsReportScript}
echo -e "Please install Xcode ${_xcodeVersion} from the App Store.${NC}"
exit 1
fi
'';
enforceiPhoneSDKAvailable = ''
${_xcodeToolsTest}
if [ $iPhoneSDK -eq 0 ]; then
${_xcodeToolsReportScript}
if [ $xcode -eq 1 ]; then
echo -e "Please install the iPhone SDK in Xcode.${NC}""
else
echo -e "Please install Xcode ${_xcodeVersion} from the App Store, and then the iPhone SDK.${NC}""
fi
exit 1
fi
'';
in {
inherit enforceXCodeAvailable
enforceiPhoneSDKAvailable;
}

View File

@ -23,7 +23,7 @@ setup_header "Checking prerequisites..."
_need_curl=0
! is_nixos && ! program_exists nix && _need_curl=1
if _need_curl && ! program_exists "curl"; then
if [ $_need_curl -eq 1 ] && ! program_exists "curl"; then
cecho "@b@yellow[[Please install curl before running setup.]]"
exit 1
fi