forked from firka/flutter
Pull iOS build templates from flutter tools vs engine artifacts (#4526)
This commit is contained in:
@@ -64,3 +64,26 @@ void ensureDirectoryExists(String filePath) {
|
||||
return;
|
||||
syncFs.directory(dirPath).create(recursive: true);
|
||||
}
|
||||
|
||||
/// Recursively copies a folder from `srcPath` to `destPath`
|
||||
void copyFolderSync(String srcPath, String destPath) {
|
||||
dart_io.Directory srcDir = new dart_io.Directory(srcPath);
|
||||
if (!srcDir.existsSync())
|
||||
throw new Exception('Source directory "${srcDir.path}" does not exist, nothing to copy');
|
||||
|
||||
dart_io.Directory destDir = new dart_io.Directory(destPath);
|
||||
if (!destDir.existsSync())
|
||||
destDir.createSync(recursive: true);
|
||||
|
||||
srcDir.listSync().forEach((dart_io.FileSystemEntity entity) {
|
||||
String newPath = path.join(destDir.path, path.basename(entity.path));
|
||||
if (entity is dart_io.File) {
|
||||
dart_io.File newFile = new dart_io.File(newPath);
|
||||
newFile.writeAsBytesSync(entity.readAsBytesSync());
|
||||
} else if (entity is dart_io.Directory) {
|
||||
copyFolderSync(entity.path, newPath);
|
||||
} else {
|
||||
throw new Exception('${entity.path} is neither File nor Directory');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import '../application_package.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/process.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../flx.dart' as flx;
|
||||
import '../globals.dart';
|
||||
import '../services.dart';
|
||||
@@ -114,12 +113,9 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
return new XcodeBuildResult(false);
|
||||
}
|
||||
} else {
|
||||
updateXcodeGeneratedProperties(flutterProjectPath, mode, target);
|
||||
updateXcodeGeneratedProperties(flutterProjectPath, mode, target);
|
||||
}
|
||||
|
||||
if (!_validateEngineRevision(app))
|
||||
return new XcodeBuildResult(false);
|
||||
|
||||
if (!_checkXcodeVersion())
|
||||
return new XcodeBuildResult(false);
|
||||
|
||||
@@ -200,31 +196,6 @@ bool _checkXcodeVersion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _validateEngineRevision(ApplicationPackage app) {
|
||||
String skyRevision = Cache.engineRevision;
|
||||
String iosRevision = _getIOSEngineRevision(app);
|
||||
|
||||
if (iosRevision != skyRevision) {
|
||||
printError("Error: incompatible sky_engine revision.");
|
||||
printStatus('sky_engine revision: $skyRevision, iOS engine revision: $iosRevision');
|
||||
return false;
|
||||
} else {
|
||||
printTrace('sky_engine revision: $skyRevision, iOS engine revision: $iosRevision');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String _getIOSEngineRevision(ApplicationPackage app) {
|
||||
File revisionFile = new File(path.join(app.rootPath, 'REVISION'));
|
||||
if (revisionFile.existsSync()) {
|
||||
// The format is 'REVISION-mode'. We only need the revision.
|
||||
String revisionStamp = revisionFile.readAsStringSync().trim();
|
||||
return revisionStamp.split('-')[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _addServicesToBundle(Directory bundle) async {
|
||||
List<Map<String, String>> services = <Map<String, String>>[];
|
||||
printTrace("Trying to resolve native pub services.");
|
||||
|
||||
@@ -7,52 +7,11 @@ import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import '../base/process.dart';
|
||||
import '../base/file_system.dart' show copyFolderSync;
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../globals.dart';
|
||||
|
||||
bool _inflateXcodeArchive(String directory, List<int> archiveBytes) {
|
||||
printStatus('Unzipping Xcode project to local directory...');
|
||||
|
||||
// We cannot use ArchiveFile because this archive contains files that are exectuable
|
||||
// and there is currently no provision to modify file permissions during
|
||||
// or after creation. See https://github.com/dart-lang/sdk/issues/15078.
|
||||
// So we depend on the platform to unzip the archive for us.
|
||||
|
||||
Directory tempDir = Directory.systemTemp.createTempSync('flutter_xcode');
|
||||
File tempFile = new File(path.join(tempDir.path, 'FlutterXcode.zip'))..createSync();
|
||||
tempFile.writeAsBytesSync(archiveBytes);
|
||||
|
||||
try {
|
||||
Directory dir = new Directory(directory);
|
||||
|
||||
// Remove the old generated project if one is present
|
||||
if (dir.existsSync())
|
||||
dir.deleteSync(recursive: true);
|
||||
|
||||
// Create the directory so unzip can write to it
|
||||
dir.createSync(recursive: true);
|
||||
|
||||
// Unzip the Xcode project into the new empty directory
|
||||
runCheckedSync(<String>['/usr/bin/unzip', tempFile.path, '-d', dir.path]);
|
||||
} catch (error) {
|
||||
printTrace('$error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cleanup the temp directory after unzipping
|
||||
tempDir.deleteSync(recursive: true);
|
||||
|
||||
// Verify that we have an Xcode project
|
||||
Directory flutterProj = new Directory(path.join(directory, 'FlutterApplication.xcodeproj'));
|
||||
if (!flutterProj.existsSync()) {
|
||||
printError("${flutterProj.path} does not exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
import '../version.dart';
|
||||
|
||||
void updateXcodeGeneratedProperties(String projectPath, BuildMode mode, String target) {
|
||||
StringBuffer localsBuffer = new StringBuffer();
|
||||
@@ -93,7 +52,7 @@ bool xcodeProjectRequiresUpdate(BuildMode mode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (revisionFile.readAsStringSync() != '${Cache.engineRevision}-${getModeName(mode)}') {
|
||||
if (revisionFile.readAsStringSync() != _getCurrentXcodeRevisionString(mode)) {
|
||||
printTrace("The revision stamp and the Flutter engine revision differ or the build mode has changed.");
|
||||
printTrace("Project needs to be updated.");
|
||||
return true;
|
||||
@@ -104,36 +63,27 @@ bool xcodeProjectRequiresUpdate(BuildMode mode) {
|
||||
}
|
||||
|
||||
Future<int> setupXcodeProjectHarness(String flutterProjectPath, BuildMode mode, String target) async {
|
||||
// Step 1: Fetch the archive from the cloud
|
||||
// Step 1: Copy templates into user project directory
|
||||
String iosFilesPath = path.join(flutterProjectPath, 'ios');
|
||||
String xcodeprojPath = path.join(iosFilesPath, '.generated');
|
||||
String xcodeProjectPath = path.join(iosFilesPath, '.generated');
|
||||
String templatesPath = path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'build-ios');
|
||||
copyFolderSync(templatesPath, xcodeProjectPath);
|
||||
|
||||
Directory toolDir = tools.getEngineArtifactsDirectory(TargetPlatform.ios, mode);
|
||||
File archiveFile = new File(path.join(toolDir.path, 'FlutterXcode.zip'));
|
||||
List<int> archiveBytes = archiveFile.readAsBytesSync();
|
||||
|
||||
if (archiveBytes.isEmpty) {
|
||||
printError('Error: No archive bytes received.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Step 2: Inflate the archive into the user project directory
|
||||
bool result = _inflateXcodeArchive(xcodeprojPath, archiveBytes);
|
||||
if (!result) {
|
||||
printError('Could not inflate the Xcode project archive.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Step 3: Populate the Generated.xcconfig with project specific paths
|
||||
// Step 2: Populate the Generated.xcconfig with project specific paths
|
||||
updateXcodeGeneratedProperties(flutterProjectPath, mode, target);
|
||||
|
||||
// Step 4: Write the REVISION file
|
||||
File revisionFile = new File(path.join(xcodeprojPath, 'REVISION'));
|
||||
// Step 3: Write the REVISION file
|
||||
File revisionFile = new File(path.join(xcodeProjectPath, 'REVISION'));
|
||||
revisionFile.createSync();
|
||||
revisionFile.writeAsStringSync('${Cache.engineRevision}-${getModeName(mode)}');
|
||||
revisionFile.writeAsStringSync(_getCurrentXcodeRevisionString(mode));
|
||||
|
||||
// Step 5: Tell the user the location of the generated project.
|
||||
// Step 4: Tell the user the location of the generated project.
|
||||
printStatus('Xcode project created in $iosFilesPath/.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
String _getCurrentXcodeRevisionString(BuildMode mode) => (new StringBuffer()
|
||||
..write('${FlutterVersion.getVersion().frameworkRevision}')
|
||||
..write('-${tools.isLocalEngine ? tools.engineBuildPath : getModeName(mode)}')
|
||||
).toString();
|
||||
|
||||
Reference in New Issue
Block a user