Unverified Commit b82cf76f authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Return void from project migrate() (#112897)

parent 69fc4fb6
...@@ -16,8 +16,7 @@ abstract class ProjectMigrator { ...@@ -16,8 +16,7 @@ abstract class ProjectMigrator {
@protected @protected
final Logger logger; final Logger logger;
/// Returns whether migration was successful or was skipped. void migrate();
bool migrate();
/// Return null if the line should be deleted. /// Return null if the line should be deleted.
@protected @protected
...@@ -80,15 +79,9 @@ class ProjectMigration { ...@@ -80,15 +79,9 @@ class ProjectMigration {
final List<ProjectMigrator> migrators; final List<ProjectMigrator> migrators;
bool run() { void run() {
for (final ProjectMigrator migrator in migrators) { for (final ProjectMigrator migrator in migrators) {
if (!migrator.migrate()) { migrator.migrate();
// Migration failures should be more robust, with transactions and fallbacks.
// See https://github.com/flutter/flutter/issues/12573 and
// https://github.com/flutter/flutter/issues/40460
return false;
}
} }
return true;
} }
} }
...@@ -133,9 +133,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -133,9 +133,7 @@ Future<XcodeBuildResult> buildXcodeProject({
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
if (!migration.run()) { migration.run();
return XcodeBuildResult(success: false);
}
if (!_checkXcodeVersion()) { if (!_checkXcodeVersion()) {
return XcodeBuildResult(success: false); return XcodeBuildResult(success: false);
......
...@@ -19,14 +19,13 @@ class HostAppInfoPlistMigration extends ProjectMigrator { ...@@ -19,14 +19,13 @@ class HostAppInfoPlistMigration extends ProjectMigrator {
final File _infoPlist; final File _infoPlist;
@override @override
bool migrate() { void migrate() {
if (!_infoPlist.existsSync()) { if (!_infoPlist.existsSync()) {
logger.printTrace('Info.plist not found, skipping host app Info.plist migration.'); logger.printTrace('Info.plist not found, skipping host app Info.plist migration.');
return true; return;
} }
processFileLines(_infoPlist); processFileLines(_infoPlist);
return true;
} }
@override @override
......
...@@ -20,7 +20,7 @@ class IOSDeploymentTargetMigration extends ProjectMigrator { ...@@ -20,7 +20,7 @@ class IOSDeploymentTargetMigration extends ProjectMigrator {
final File _appFrameworkInfoPlist; final File _appFrameworkInfoPlist;
@override @override
bool migrate() { void migrate() {
if (_xcodeProjectInfoFile.existsSync()) { if (_xcodeProjectInfoFile.existsSync()) {
processFileLines(_xcodeProjectInfoFile); processFileLines(_xcodeProjectInfoFile);
} else { } else {
...@@ -38,8 +38,6 @@ class IOSDeploymentTargetMigration extends ProjectMigrator { ...@@ -38,8 +38,6 @@ class IOSDeploymentTargetMigration extends ProjectMigrator {
} else { } else {
logger.printTrace('Podfile not found, skipping global platform iOS version migration.'); logger.printTrace('Podfile not found, skipping global platform iOS version migration.');
} }
return true;
} }
@override @override
......
...@@ -16,10 +16,10 @@ class ProjectBaseConfigurationMigration extends ProjectMigrator { ...@@ -16,10 +16,10 @@ class ProjectBaseConfigurationMigration extends ProjectMigrator {
final File _xcodeProjectInfoFile; final File _xcodeProjectInfoFile;
@override @override
bool migrate() { void migrate() {
if (!_xcodeProjectInfoFile.existsSync()) { if (!_xcodeProjectInfoFile.existsSync()) {
logger.printTrace('Xcode project not found, skipping Runner project build settings and configuration migration'); logger.printTrace('Xcode project not found, skipping Runner project build settings and configuration migration');
return true; return;
} }
final String originalProjectContents = _xcodeProjectInfoFile.readAsStringSync(); final String originalProjectContents = _xcodeProjectInfoFile.readAsStringSync();
...@@ -84,6 +84,5 @@ class ProjectBaseConfigurationMigration extends ProjectMigrator { ...@@ -84,6 +84,5 @@ class ProjectBaseConfigurationMigration extends ProjectMigrator {
logger.printStatus('Project base configurations detected, removing.'); logger.printStatus('Project base configurations detected, removing.');
_xcodeProjectInfoFile.writeAsStringSync(newProjectContents); _xcodeProjectInfoFile.writeAsStringSync(newProjectContents);
} }
return true;
} }
} }
...@@ -16,14 +16,13 @@ class ProjectBuildLocationMigration extends ProjectMigrator { ...@@ -16,14 +16,13 @@ class ProjectBuildLocationMigration extends ProjectMigrator {
final File _xcodeProjectWorkspaceData; final File _xcodeProjectWorkspaceData;
@override @override
bool migrate() { void migrate() {
if (!_xcodeProjectWorkspaceData.existsSync()) { if (!_xcodeProjectWorkspaceData.existsSync()) {
logger.printTrace('Xcode project workspace data not found, skipping build location migration.'); logger.printTrace('Xcode project workspace data not found, skipping build location migration.');
return true; return;
} }
processFileLines(_xcodeProjectWorkspaceData); processFileLines(_xcodeProjectWorkspaceData);
return true;
} }
@override @override
......
...@@ -23,15 +23,13 @@ class RemoveFrameworkLinkAndEmbeddingMigration extends ProjectMigrator { ...@@ -23,15 +23,13 @@ class RemoveFrameworkLinkAndEmbeddingMigration extends ProjectMigrator {
final Usage _usage; final Usage _usage;
@override @override
bool migrate() { void migrate() {
if (!_xcodeProjectInfoFile.existsSync()) { if (!_xcodeProjectInfoFile.existsSync()) {
logger.printTrace('Xcode project not found, skipping framework link and embedding migration'); logger.printTrace('Xcode project not found, skipping framework link and embedding migration');
return true; return;
} }
processFileLines(_xcodeProjectInfoFile); processFileLines(_xcodeProjectInfoFile);
return true;
} }
@override @override
......
...@@ -18,10 +18,10 @@ class XcodeBuildSystemMigration extends ProjectMigrator { ...@@ -18,10 +18,10 @@ class XcodeBuildSystemMigration extends ProjectMigrator {
final File _xcodeWorkspaceSharedSettings; final File _xcodeWorkspaceSharedSettings;
@override @override
bool migrate() { void migrate() {
if (!_xcodeWorkspaceSharedSettings.existsSync()) { if (!_xcodeWorkspaceSharedSettings.existsSync()) {
logger.printTrace('Xcode workspace settings not found, skipping build system migration'); logger.printTrace('Xcode workspace settings not found, skipping build system migration');
return true; return;
} }
final String contents = _xcodeWorkspaceSharedSettings.readAsStringSync(); final String contents = _xcodeWorkspaceSharedSettings.readAsStringSync();
...@@ -36,7 +36,5 @@ class XcodeBuildSystemMigration extends ProjectMigrator { ...@@ -36,7 +36,5 @@ class XcodeBuildSystemMigration extends ProjectMigrator {
logger.printStatus('Legacy build system detected, removing ${_xcodeWorkspaceSharedSettings.path}'); logger.printStatus('Legacy build system detected, removing ${_xcodeWorkspaceSharedSettings.path}');
_xcodeWorkspaceSharedSettings.deleteSync(); _xcodeWorkspaceSharedSettings.deleteSync();
} }
return true;
} }
} }
...@@ -47,9 +47,7 @@ Future<void> buildLinux( ...@@ -47,9 +47,7 @@ Future<void> buildLinux(
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
if (!migration.run()) { migration.run();
throwToolExit('Unable to migrate project files');
}
// Build the environment that needs to be set for the re-entrant flutter build // Build the environment that needs to be set for the re-entrant flutter build
// step. // step.
......
...@@ -54,9 +54,7 @@ Future<void> buildMacOS({ ...@@ -54,9 +54,7 @@ Future<void> buildMacOS({
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
if (!migration.run()) { migration.run();
throwToolExit('Could not migrate project file');
}
final Directory flutterBuildDir = globals.fs.directory(getMacOSBuildDirectory()); final Directory flutterBuildDir = globals.fs.directory(getMacOSBuildDirectory());
if (!flutterBuildDir.existsSync()) { if (!flutterBuildDir.existsSync()) {
......
...@@ -18,7 +18,7 @@ class MacOSDeploymentTargetMigration extends ProjectMigrator { ...@@ -18,7 +18,7 @@ class MacOSDeploymentTargetMigration extends ProjectMigrator {
final File _podfile; final File _podfile;
@override @override
bool migrate() { void migrate() {
if (_xcodeProjectInfoFile.existsSync()) { if (_xcodeProjectInfoFile.existsSync()) {
processFileLines(_xcodeProjectInfoFile); processFileLines(_xcodeProjectInfoFile);
} else { } else {
...@@ -30,8 +30,6 @@ class MacOSDeploymentTargetMigration extends ProjectMigrator { ...@@ -30,8 +30,6 @@ class MacOSDeploymentTargetMigration extends ProjectMigrator {
} else { } else {
logger.printTrace('Podfile not found, skipping global platform macOS version migration.'); logger.printTrace('Podfile not found, skipping global platform macOS version migration.');
} }
return true;
} }
@override @override
......
...@@ -21,16 +21,14 @@ class RemoveMacOSFrameworkLinkAndEmbeddingMigration extends ProjectMigrator { ...@@ -21,16 +21,14 @@ class RemoveMacOSFrameworkLinkAndEmbeddingMigration extends ProjectMigrator {
final Usage _usage; final Usage _usage;
@override @override
bool migrate() { void migrate() {
if (!_xcodeProjectInfoFile.existsSync()) { if (!_xcodeProjectInfoFile.existsSync()) {
logger.printTrace( logger.printTrace(
'Xcode project not found, skipping framework link and embedding migration'); 'Xcode project not found, skipping framework link and embedding migration');
return true; return;
} }
processFileLines(_xcodeProjectInfoFile); processFileLines(_xcodeProjectInfoFile);
return true;
} }
@override @override
......
...@@ -16,10 +16,10 @@ class CmakeCustomCommandMigration extends ProjectMigrator { ...@@ -16,10 +16,10 @@ class CmakeCustomCommandMigration extends ProjectMigrator {
final File _cmakeFile; final File _cmakeFile;
@override @override
bool migrate() { void migrate() {
if (!_cmakeFile.existsSync()) { if (!_cmakeFile.existsSync()) {
logger.printTrace('CMake project not found, skipping add_custom_command() VERBATIM migration'); logger.printTrace('CMake project not found, skipping add_custom_command() VERBATIM migration');
return true; return;
} }
final String originalProjectContents = _cmakeFile.readAsStringSync(); final String originalProjectContents = _cmakeFile.readAsStringSync();
...@@ -68,6 +68,5 @@ class CmakeCustomCommandMigration extends ProjectMigrator { ...@@ -68,6 +68,5 @@ class CmakeCustomCommandMigration extends ProjectMigrator {
logger.printStatus('add_custom_command() missing VERBATIM or FLUTTER_TARGET_PLATFORM, updating.'); logger.printStatus('add_custom_command() missing VERBATIM or FLUTTER_TARGET_PLATFORM, updating.');
_cmakeFile.writeAsStringSync(newProjectContents); _cmakeFile.writeAsStringSync(newProjectContents);
} }
return true;
} }
} }
...@@ -18,7 +18,7 @@ class XcodeProjectObjectVersionMigration extends ProjectMigrator { ...@@ -18,7 +18,7 @@ class XcodeProjectObjectVersionMigration extends ProjectMigrator {
final File _xcodeProjectSchemeFile; final File _xcodeProjectSchemeFile;
@override @override
bool migrate() { void migrate() {
if (_xcodeProjectInfoFile.existsSync()) { if (_xcodeProjectInfoFile.existsSync()) {
processFileLines(_xcodeProjectInfoFile); processFileLines(_xcodeProjectInfoFile);
} else { } else {
...@@ -29,8 +29,6 @@ class XcodeProjectObjectVersionMigration extends ProjectMigrator { ...@@ -29,8 +29,6 @@ class XcodeProjectObjectVersionMigration extends ProjectMigrator {
} else { } else {
logger.printTrace('Runner scheme not found, skipping Xcode compatibility migration.'); logger.printTrace('Runner scheme not found, skipping Xcode compatibility migration.');
} }
return true;
} }
@override @override
......
...@@ -15,10 +15,10 @@ class XcodeScriptBuildPhaseMigration extends ProjectMigrator { ...@@ -15,10 +15,10 @@ class XcodeScriptBuildPhaseMigration extends ProjectMigrator {
final File _xcodeProjectInfoFile; final File _xcodeProjectInfoFile;
@override @override
bool migrate() { void migrate() {
if (!_xcodeProjectInfoFile.existsSync()) { if (!_xcodeProjectInfoFile.existsSync()) {
logger.printTrace('Xcode project not found, skipping script build phase dependency analysis removal.'); logger.printTrace('Xcode project not found, skipping script build phase dependency analysis removal.');
return true; return;
} }
final String originalProjectContents = _xcodeProjectInfoFile.readAsStringSync(); final String originalProjectContents = _xcodeProjectInfoFile.readAsStringSync();
...@@ -56,6 +56,5 @@ class XcodeScriptBuildPhaseMigration extends ProjectMigrator { ...@@ -56,6 +56,5 @@ class XcodeScriptBuildPhaseMigration extends ProjectMigrator {
logger.printStatus('Removing script build phase dependency analysis.'); logger.printStatus('Removing script build phase dependency analysis.');
_xcodeProjectInfoFile.writeAsStringSync(newProjectContents); _xcodeProjectInfoFile.writeAsStringSync(newProjectContents);
} }
return true;
} }
} }
...@@ -40,9 +40,7 @@ Future<void> buildWeb( ...@@ -40,9 +40,7 @@ Future<void> buildWeb(
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
if (!migration.run()) { migration.run();
throwToolExit('Failed to run all web migrations.');
}
final Status status = globals.logger.startProgress('Compiling $target for the Web...'); final Status status = globals.logger.startProgress('Compiling $target for the Web...');
final Stopwatch sw = Stopwatch()..start(); final Stopwatch sw = Stopwatch()..start();
......
...@@ -18,17 +18,16 @@ class ScrubGeneratedPluginRegistrant extends ProjectMigrator { ...@@ -18,17 +18,16 @@ class ScrubGeneratedPluginRegistrant extends ProjectMigrator {
final Logger _logger; final Logger _logger;
@override @override
bool migrate() { void migrate() {
final File registrant = _project.libDirectory.childFile('generated_plugin_registrant.dart'); final File registrant = _project.libDirectory.childFile('generated_plugin_registrant.dart');
final File gitignore = _project.parent.directory.childFile('.gitignore'); final File gitignore = _project.parent.directory.childFile('.gitignore');
if (!removeFile(registrant)) { if (!removeFile(registrant)) {
return false; return;
} }
if (gitignore.existsSync()) { if (gitignore.existsSync()) {
processFileLines(gitignore); processFileLines(gitignore);
} }
return true;
} }
// Cleans up the .gitignore by removing the line that mentions generated_plugin_registrant. // Cleans up the .gitignore by removing the line that mentions generated_plugin_registrant.
......
...@@ -54,9 +54,7 @@ Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, { ...@@ -54,9 +54,7 @@ Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
if (!migration.run()) { migration.run();
throwToolExit('Unable to migrate project files');
}
// Ensure that necessary ephemeral files are generated and up to date. // Ensure that necessary ephemeral files are generated and up to date.
_writeGeneratedFlutterConfig(windowsProject, buildInfo, target); _writeGeneratedFlutterConfig(windowsProject, buildInfo, target);
......
...@@ -30,15 +30,9 @@ void main () { ...@@ -30,15 +30,9 @@ void main () {
}); });
testWithoutContext('migrators succeed', () { testWithoutContext('migrators succeed', () {
final FakeIOSMigrator fakeIOSMigrator = FakeIOSMigrator(succeeds: true); final FakeIOSMigrator fakeIOSMigrator = FakeIOSMigrator();
final ProjectMigration migration = ProjectMigration(<ProjectMigrator>[fakeIOSMigrator]); final ProjectMigration migration = ProjectMigration(<ProjectMigrator>[fakeIOSMigrator]);
expect(migration.run(), isTrue); migration.run();
});
testWithoutContext('migrators fail', () {
final FakeIOSMigrator fakeIOSMigrator = FakeIOSMigrator(succeeds: false);
final ProjectMigration migration = ProjectMigration(<ProjectMigrator>[fakeIOSMigrator]);
expect(migration.run(), isFalse);
}); });
group('remove framework linking and embedding migration', () { group('remove framework linking and embedding migration', () {
...@@ -61,7 +55,7 @@ void main () { ...@@ -61,7 +55,7 @@ void main () {
testLogger, testLogger,
testUsage testUsage
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(testUsage.events, isEmpty); expect(testUsage.events, isEmpty);
expect(xcodeProjectInfoFile.existsSync(), isFalse); expect(xcodeProjectInfoFile.existsSync(), isFalse);
...@@ -80,7 +74,7 @@ void main () { ...@@ -80,7 +74,7 @@ void main () {
testLogger, testLogger,
testUsage, testUsage,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(testUsage.events, isEmpty); expect(testUsage.events, isEmpty);
expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified); expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
...@@ -100,7 +94,7 @@ shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend. ...@@ -100,7 +94,7 @@ shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.
testLogger, testLogger,
testUsage, testUsage,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), contents); expect(xcodeProjectInfoFile.readAsStringSync(), contents);
expect(testLogger.statusText, isEmpty); expect(testLogger.statusText, isEmpty);
}); });
...@@ -127,7 +121,7 @@ keep this 2 ...@@ -127,7 +121,7 @@ keep this 2
testLogger, testLogger,
testUsage, testUsage,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(testUsage.events, isEmpty); expect(testUsage.events, isEmpty);
expect(xcodeProjectInfoFile.readAsStringSync(), r''' expect(xcodeProjectInfoFile.readAsStringSync(), r'''
...@@ -207,7 +201,7 @@ keep this 2 ...@@ -207,7 +201,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeWorkspaceSharedSettings.existsSync(), isFalse); expect(xcodeWorkspaceSharedSettings.existsSync(), isFalse);
expect(testLogger.traceText, contains('Xcode workspace settings not found, skipping build system migration')); expect(testLogger.traceText, contains('Xcode workspace settings not found, skipping build system migration'));
...@@ -230,7 +224,7 @@ keep this 2 ...@@ -230,7 +224,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeWorkspaceSharedSettings.existsSync(), isTrue); expect(xcodeWorkspaceSharedSettings.existsSync(), isTrue);
expect(testLogger.statusText, isEmpty); expect(testLogger.statusText, isEmpty);
}); });
...@@ -253,7 +247,7 @@ keep this 2 ...@@ -253,7 +247,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeWorkspaceSharedSettings.existsSync(), isFalse); expect(xcodeWorkspaceSharedSettings.existsSync(), isFalse);
expect(testLogger.statusText, contains('Legacy build system detected, removing')); expect(testLogger.statusText, contains('Legacy build system detected, removing'));
...@@ -279,7 +273,7 @@ keep this 2 ...@@ -279,7 +273,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectWorkspaceData.existsSync(), isFalse); expect(xcodeProjectWorkspaceData.existsSync(), isFalse);
expect(testLogger.traceText, contains('Xcode project workspace data not found, skipping build location migration.')); expect(testLogger.traceText, contains('Xcode project workspace data not found, skipping build location migration.'));
...@@ -301,7 +295,7 @@ keep this 2 ...@@ -301,7 +295,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectWorkspaceData.existsSync(), isTrue); expect(xcodeProjectWorkspaceData.existsSync(), isTrue);
expect(testLogger.statusText, isEmpty); expect(testLogger.statusText, isEmpty);
}); });
...@@ -325,7 +319,7 @@ keep this 2 ...@@ -325,7 +319,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectWorkspaceData.readAsStringSync(), ''' expect(xcodeProjectWorkspaceData.readAsStringSync(), '''
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Workspace <Workspace
...@@ -358,7 +352,7 @@ keep this 2 ...@@ -358,7 +352,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.existsSync(), isFalse); expect(xcodeProjectInfoFile.existsSync(), isFalse);
expect(testLogger.traceText, contains('Xcode project not found, skipping Runner project build settings and configuration migration')); expect(testLogger.traceText, contains('Xcode project not found, skipping Runner project build settings and configuration migration'));
...@@ -374,7 +368,7 @@ keep this 2 ...@@ -374,7 +368,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified); expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
expect(xcodeProjectInfoFile.readAsStringSync(), contents); expect(xcodeProjectInfoFile.readAsStringSync(), contents);
...@@ -402,7 +396,7 @@ keep this 3 ...@@ -402,7 +396,7 @@ keep this 3
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), ''' expect(xcodeProjectInfoFile.readAsStringSync(), '''
97C147031CF9000F007C117D /* Debug */ = { 97C147031CF9000F007C117D /* Debug */ = {
...@@ -457,7 +451,7 @@ keep this 3 ...@@ -457,7 +451,7 @@ keep this 3
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), ''' expect(xcodeProjectInfoFile.readAsStringSync(), '''
97C147031CF9000F007C1171 /* Debug */ = { 97C147031CF9000F007C1171 /* Debug */ = {
...@@ -520,7 +514,7 @@ keep this 3 ...@@ -520,7 +514,7 @@ keep this 3
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.existsSync(), isFalse); expect(xcodeProjectInfoFile.existsSync(), isFalse);
expect(appFrameworkInfoPlist.existsSync(), isFalse); expect(appFrameworkInfoPlist.existsSync(), isFalse);
expect(podfile.existsSync(), isFalse); expect(podfile.existsSync(), isFalse);
...@@ -551,7 +545,7 @@ keep this 3 ...@@ -551,7 +545,7 @@ keep this 3
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified); expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents); expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);
...@@ -597,7 +591,7 @@ platform :ios, '9.0' ...@@ -597,7 +591,7 @@ platform :ios, '9.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), ''' expect(xcodeProjectInfoFile.readAsStringSync(), '''
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
...@@ -656,7 +650,7 @@ platform :ios, '11.0' ...@@ -656,7 +650,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.existsSync(), isFalse); expect(xcodeProjectInfoFile.existsSync(), isFalse);
expect(xcodeProjectSchemeFile.existsSync(), isFalse); expect(xcodeProjectSchemeFile.existsSync(), isFalse);
...@@ -688,7 +682,7 @@ platform :ios, '11.0' ...@@ -688,7 +682,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified); expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents); expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);
...@@ -718,7 +712,7 @@ platform :ios, '11.0' ...@@ -718,7 +712,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), ''' expect(xcodeProjectInfoFile.readAsStringSync(), '''
classes = { classes = {
...@@ -759,7 +753,7 @@ platform :ios, '11.0' ...@@ -759,7 +753,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(infoPlistFile.existsSync(), isFalse); expect(infoPlistFile.existsSync(), isFalse);
expect(testLogger.traceText, contains('Info.plist not found, skipping host app Info.plist migration.')); expect(testLogger.traceText, contains('Info.plist not found, skipping host app Info.plist migration.'));
...@@ -786,7 +780,7 @@ platform :ios, '11.0' ...@@ -786,7 +780,7 @@ platform :ios, '11.0'
testLogger, testLogger,
); );
final DateTime infoPlistFileLastModified = infoPlistFile.lastModifiedSync(); final DateTime infoPlistFileLastModified = infoPlistFile.lastModifiedSync();
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(infoPlistFile.lastModifiedSync(), infoPlistFileLastModified); expect(infoPlistFile.lastModifiedSync(), infoPlistFileLastModified);
expect(testLogger.statusText, isEmpty); expect(testLogger.statusText, isEmpty);
...@@ -807,7 +801,7 @@ platform :ios, '11.0' ...@@ -807,7 +801,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(infoPlistFile.readAsStringSync(), equals(''' expect(infoPlistFile.readAsStringSync(), equals('''
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
...@@ -913,7 +907,7 @@ platform :ios, '11.0' ...@@ -913,7 +907,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.existsSync(), isFalse); expect(xcodeProjectInfoFile.existsSync(), isFalse);
expect(testLogger.traceText, contains('Xcode project not found, skipping script build phase dependency analysis removal')); expect(testLogger.traceText, contains('Xcode project not found, skipping script build phase dependency analysis removal'));
...@@ -939,7 +933,7 @@ platform :ios, '11.0' ...@@ -939,7 +933,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified); expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents); expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);
...@@ -970,7 +964,7 @@ platform :ios, '11.0' ...@@ -970,7 +964,7 @@ platform :ios, '11.0'
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); iosProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), ''' expect(xcodeProjectInfoFile.readAsStringSync(), '''
/* Begin PBXShellScriptBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */
...@@ -1020,15 +1014,11 @@ class FakeIosProject extends Fake implements IosProject { ...@@ -1020,15 +1014,11 @@ class FakeIosProject extends Fake implements IosProject {
} }
class FakeIOSMigrator extends ProjectMigrator { class FakeIOSMigrator extends ProjectMigrator {
FakeIOSMigrator({required this.succeeds}) FakeIOSMigrator()
: super(BufferLogger.test()); : super(BufferLogger.test());
final bool succeeds;
@override @override
bool migrate() { void migrate() {}
return succeeds;
}
@override @override
String migrateLine(String line) { String migrateLine(String line) {
......
...@@ -37,7 +37,7 @@ void main() { ...@@ -37,7 +37,7 @@ void main() {
testLogger, testLogger,
testUsage, testUsage,
); );
expect(macosProjectMigration.migrate(), isTrue); macosProjectMigration.migrate();
expect(testUsage.events, isEmpty); expect(testUsage.events, isEmpty);
expect(xcodeProjectInfoFile.existsSync(), isFalse); expect(xcodeProjectInfoFile.existsSync(), isFalse);
...@@ -61,7 +61,7 @@ void main() { ...@@ -61,7 +61,7 @@ void main() {
testLogger, testLogger,
testUsage, testUsage,
); );
expect(macosProjectMigration.migrate(), isTrue); macosProjectMigration.migrate();
expect(testUsage.events, isEmpty); expect(testUsage.events, isEmpty);
expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified); expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
...@@ -82,7 +82,7 @@ shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/. ...@@ -82,7 +82,7 @@ shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.
testLogger, testLogger,
testUsage, testUsage,
); );
expect(macosProjectMigration.migrate(), isTrue); macosProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), contents); expect(xcodeProjectInfoFile.readAsStringSync(), contents);
expect(testLogger.statusText, isEmpty); expect(testLogger.statusText, isEmpty);
}); });
...@@ -105,7 +105,7 @@ keep this 2 ...@@ -105,7 +105,7 @@ keep this 2
testLogger, testLogger,
testUsage, testUsage,
); );
expect(macosProjectMigration.migrate(), isTrue); macosProjectMigration.migrate();
expect(testUsage.events, isEmpty); expect(testUsage.events, isEmpty);
expect(xcodeProjectInfoFile.readAsStringSync(), r''' expect(xcodeProjectInfoFile.readAsStringSync(), r'''
...@@ -178,7 +178,7 @@ keep this 2 ...@@ -178,7 +178,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(macOSProjectMigration.migrate(), isTrue); macOSProjectMigration.migrate();
expect(xcodeProjectInfoFile.existsSync(), isFalse); expect(xcodeProjectInfoFile.existsSync(), isFalse);
expect(podfile.existsSync(), isFalse); expect(podfile.existsSync(), isFalse);
...@@ -201,7 +201,7 @@ keep this 2 ...@@ -201,7 +201,7 @@ keep this 2
project, project,
testLogger, testLogger,
); );
expect(macOSProjectMigration.migrate(), isTrue); macOSProjectMigration.migrate();
expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified); expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents); expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);
...@@ -227,7 +227,7 @@ platform :osx, '10.11' ...@@ -227,7 +227,7 @@ platform :osx, '10.11'
project, project,
testLogger, testLogger,
); );
expect(macOSProjectMigration.migrate(), isTrue); macOSProjectMigration.migrate();
expect(xcodeProjectInfoFile.readAsStringSync(), ''' expect(xcodeProjectInfoFile.readAsStringSync(), '''
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
......
...@@ -15,18 +15,6 @@ import '../../src/common.dart'; ...@@ -15,18 +15,6 @@ import '../../src/common.dart';
void main () { void main () {
group('CMake project migration', () { group('CMake project migration', () {
testWithoutContext('migrators succeed', () {
final FakeCmakeMigrator fakeCmakeMigrator = FakeCmakeMigrator(succeeds: true);
final ProjectMigration migration = ProjectMigration(<ProjectMigrator>[fakeCmakeMigrator]);
expect(migration.run(), isTrue);
});
testWithoutContext('migrators fail', () {
final FakeCmakeMigrator fakeCmakeMigrator = FakeCmakeMigrator(succeeds: false);
final ProjectMigration migration = ProjectMigration(<ProjectMigrator>[fakeCmakeMigrator]);
expect(migration.run(), isFalse);
});
group('migrate add_custom_command() to use VERBATIM', () { group('migrate add_custom_command() to use VERBATIM', () {
late MemoryFileSystem memoryFileSystem; late MemoryFileSystem memoryFileSystem;
late BufferLogger testLogger; late BufferLogger testLogger;
...@@ -50,7 +38,7 @@ void main () { ...@@ -50,7 +38,7 @@ void main () {
mockCmakeProject, mockCmakeProject,
testLogger, testLogger,
); );
expect(cmakeProjectMigration.migrate(), isTrue); cmakeProjectMigration.migrate();
expect(managedCmakeFile.existsSync(), isFalse); expect(managedCmakeFile.existsSync(), isFalse);
expect(testLogger.traceText, contains('CMake project not found, skipping add_custom_command() VERBATIM migration')); expect(testLogger.traceText, contains('CMake project not found, skipping add_custom_command() VERBATIM migration'));
...@@ -66,7 +54,7 @@ void main () { ...@@ -66,7 +54,7 @@ void main () {
mockCmakeProject, mockCmakeProject,
testLogger, testLogger,
); );
expect(cmakeProjectMigration.migrate(), isTrue); cmakeProjectMigration.migrate();
expect(managedCmakeFile.lastModifiedSync(), projectLastModified); expect(managedCmakeFile.lastModifiedSync(), projectLastModified);
expect(managedCmakeFile.readAsStringSync(), contents); expect(managedCmakeFile.readAsStringSync(), contents);
...@@ -93,7 +81,7 @@ add_custom_command( ...@@ -93,7 +81,7 @@ add_custom_command(
mockCmakeProject, mockCmakeProject,
testLogger, testLogger,
); );
expect(cmakeProjectMigration.migrate(), isTrue); cmakeProjectMigration.migrate();
expect(managedCmakeFile.lastModifiedSync(), projectLastModified); expect(managedCmakeFile.lastModifiedSync(), projectLastModified);
expect(managedCmakeFile.readAsStringSync(), contents); expect(managedCmakeFile.readAsStringSync(), contents);
...@@ -117,7 +105,7 @@ add_custom_command( ...@@ -117,7 +105,7 @@ add_custom_command(
mockCmakeProject, mockCmakeProject,
testLogger, testLogger,
); );
expect(cmakeProjectMigration.migrate(), isTrue); cmakeProjectMigration.migrate();
expect(managedCmakeFile.readAsStringSync(), r''' expect(managedCmakeFile.readAsStringSync(), r'''
add_custom_command( add_custom_command(
...@@ -151,7 +139,7 @@ add_custom_command( ...@@ -151,7 +139,7 @@ add_custom_command(
mockCmakeProject, mockCmakeProject,
testLogger, testLogger,
); );
expect(cmakeProjectMigration.migrate(), isTrue); cmakeProjectMigration.migrate();
expect(managedCmakeFile.readAsStringSync(), r''' expect(managedCmakeFile.readAsStringSync(), r'''
add_custom_command( add_custom_command(
...@@ -179,15 +167,11 @@ class FakeCmakeProject extends Fake implements CmakeBasedProject { ...@@ -179,15 +167,11 @@ class FakeCmakeProject extends Fake implements CmakeBasedProject {
} }
class FakeCmakeMigrator extends ProjectMigrator { class FakeCmakeMigrator extends ProjectMigrator {
FakeCmakeMigrator({required this.succeeds}) FakeCmakeMigrator()
: super(BufferLogger.test()); : super(BufferLogger.test());
final bool succeeds;
@override @override
bool migrate() { void migrate() { }
return succeeds;
}
@override @override
String migrateLine(String line) { String migrateLine(String line) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment