Unverified Commit a476a08e authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

check if project exists before regenerating platform specific tooling (#31342)

parent 1200ae33
...@@ -443,7 +443,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi ...@@ -443,7 +443,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
offline: argResults['offline'], offline: argResults['offline'],
); );
final FlutterProject project = await FlutterProject.fromDirectory(directory); final FlutterProject project = await FlutterProject.fromDirectory(directory);
await project.ensureReadyForPlatformSpecificTooling(); await project.ensureReadyForPlatformSpecificTooling(checkProjects: false);
} }
return generatedCount; return generatedCount;
} }
...@@ -510,7 +510,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi ...@@ -510,7 +510,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
if (argResults['pub']) { if (argResults['pub']) {
await pubGet(context: PubContext.create, directory: directory.path, offline: argResults['offline']); await pubGet(context: PubContext.create, directory: directory.path, offline: argResults['offline']);
await project.ensureReadyForPlatformSpecificTooling(); await project.ensureReadyForPlatformSpecificTooling(checkProjects: false);
} }
gradle.updateLocalProperties(project: project, requireAndroidSdk: false); gradle.updateLocalProperties(project: project, requireAndroidSdk: false);
......
...@@ -29,8 +29,8 @@ class InjectPluginsCommand extends FlutterCommand { ...@@ -29,8 +29,8 @@ class InjectPluginsCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
final FlutterProject project = await FlutterProject.current(); final FlutterProject project = await FlutterProject.current();
refreshPluginsList(project); refreshPluginsList(project, checkProjects: true);
await injectPlugins(project); await injectPlugins(project, checkProjects: true);
final bool result = hasPlugins(project); final bool result = hasPlugins(project);
if (result) { if (result) {
printStatus('GeneratedPluginRegistrants successfully written.'); printStatus('GeneratedPluginRegistrants successfully written.');
......
...@@ -43,7 +43,7 @@ class MakeHostAppEditableCommand extends FlutterCommand { ...@@ -43,7 +43,7 @@ class MakeHostAppEditableCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
await _project.ensureReadyForPlatformSpecificTooling(); await _project.ensureReadyForPlatformSpecificTooling(checkProjects: false);
final bool isAndroidRequested = argResults['android']; final bool isAndroidRequested = argResults['android'];
final bool isIOSRequested = argResults['ios']; final bool isIOSRequested = argResults['ios'];
......
...@@ -94,13 +94,13 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -94,13 +94,13 @@ class PackagesGetCommand extends FlutterCommand {
await _runPubGet(target); await _runPubGet(target);
final FlutterProject rootProject = await FlutterProject.fromPath(target); final FlutterProject rootProject = await FlutterProject.fromPath(target);
await rootProject.ensureReadyForPlatformSpecificTooling(); await rootProject.ensureReadyForPlatformSpecificTooling(checkProjects: true);
// Get/upgrade packages in example app as well // Get/upgrade packages in example app as well
if (rootProject.hasExampleApp) { if (rootProject.hasExampleApp) {
final FlutterProject exampleProject = rootProject.example; final FlutterProject exampleProject = rootProject.example;
await _runPubGet(exampleProject.directory.path); await _runPubGet(exampleProject.directory.path);
await exampleProject.ensureReadyForPlatformSpecificTooling(); await exampleProject.ensureReadyForPlatformSpecificTooling(checkProjects: true);
} }
return null; return null;
......
...@@ -98,9 +98,10 @@ bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) { ...@@ -98,9 +98,10 @@ bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
if (pluginManifest.isNotEmpty) { if (pluginManifest.isNotEmpty) {
pluginsFile.writeAsStringSync('$pluginManifest\n', flush: true); pluginsFile.writeAsStringSync('$pluginManifest\n', flush: true);
} else { } else {
if (pluginsFile.existsSync()) if (pluginsFile.existsSync()) {
pluginsFile.deleteSync(); pluginsFile.deleteSync();
} }
}
final String newContents = _readFlutterPluginsList(project); final String newContents = _readFlutterPluginsList(project);
return oldContents != newContents; return oldContents != newContents;
} }
...@@ -282,31 +283,44 @@ Future<void> _writeIOSPluginRegistrant(FlutterProject project, List<Plugin> plug ...@@ -282,31 +283,44 @@ Future<void> _writeIOSPluginRegistrant(FlutterProject project, List<Plugin> plug
/// Rewrites the `.flutter-plugins` file of [project] based on the plugin /// Rewrites the `.flutter-plugins` file of [project] based on the plugin
/// dependencies declared in `pubspec.yaml`. /// dependencies declared in `pubspec.yaml`.
/// ///
/// If `checkProjects` is true, then plugins are only injected into directories
/// which already exist.
///
/// Assumes `pub get` has been executed since last change to `pubspec.yaml`. /// Assumes `pub get` has been executed since last change to `pubspec.yaml`.
void refreshPluginsList(FlutterProject project) { void refreshPluginsList(FlutterProject project, {bool checkProjects = false}) {
final List<Plugin> plugins = findPlugins(project); final List<Plugin> plugins = findPlugins(project);
final bool changed = _writeFlutterPluginsList(project, plugins); final bool changed = _writeFlutterPluginsList(project, plugins);
if (changed) if (changed) {
if (checkProjects && !project.ios.existsSync()) {
return;
}
cocoaPods.invalidatePodInstallOutput(project.ios); cocoaPods.invalidatePodInstallOutput(project.ios);
}
} }
/// Injects plugins found in `pubspec.yaml` into the platform-specific projects. /// Injects plugins found in `pubspec.yaml` into the platform-specific projects.
/// ///
/// If `checkProjects` is true, then plugins are only injected into directories
/// which already exist.
///
/// Assumes [refreshPluginsList] has been called since last change to `pubspec.yaml`. /// Assumes [refreshPluginsList] has been called since last change to `pubspec.yaml`.
Future<void> injectPlugins(FlutterProject project) async { Future<void> injectPlugins(FlutterProject project, {bool checkProjects = false}) async {
final List<Plugin> plugins = findPlugins(project); final List<Plugin> plugins = findPlugins(project);
if ((checkProjects && project.android.existsSync()) || !checkProjects) {
await _writeAndroidPluginRegistrant(project, plugins); await _writeAndroidPluginRegistrant(project, plugins);
}
if ((checkProjects && project.ios.existsSync()) || !checkProjects) {
await _writeIOSPluginRegistrant(project, plugins); await _writeIOSPluginRegistrant(project, plugins);
if (!project.isModule && project.ios.hostAppRoot.existsSync()) { }
final IosProject iosProject = IosProject.fromFlutter(project); if (!project.isModule && ((project.ios.hostAppRoot.existsSync() && checkProjects) || !checkProjects)) {
final CocoaPods cocoaPods = CocoaPods(); final CocoaPods cocoaPods = CocoaPods();
if (plugins.isNotEmpty) { if (plugins.isNotEmpty) {
cocoaPods.setupPodfile(project.ios); cocoaPods.setupPodfile(project.ios);
} }
/// The user may have a custom maintained Podfile that they're running `pod install` /// The user may have a custom maintained Podfile that they're running `pod install`
/// on themselves. /// on themselves.
else if (iosProject.podfile.existsSync() && iosProject.podfileLock.existsSync()) { else if (project.ios.podfile.existsSync() && project.ios.podfileLock.existsSync()) {
cocoaPods.addPodsDependencyToFlutterXcconfig(iosProject); cocoaPods.addPodsDependencyToFlutterXcconfig(project.ios);
} }
} }
} }
......
...@@ -158,16 +158,21 @@ class FlutterProject { ...@@ -158,16 +158,21 @@ class FlutterProject {
/// Generates project files necessary to make Gradle builds work on Android /// Generates project files necessary to make Gradle builds work on Android
/// and CocoaPods+Xcode work on iOS, for app and module projects only. /// and CocoaPods+Xcode work on iOS, for app and module projects only.
Future<void> ensureReadyForPlatformSpecificTooling() async { Future<void> ensureReadyForPlatformSpecificTooling({bool checkProjects = false}) async {
if (!directory.existsSync() || hasExampleApp) if (!directory.existsSync() || hasExampleApp) {
return; return;
}
refreshPluginsList(this); refreshPluginsList(this);
if ((android.existsSync() && checkProjects) || !checkProjects) {
await android.ensureReadyForPlatformSpecificTooling(); await android.ensureReadyForPlatformSpecificTooling();
}
if ((ios.existsSync() && checkProjects) || !checkProjects) {
await ios.ensureReadyForPlatformSpecificTooling(); await ios.ensureReadyForPlatformSpecificTooling();
}
if (flutterWebEnabled) { if (flutterWebEnabled) {
await web.ensureReadyForPlatformSpecificTooling(); await web.ensureReadyForPlatformSpecificTooling();
} }
await injectPlugins(this); await injectPlugins(this, checkProjects: checkProjects);
} }
/// Return the set of builders used by this package. /// Return the set of builders used by this package.
...@@ -203,6 +208,8 @@ class IosProject { ...@@ -203,6 +208,8 @@ class IosProject {
Directory get _ephemeralDirectory => parent.directory.childDirectory('.ios'); Directory get _ephemeralDirectory => parent.directory.childDirectory('.ios');
Directory get _editableDirectory => parent.directory.childDirectory('ios'); Directory get _editableDirectory => parent.directory.childDirectory('ios');
bool existsSync() => parent.isModule || _editableDirectory.existsSync();
/// This parent folder of `Runner.xcodeproj`. /// This parent folder of `Runner.xcodeproj`.
Directory get hostAppRoot { Directory get hostAppRoot {
if (!isModule || _editableDirectory.existsSync()) if (!isModule || _editableDirectory.existsSync())
...@@ -381,6 +388,8 @@ class AndroidProject { ...@@ -381,6 +388,8 @@ class AndroidProject {
return _ephemeralDirectory; return _ephemeralDirectory;
} }
bool existsSync() => parent.isModule || _flutterLibGradleRoot.existsSync();
/// The Gradle root directory of the Android wrapping of Flutter and plugins. /// The Gradle root directory of the Android wrapping of Flutter and plugins.
/// This is the same as [hostAppGradleRoot] except when the project is /// This is the same as [hostAppGradleRoot] except when the project is
/// a Flutter module with an editable host app. /// a Flutter module with an editable host app.
...@@ -486,6 +495,8 @@ class WebProject { ...@@ -486,6 +495,8 @@ class WebProject {
final FlutterProject parent; final FlutterProject parent;
bool existsSync() => parent.directory.childDirectory('web').existsSync();
Future<void> ensureReadyForPlatformSpecificTooling() async { Future<void> ensureReadyForPlatformSpecificTooling() async {
/// Generate index.html in build/web. Eventually we could support /// Generate index.html in build/web. Eventually we could support
/// a custom html under the web sub directory. /// a custom html under the web sub directory.
......
...@@ -475,7 +475,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -475,7 +475,7 @@ abstract class FlutterCommand extends Command<void> {
if (shouldRunPub) { if (shouldRunPub) {
await pubGet(context: PubContext.getVerifyContext(name)); await pubGet(context: PubContext.getVerifyContext(name));
final FlutterProject project = await FlutterProject.current(); final FlutterProject project = await FlutterProject.current();
await project.ensureReadyForPlatformSpecificTooling(); await project.ensureReadyForPlatformSpecificTooling(checkProjects: true);
} }
setupApplicationPackages(); setupApplicationPackages();
......
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