From 4041a12612797536db0fd732dfde950ea62efe3e Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Thu, 9 May 2019 18:16:15 +0200 Subject: [PATCH] Print a friendlier message when Xcode/iPhone SDK are not installed Signed-off-by: Pedro Pombeiro --- nix/status-go/build-desktop-status-go.nix | 4 +- nix/status-go/build-mobile-status-go.nix | 4 +- nix/status-go/build-status-go.nix | 8 ++-- nix/status-go/default.nix | 7 ++-- nix/status-go/gomobile/default.nix | 8 ++-- nix/utils.nix | 45 +++++++++++++++++++++++ scripts/setup | 2 +- 7 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 nix/utils.nix diff --git a/nix/status-go/build-desktop-status-go.nix b/nix/status-go/build-desktop-status-go.nix index 2e7ec22021..109a45f3d8 100644 --- a/nix/status-go/build-desktop-status-go.nix +++ b/nix/status-go/build-desktop-status-go.nix @@ -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 // { diff --git a/nix/status-go/build-mobile-status-go.nix b/nix/status-go/build-mobile-status-go.nix index 3b7dfa7a50..8735c6fd07 100644 --- a/nix/status-go/build-mobile-status-go.nix +++ b/nix/status-go/build-mobile-status-go.nix @@ -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 // { diff --git a/nix/status-go/build-status-go.nix b/nix/status-go/build-status-go.nix index d11b4fe59a..d2d64d2200 100644 --- a/nix/status-go/build-status-go.nix +++ b/nix/status-go/build-status-go.nix @@ -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 diff --git a/nix/status-go/default.nix b/nix/status-go/default.nix index 7f1dec6c61..65e72af582 100644 --- a/nix/status-go/default.nix +++ b/nix/status-go/default.nix @@ -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 diff --git a/nix/status-go/gomobile/default.nix b/nix/status-go/gomobile/default.nix index b9415f8f0a..a210457e39 100644 --- a/nix/status-go/gomobile/default.nix +++ b/nix/status-go/gomobile/default.nix @@ -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; diff --git a/nix/utils.nix b/nix/utils.nix new file mode 100644 index 0000000000..03108fde0b --- /dev/null +++ b/nix/utils.nix @@ -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; +} \ No newline at end of file diff --git a/scripts/setup b/scripts/setup index 7521ce5864..66125c9c2e 100755 --- a/scripts/setup +++ b/scripts/setup @@ -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