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