From 43650e93f4e3bac849f9ccc35fd1b8f71667da4f Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 14 Feb 2017 09:56:57 -0800 Subject: [PATCH] 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. --- packages/flutter_tools/lib/src/commands/create.dart | 6 +++++- packages/flutter_tools/lib/src/ios/xcodeproj.dart | 3 +-- packages/flutter_tools/test/create_test.dart | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 4458ff98e9..fd4c56c54f 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -8,10 +8,13 @@ import '../android/android.dart' as android; 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 @@ class CreateCommand extends FlutterCommand { 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 16a0aecc15..245b335cdc 100644 --- a/packages/flutter_tools/lib/src/ios/xcodeproj.dart +++ b/packages/flutter_tools/lib/src/ios/xcodeproj.dart @@ -20,8 +20,7 @@ void updateXcodeGeneratedProperties(String projectPath, BuildMode mode, String t 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 ddff7801e2..6c9ffedecc 100644 --- a/packages/flutter_tools/test/create_test.dart +++ b/packages/flutter_tools/test/create_test.dart @@ -66,6 +66,15 @@ void main() { 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.