1Fix for macOS build issue in Flutter >= 3.35
2
3Since version 3.35, the behavior of macos_assemble.sh and xcode_backend.sh
4is almost identical. This caused the same error for macOS that previously
5occurred for iOS.
6
7Derived from the iOS patch: ./fix-ios-build-xcode-backend-sh.patch
8
9Example error:
10```
11$ flutter run -d macos
12Launching lib/main.dart on macOS in debug mode...
13Target debug_unpack_macos failed: Error: Flutter failed to create a directory at "/<nix-store>/XXXX-flutter-3.35.1-unwrapped/bin/cache/artifacts".
14Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
15Failed to copy Flutter framework.
16** BUILD FAILED **
17```
18
19---
20
21diff --git a/packages/flutter_tools/bin/macos_assemble.sh b/packages/flutter_tools/bin/macos_assemble.sh
22index 28acf8842..d0f2923df 100644
23--- a/packages/flutter_tools/bin/macos_assemble.sh
24+++ b/packages/flutter_tools/bin/macos_assemble.sh
25@@ -13,29 +13,13 @@
26 # exit on error, or usage of unset var
27 set -euo pipefail
28
29-# Needed because if it is set, cd may print the path it changed to.
30-unset CDPATH
31-
32-function follow_links() (
33- cd -P "$(dirname -- "$1")"
34- file="$PWD/$(basename -- "$1")"
35- while [[ -h "$file" ]]; do
36- cd -P "$(dirname -- "$file")"
37- file="$(readlink -- "$file")"
38- cd -P "$(dirname -- "$file")"
39- file="$PWD/$(basename -- "$file")"
40- done
41- echo "$file"
42-)
43-
44-PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
45-BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
46-FLUTTER_ROOT="$BIN_DIR/../../.."
47-DART="$FLUTTER_ROOT/bin/dart"
48+# Run `dart ./xcode_backend.dart` with the dart from $FLUTTER_ROOT.
49+dart="${FLUTTER_ROOT}/bin/dart"
50+xcode_backend_dart="$(dirname "${BASH_SOURCE[0]}")/xcode_backend.dart"
51
52 # Main entry point.
53 if [[ $# == 0 ]]; then
54- "$DART" "$BIN_DIR/xcode_backend.dart" "build" "macos"
55+ exec "${dart}" "${xcode_backend_dart}" "build" "macos"
56 else
57- "$DART" "$BIN_DIR/xcode_backend.dart" "$@" "macos"
58+ exec "${dart}" "${xcode_backend_dart}" "$@" "macos"
59 fi