Emit additional Xcode settings in flutter create (#8125)

On flutter run, we update ios/Flutter/Generated.xcconfig with various
Flutter-specific settings required by xcode_backend.sh during a build
from Xcode. These settings need to be present at the time the project is
loaded since Xcode doesn't pick up live updates to these files.

Without these settings, Xcode fails to locate xcode_backend.sh itself,
causing the build to fail until the Xcode project has been closed and
re-opened. This also prevents Xcode's project updater from 'helpfully'
suggesting to clean up and delete the Generated.xcconfig file.
diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart
index 4458ff9..fd4c56c 100644
--- a/packages/flutter_tools/lib/src/commands/create.dart
+++ b/packages/flutter_tools/lib/src/commands/create.dart
@@ -8,10 +8,13 @@
 import '../base/common.dart';
 import '../base/file_system.dart';
 import '../base/utils.dart';
+import '../build_info.dart';
 import '../cache.dart';
 import '../dart/pub.dart';
 import '../doctor.dart';
+import '../flx.dart' as flx;
 import '../globals.dart';
+import '../ios/xcodeproj.dart';
 import '../runner/flutter_command.dart';
 import '../template.dart';
 
@@ -98,9 +101,10 @@
       renderDriverTest: argResults['with-driver-test']
     );
     printStatus('Wrote $generatedCount files.');
-
     printStatus('');
 
+    updateXcodeGeneratedProperties(dirPath, BuildMode.debug, flx.defaultMainPath);
+
     if (argResults['pub'])
       await pubGet(directory: dirPath);
 
diff --git a/packages/flutter_tools/lib/src/ios/xcodeproj.dart b/packages/flutter_tools/lib/src/ios/xcodeproj.dart
index 16a0aec..245b335 100644
--- a/packages/flutter_tools/lib/src/ios/xcodeproj.dart
+++ b/packages/flutter_tools/lib/src/ios/xcodeproj.dart
@@ -20,8 +20,7 @@
   localsBuffer.writeln('FLUTTER_ROOT=$flutterRoot');
 
   // This holds because requiresProjectRoot is true for this command
-  String applicationRoot = fs.path.normalize(fs.currentDirectory.path);
-  localsBuffer.writeln('FLUTTER_APPLICATION_PATH=$applicationRoot');
+  localsBuffer.writeln('FLUTTER_APPLICATION_PATH=${fs.path.normalize(projectPath)}');
 
   // Relative to FLUTTER_APPLICATION_PATH, which is [Directory.current].
   localsBuffer.writeln('FLUTTER_TARGET=$target');
diff --git a/packages/flutter_tools/test/create_test.dart b/packages/flutter_tools/test/create_test.dart
index ddff780..6c9ffed 100644
--- a/packages/flutter_tools/test/create_test.dart
+++ b/packages/flutter_tools/test/create_test.dart
@@ -66,6 +66,15 @@
           expect(original, formatted, reason: file.path);
         }
       }
+
+      // Generated Xcode settings
+      String xcodeConfigPath = fs.path.join('ios', 'Flutter', 'Generated.xcconfig');
+      expectExists(xcodeConfigPath);
+      File xcodeConfigFile = fs.file(fs.path.join(temp.path, xcodeConfigPath));
+      String xcodeConfig = xcodeConfigFile.readAsStringSync();
+      expect(xcodeConfig, contains('FLUTTER_ROOT='));
+      expect(xcodeConfig, contains('FLUTTER_APPLICATION_PATH='));
+      expect(xcodeConfig, contains('FLUTTER_FRAMEWORK_DIR='));
     });
 
     // Verify that we can regenerate over an existing project.