@@ -38,6 +38,32 @@ AssertExists() {
3838 return 0
3939}
4040
41+ ParseFlutterBuildMode () {
42+ # Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
43+ # This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
44+ # they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
45+ local build_mode=" $( echo " ${FLUTTER_BUILD_MODE:- ${CONFIGURATION} } " | tr " [:upper:]" " [:lower:]" ) "
46+
47+ case " $build_mode " in
48+ * release* ) build_mode=" release" ;;
49+ * profile* ) build_mode=" profile" ;;
50+ * debug* ) build_mode=" debug" ;;
51+ * )
52+ EchoError " ========================================================================"
53+ EchoError " ERROR: Unknown FLUTTER_BUILD_MODE: ${build_mode} ."
54+ EchoError " Valid values are 'Debug', 'Profile', or 'Release' (case insensitive)."
55+ EchoError " This is controlled by the FLUTTER_BUILD_MODE environment variable."
56+ EchoError " If that is not set, the CONFIGURATION environment variable is used."
57+ EchoError " "
58+ EchoError " You can fix this by either adding an appropriately named build"
59+ EchoError " configuration, or adding an appropriate value for FLUTTER_BUILD_MODE to the"
60+ EchoError " .xcconfig file for the current build configuration (${CONFIGURATION} )."
61+ EchoError " ========================================================================"
62+ exit -1;;
63+ esac
64+ echo " ${build_mode} "
65+ }
66+
4167BuildApp () {
4268 local project_path=" ${SOURCE_ROOT} /.."
4369 if [[ -n " $FLUTTER_APPLICATION_PATH " ]]; then
@@ -72,24 +98,12 @@ BuildApp() {
7298 # Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
7399 # This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
74100 # they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
75- local build_mode=" $( echo " ${FLUTTER_BUILD_MODE :- ${CONFIGURATION} } " | tr " [:upper:] " " [:lower:] " ) "
101+ local build_mode=" $( ParseFlutterBuildMode ) "
76102 local artifact_variant=" unknown"
77103 case " $build_mode " in
78- * release* ) build_mode=" release" ; artifact_variant=" ios-release" ;;
79- * profile* ) build_mode=" profile" ; artifact_variant=" ios-profile" ;;
80- * debug* ) build_mode=" debug" ; artifact_variant=" ios" ;;
81- * )
82- EchoError " ========================================================================"
83- EchoError " ERROR: Unknown FLUTTER_BUILD_MODE: ${build_mode} ."
84- EchoError " Valid values are 'Debug', 'Profile', or 'Release' (case insensitive)."
85- EchoError " This is controlled by the FLUTTER_BUILD_MODE environment variable."
86- EchoError " If that is not set, the CONFIGURATION environment variable is used."
87- EchoError " "
88- EchoError " You can fix this by either adding an appropriately named build"
89- EchoError " configuration, or adding an appropriate value for FLUTTER_BUILD_MODE to the"
90- EchoError " .xcconfig file for the current build configuration (${CONFIGURATION} )."
91- EchoError " ========================================================================"
92- exit -1;;
104+ release ) artifact_variant=" ios-release" ;;
105+ profile ) artifact_variant=" ios-profile" ;;
106+ debug ) artifact_variant=" ios" ;;
93107 esac
94108
95109 # Warn the user if not archiving (ACTION=install) in release mode.
@@ -127,7 +141,7 @@ is set to release or run \"flutter build ios --release\", then re-run Archive fr
127141 fi
128142
129143 local bitcode_flag=" "
130- if [[ $ENABLE_BITCODE == " YES" ]]; then
144+ if [[ " $ENABLE_BITCODE " == " YES" ]]; then
131145 bitcode_flag=" true"
132146 fi
133147
@@ -306,6 +320,36 @@ EmbedFlutterFrameworks() {
306320 RunCommand codesign --force --verbose --sign " ${EXPANDED_CODE_SIGN_IDENTITY} " -- " ${xcode_frameworks_dir} /App.framework/App"
307321 RunCommand codesign --force --verbose --sign " ${EXPANDED_CODE_SIGN_IDENTITY} " -- " ${xcode_frameworks_dir} /Flutter.framework/Flutter"
308322 fi
323+
324+ AddObservatoryBonjourService
325+ }
326+
327+ # Add the observatory publisher Bonjour service to the produced app bundle Info.plist.
328+ AddObservatoryBonjourService () {
329+ local build_mode=" $( ParseFlutterBuildMode) "
330+ # Debug and profile only.
331+ if [[ " ${build_mode} " == " release" ]]; then
332+ return
333+ fi
334+ local built_products_plist=" ${BUILT_PRODUCTS_DIR} /${INFOPLIST_PATH} "
335+
336+ if [[ ! -f " ${built_products_plist} " ]]; then
337+ EchoError " error: ${INFOPLIST_PATH} does not exist. The Flutter \" Thin Binary\" build phase must run after \" Copy Bundle Resources\" ."
338+ exit -1
339+ fi
340+ # If there are already NSBonjourServices specified by the app (uncommon), insert the observatory service name to the existing list.
341+ if plutil -extract NSBonjourServices xml1 -o - " ${built_products_plist} " ; then
342+ RunCommand plutil -insert NSBonjourServices.0 -string " _dartobservatory._tcp" " ${built_products_plist} "
343+ else
344+ # Otherwise, add the NSBonjourServices key and observatory service name.
345+ RunCommand plutil -insert NSBonjourServices -json " [\" _dartobservatory._tcp\" ]" " ${built_products_plist} "
346+ fi
347+
348+ # Don't override the local network description the Flutter app developer specified (uncommon).
349+ # This text will appear below the "Your app would like to find and connect to devices on your local network" permissions popup.
350+ if ! plutil -extract NSLocalNetworkUsageDescription xml1 -o - " ${built_products_plist} " ; then
351+ RunCommand plutil -insert NSLocalNetworkUsageDescription -string " Allow Flutter tools on your computer to connect and debug your application. This prompt will not appear on release builds." " ${built_products_plist} "
352+ fi
309353}
310354
311355EmbedAndThinFrameworks () {
328372 EmbedFlutterFrameworks ;;
329373 " embed_and_thin" )
330374 EmbedAndThinFrameworks ;;
375+ " test_observatory_bonjour_service" )
376+ # Exposed for integration testing only.
377+ AddObservatoryBonjourService ;;
331378 esac
332379fi
0 commit comments