Return void from project migrate() (#112897)
This commit is contained in:
@@ -16,8 +16,7 @@ abstract class ProjectMigrator {
|
||||
@protected
|
||||
final Logger logger;
|
||||
|
||||
/// Returns whether migration was successful or was skipped.
|
||||
bool migrate();
|
||||
void migrate();
|
||||
|
||||
/// Return null if the line should be deleted.
|
||||
@protected
|
||||
@@ -80,15 +79,9 @@ class ProjectMigration {
|
||||
|
||||
final List<ProjectMigrator> migrators;
|
||||
|
||||
bool run() {
|
||||
void run() {
|
||||
for (final ProjectMigrator migrator in migrators) {
|
||||
if (!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;
|
||||
}
|
||||
migrator.migrate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,9 +133,7 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
if (!migration.run()) {
|
||||
return XcodeBuildResult(success: false);
|
||||
}
|
||||
migration.run();
|
||||
|
||||
if (!_checkXcodeVersion()) {
|
||||
return XcodeBuildResult(success: false);
|
||||
|
||||
@@ -19,14 +19,13 @@ class HostAppInfoPlistMigration extends ProjectMigrator {
|
||||
final File _infoPlist;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_infoPlist.existsSync()) {
|
||||
logger.printTrace('Info.plist not found, skipping host app Info.plist migration.');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
processFileLines(_infoPlist);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -20,7 +20,7 @@ class IOSDeploymentTargetMigration extends ProjectMigrator {
|
||||
final File _appFrameworkInfoPlist;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (_xcodeProjectInfoFile.existsSync()) {
|
||||
processFileLines(_xcodeProjectInfoFile);
|
||||
} else {
|
||||
@@ -38,8 +38,6 @@ class IOSDeploymentTargetMigration extends ProjectMigrator {
|
||||
} else {
|
||||
logger.printTrace('Podfile not found, skipping global platform iOS version migration.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -16,10 +16,10 @@ class ProjectBaseConfigurationMigration extends ProjectMigrator {
|
||||
final File _xcodeProjectInfoFile;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_xcodeProjectInfoFile.existsSync()) {
|
||||
logger.printTrace('Xcode project not found, skipping Runner project build settings and configuration migration');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
final String originalProjectContents = _xcodeProjectInfoFile.readAsStringSync();
|
||||
@@ -84,6 +84,5 @@ class ProjectBaseConfigurationMigration extends ProjectMigrator {
|
||||
logger.printStatus('Project base configurations detected, removing.');
|
||||
_xcodeProjectInfoFile.writeAsStringSync(newProjectContents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,13 @@ class ProjectBuildLocationMigration extends ProjectMigrator {
|
||||
final File _xcodeProjectWorkspaceData;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_xcodeProjectWorkspaceData.existsSync()) {
|
||||
logger.printTrace('Xcode project workspace data not found, skipping build location migration.');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
processFileLines(_xcodeProjectWorkspaceData);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -23,15 +23,13 @@ class RemoveFrameworkLinkAndEmbeddingMigration extends ProjectMigrator {
|
||||
final Usage _usage;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_xcodeProjectInfoFile.existsSync()) {
|
||||
logger.printTrace('Xcode project not found, skipping framework link and embedding migration');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
processFileLines(_xcodeProjectInfoFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -18,10 +18,10 @@ class XcodeBuildSystemMigration extends ProjectMigrator {
|
||||
final File _xcodeWorkspaceSharedSettings;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_xcodeWorkspaceSharedSettings.existsSync()) {
|
||||
logger.printTrace('Xcode workspace settings not found, skipping build system migration');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
final String contents = _xcodeWorkspaceSharedSettings.readAsStringSync();
|
||||
@@ -36,7 +36,5 @@ class XcodeBuildSystemMigration extends ProjectMigrator {
|
||||
logger.printStatus('Legacy build system detected, removing ${_xcodeWorkspaceSharedSettings.path}');
|
||||
_xcodeWorkspaceSharedSettings.deleteSync();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +47,7 @@ Future<void> buildLinux(
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
if (!migration.run()) {
|
||||
throwToolExit('Unable to migrate project files');
|
||||
}
|
||||
migration.run();
|
||||
|
||||
// Build the environment that needs to be set for the re-entrant flutter build
|
||||
// step.
|
||||
|
||||
@@ -54,9 +54,7 @@ Future<void> buildMacOS({
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
if (!migration.run()) {
|
||||
throwToolExit('Could not migrate project file');
|
||||
}
|
||||
migration.run();
|
||||
|
||||
final Directory flutterBuildDir = globals.fs.directory(getMacOSBuildDirectory());
|
||||
if (!flutterBuildDir.existsSync()) {
|
||||
|
||||
@@ -18,7 +18,7 @@ class MacOSDeploymentTargetMigration extends ProjectMigrator {
|
||||
final File _podfile;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (_xcodeProjectInfoFile.existsSync()) {
|
||||
processFileLines(_xcodeProjectInfoFile);
|
||||
} else {
|
||||
@@ -30,8 +30,6 @@ class MacOSDeploymentTargetMigration extends ProjectMigrator {
|
||||
} else {
|
||||
logger.printTrace('Podfile not found, skipping global platform macOS version migration.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -21,16 +21,14 @@ class RemoveMacOSFrameworkLinkAndEmbeddingMigration extends ProjectMigrator {
|
||||
final Usage _usage;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_xcodeProjectInfoFile.existsSync()) {
|
||||
logger.printTrace(
|
||||
'Xcode project not found, skipping framework link and embedding migration');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
processFileLines(_xcodeProjectInfoFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -16,10 +16,10 @@ class CmakeCustomCommandMigration extends ProjectMigrator {
|
||||
final File _cmakeFile;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_cmakeFile.existsSync()) {
|
||||
logger.printTrace('CMake project not found, skipping add_custom_command() VERBATIM migration');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
final String originalProjectContents = _cmakeFile.readAsStringSync();
|
||||
@@ -68,6 +68,5 @@ class CmakeCustomCommandMigration extends ProjectMigrator {
|
||||
logger.printStatus('add_custom_command() missing VERBATIM or FLUTTER_TARGET_PLATFORM, updating.');
|
||||
_cmakeFile.writeAsStringSync(newProjectContents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class XcodeProjectObjectVersionMigration extends ProjectMigrator {
|
||||
final File _xcodeProjectSchemeFile;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (_xcodeProjectInfoFile.existsSync()) {
|
||||
processFileLines(_xcodeProjectInfoFile);
|
||||
} else {
|
||||
@@ -29,8 +29,6 @@ class XcodeProjectObjectVersionMigration extends ProjectMigrator {
|
||||
} else {
|
||||
logger.printTrace('Runner scheme not found, skipping Xcode compatibility migration.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -15,10 +15,10 @@ class XcodeScriptBuildPhaseMigration extends ProjectMigrator {
|
||||
final File _xcodeProjectInfoFile;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
if (!_xcodeProjectInfoFile.existsSync()) {
|
||||
logger.printTrace('Xcode project not found, skipping script build phase dependency analysis removal.');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
final String originalProjectContents = _xcodeProjectInfoFile.readAsStringSync();
|
||||
@@ -56,6 +56,5 @@ class XcodeScriptBuildPhaseMigration extends ProjectMigrator {
|
||||
logger.printStatus('Removing script build phase dependency analysis.');
|
||||
_xcodeProjectInfoFile.writeAsStringSync(newProjectContents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@ Future<void> buildWeb(
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
if (!migration.run()) {
|
||||
throwToolExit('Failed to run all web migrations.');
|
||||
}
|
||||
migration.run();
|
||||
|
||||
final Status status = globals.logger.startProgress('Compiling $target for the Web...');
|
||||
final Stopwatch sw = Stopwatch()..start();
|
||||
|
||||
@@ -18,17 +18,16 @@ class ScrubGeneratedPluginRegistrant extends ProjectMigrator {
|
||||
final Logger _logger;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
void migrate() {
|
||||
final File registrant = _project.libDirectory.childFile('generated_plugin_registrant.dart');
|
||||
final File gitignore = _project.parent.directory.childFile('.gitignore');
|
||||
|
||||
if (!removeFile(registrant)) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (gitignore.existsSync()) {
|
||||
processFileLines(gitignore);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cleans up the .gitignore by removing the line that mentions generated_plugin_registrant.
|
||||
|
||||
@@ -54,9 +54,7 @@ Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
if (!migration.run()) {
|
||||
throwToolExit('Unable to migrate project files');
|
||||
}
|
||||
migration.run();
|
||||
|
||||
// Ensure that necessary ephemeral files are generated and up to date.
|
||||
_writeGeneratedFlutterConfig(windowsProject, buildInfo, target);
|
||||
|
||||
Reference in New Issue
Block a user