From b37112af2afb78241920ede6c375a3cb1d587feb Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 17 Feb 2016 12:26:00 -0800 Subject: [PATCH] Rewrite Local.xcconfig per build In case the user changes the path of the Flutter project on disk, the Dart SDK or the Flutter repository itself, the old Xcode paths would be invalid. Now, we rewrite them when we build the project. --- packages/flutter_tools/lib/src/ios/device_ios.dart | 6 +++++- .../flutter_tools/lib/src/ios/setup_xcodeproj.dart | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/device_ios.dart b/packages/flutter_tools/lib/src/ios/device_ios.dart index b6a667c98f..83d46955e1 100644 --- a/packages/flutter_tools/lib/src/ios/device_ios.dart +++ b/packages/flutter_tools/lib/src/ios/device_ios.dart @@ -565,12 +565,16 @@ String _getIOSEngineRevision(ApplicationPackage app) { } Future _buildIOSXcodeProject(ApplicationPackage app, { bool buildForDevice }) async { + String flutterProjectPath = Directory.current.path; + if (xcodeProjectRequiresUpdate()) { printTrace('Initializing the Xcode project.'); - if ((await setupXcodeProjectHarness()) != 0) { + if ((await setupXcodeProjectHarness(flutterProjectPath)) != 0) { printError('Could not initialize the Xcode project.'); return false; } + } else { + updateXcodeLocalProperties(flutterProjectPath); } if (!_validateEngineRevision(app)) diff --git a/packages/flutter_tools/lib/src/ios/setup_xcodeproj.dart b/packages/flutter_tools/lib/src/ios/setup_xcodeproj.dart index 704c4e66a4..7c98bbc960 100644 --- a/packages/flutter_tools/lib/src/ios/setup_xcodeproj.dart +++ b/packages/flutter_tools/lib/src/ios/setup_xcodeproj.dart @@ -91,7 +91,7 @@ Future _inflateXcodeArchive(String directory, List archiveBytes) asyn return true; } -void _setupXcodeProjXcconfig(String filePath) { +void updateXcodeLocalProperties(String projectPath) { StringBuffer localsBuffer = new StringBuffer(); localsBuffer.writeln('// This is a generated file; do not edit or check into version control.'); @@ -106,7 +106,7 @@ void _setupXcodeProjXcconfig(String filePath) { String dartSDKPath = path.normalize(path.join(Platform.resolvedExecutable, '..', '..')); localsBuffer.writeln('DART_SDK_PATH=$dartSDKPath'); - File localsFile = new File(filePath); + File localsFile = new File(path.join(projectPath, 'ios', '.generated', 'Local.xcconfig')); localsFile.createSync(recursive: true); localsFile.writeAsStringSync(localsBuffer.toString()); } @@ -130,9 +130,9 @@ bool xcodeProjectRequiresUpdate() { return false; } -Future setupXcodeProjectHarness() async { +Future setupXcodeProjectHarness(String flutterProjectPath) async { // Step 1: Fetch the archive from the cloud - String iosFilesPath = path.join(Directory.current.path, 'ios'); + String iosFilesPath = path.join(flutterProjectPath, 'ios'); String xcodeprojPath = path.join(iosFilesPath, '.generated'); List archiveBytes = await _fetchXcodeArchive(); @@ -149,7 +149,7 @@ Future setupXcodeProjectHarness() async { } // Step 3: Populate the Local.xcconfig with project specific paths - _setupXcodeProjXcconfig(path.join(xcodeprojPath, 'Local.xcconfig')); + updateXcodeLocalProperties(flutterProjectPath); // Step 4: Write the REVISION file File revisionFile = new File(path.join(xcodeprojPath, 'REVISION'));