at master 2.6 kB view raw
1From 6df275df3b8694daf16302b407520e3b1dee6724 Mon Sep 17 00:00:00 2001 2From: Philip Hayes <philiphayes9@gmail.com> 3Date: Thu, 12 Sep 2024 13:23:00 -0700 4Subject: [PATCH] fix: cleanup xcode_backend.sh to fix iOS build w/ 5 `NixOS/nixpkgs` flutter 6 7This patch cleans up `xcode_backend.sh`. It now effectively just runs 8`exec $FLUTTER_ROOT/bin/dart ./xcode_backend.dart`. 9 10The previous `xcode_backend.sh` tries to discover `$FLUTTER_ROOT` from 11argv[0], even though its presence is already guaranteed (the wrapped 12`xcode_backend.dart` also relies on this env). 13 14When using nixpkgs flutter, the flutter SDK directory is composed of several 15layers, joined together using symlinks (called a `symlinkJoin`). Without this 16patch, the auto-discover traverses the symlinks into the wrong layer, and so it 17uses an "unwrapped" `dart` command instead of a "wrapped" dart that sets some 18important envs/flags (like `$FLUTTER_ROOT`). 19 20Using the "unwrapped" dart then manifests in this error when compiling, since 21it doesn't see the ios build-support artifacts: 22 23``` 24$ flutter run -d iphone 25Running Xcode build... 26Xcode build done. 6.4s 27Failed to build iOS app 28Error (Xcode): Target debug_unpack_ios failed: Error: Flutter failed to create a directory at "/<nix-store>/XXXX-flutter-3.24.1-unwrapped/bin/cache/artifacts". 29``` 30--- 31 packages/flutter_tools/bin/xcode_backend.sh | 25 ++++----------------- 32 1 file changed, 4 insertions(+), 21 deletions(-) 33 34diff --git a/packages/flutter_tools/bin/xcode_backend.sh b/packages/flutter_tools/bin/xcode_backend.sh 35index 2889d7c8e4..48b9d06c6e 100755 36--- a/packages/flutter_tools/bin/xcode_backend.sh 37+++ b/packages/flutter_tools/bin/xcode_backend.sh 38@@ -13,24 +13,7 @@ 39 # exit on error, or usage of unset var 40 set -euo pipefail 41 42-# Needed because if it is set, cd may print the path it changed to. 43-unset CDPATH 44- 45-function follow_links() ( 46- cd -P "$(dirname -- "$1")" 47- file="$PWD/$(basename -- "$1")" 48- while [[ -h "$file" ]]; do 49- cd -P "$(dirname -- "$file")" 50- file="$(readlink -- "$file")" 51- cd -P "$(dirname -- "$file")" 52- file="$PWD/$(basename -- "$file")" 53- done 54- echo "$file" 55-) 56- 57-PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")" 58-BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" 59-FLUTTER_ROOT="$BIN_DIR/../../.." 60-DART="$FLUTTER_ROOT/bin/dart" 61- 62-"$DART" "$BIN_DIR/xcode_backend.dart" "$@" "ios" 63+# Run `dart ./xcode_backend.dart` with the dart from $FLUTTER_ROOT. 64+dart="${FLUTTER_ROOT}/bin/dart" 65+xcode_backend_dart="${BASH_SOURCE[0]%.sh}.dart" 66+exec "${dart}" "${xcode_backend_dart}" "$@" "ios" 67-- 682.46.0