From ee0aebe2f33c234d0ec9dfd55f36148822d3b27e Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Sun, 23 Oct 2022 14:53:01 +0200 Subject: [PATCH 01/10] Update tool to set macOS deployment target to 10.15. This change is necessary for https://github.com/flutter/plugins/pull/6517. --- .../src/create_all_plugins_app_command.dart | 82 ++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index a23dc83d98f3..345de924396d 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -61,10 +61,19 @@ class CreateAllPluginsAppCommand extends PackageCommand { print(''); } + await _genPubspecWithAllPlugins(); + + /// Run `flutter pub get` to generate all native build files for macOS. + final int genNativeBuildFilesExitCode = await _genNativeBuildFiles(); + if (genNativeBuildFilesExitCode != 0) { + throw ToolExit(genNativeBuildFilesExitCode); + } + await Future.wait(>[ - _genPubspecWithAllPlugins(), _updateAppGradle(), _updateManifest(), + _updateMacosPodfile(), + _updateMacosPbxproj(), ]); } @@ -259,4 +268,75 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} return buffer.toString(); } + + Future _genNativeBuildFiles() async { + // Only run on macOS. + // Other platforms don't need generation of additional files. + if (!io.Platform.isMacOS) { + return 0; + } + + final io.ProcessResult result = io.Process.runSync( + flutterCommand, + [ + 'pub', + 'get', + ], + workingDirectory: _appDirectory.path, + ); + + print(result.stdout); + print(result.stderr); + return result.exitCode; + } + + Future _updateMacosPodfile() async { + // Only change the macOS deployment target if the host platform is macOS. + if (!io.Platform.isMacOS) { + return; + } + + final File podfileFile = + app.platformDirectory(FlutterPlatform.macos).childFile('Podfile'); + if (!podfileFile.existsSync()) { + throw ToolExit(64); + } + + final StringBuffer newPodfile = StringBuffer(); + for (final String line in podfileFile.readAsLinesSync()) { + if (line.contains('platform :osx')) { + // macOS 10.15 is required by in_app_purchase. + newPodfile.writeln("platform :osx, '10.15'"); + } else { + newPodfile.writeln(line); + } + } + podfileFile.writeAsStringSync(newPodfile.toString()); + } + + Future _updateMacosPbxproj() async { + // Only change the macOS deployment target if the host platform is macOS. + if (!io.Platform.isMacOS) { + return; + } + + final File pbxprojFile = app + .platformDirectory(FlutterPlatform.macos) + .childDirectory('Runner.xcodeproj') + .childFile('project.pbxproj'); + if (!pbxprojFile.existsSync()) { + throw ToolExit(64); + } + + final StringBuffer newPbxproj = StringBuffer(); + for (final String line in pbxprojFile.readAsLinesSync()) { + if (line.contains('MACOSX_DEPLOYMENT_TARGET')) { + // macOS 10.15 is required by in_app_purchase. + newPbxproj.writeln(' MACOSX_DEPLOYMENT_TARGET = 10.15;'); + } else { + newPbxproj.writeln(line); + } + } + pbxprojFile.writeAsStringSync(newPbxproj.toString()); + } } From abd3bc49d39805bebffd92e680a94bdc32c68cb2 Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:39:47 +0200 Subject: [PATCH 02/10] Added a unit test for changing the macOS deployment version. --- .../src/create_all_plugins_app_command.dart | 23 ++++------------- .../create_all_plugins_app_command_test.dart | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index 345de924396d..c008d6341066 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -15,6 +15,9 @@ import 'common/repository_package.dart'; const String _outputDirectoryFlag = 'output-dir'; +const int _exitUpdateMacosPodfileFailed = 3; +const int _exitUpdateMacosPbxprojFailed = 4; + /// A command to create an application that builds all in a single application. class CreateAllPluginsAppCommand extends PackageCommand { /// Creates an instance of the builder command. @@ -270,12 +273,6 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} } Future _genNativeBuildFiles() async { - // Only run on macOS. - // Other platforms don't need generation of additional files. - if (!io.Platform.isMacOS) { - return 0; - } - final io.ProcessResult result = io.Process.runSync( flutterCommand, [ @@ -291,15 +288,10 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} } Future _updateMacosPodfile() async { - // Only change the macOS deployment target if the host platform is macOS. - if (!io.Platform.isMacOS) { - return; - } - final File podfileFile = app.platformDirectory(FlutterPlatform.macos).childFile('Podfile'); if (!podfileFile.existsSync()) { - throw ToolExit(64); + throw ToolExit(_exitUpdateMacosPodfileFailed); } final StringBuffer newPodfile = StringBuffer(); @@ -315,17 +307,12 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} } Future _updateMacosPbxproj() async { - // Only change the macOS deployment target if the host platform is macOS. - if (!io.Platform.isMacOS) { - return; - } - final File pbxprojFile = app .platformDirectory(FlutterPlatform.macos) .childDirectory('Runner.xcodeproj') .childFile('project.pbxproj'); if (!pbxprojFile.existsSync()) { - throw ToolExit(64); + throw ToolExit(_exitUpdateMacosPbxprojFailed); } final StringBuffer newPbxproj = StringBuffer(); diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index 830dd59a8d42..85028f0d6a70 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -103,6 +103,31 @@ void main() { baselinePubspec.environment?[dartSdkKey]); }); + test('macOS deployment target is modified', () async { + await runCapturingPrint(runner, ['all-plugins-app']); + + final List podfile = command.app + .platformDirectory(FlutterPlatform.macos) + .childFile('Podfile') + .readAsLinesSync(); + final List pbxproj = command.app + .platformDirectory(FlutterPlatform.macos) + .childDirectory('Runner.xcodeproj') + .childFile('project.pbxproj') + .readAsLinesSync(); + + expect( + podfile, + everyElement((String line) => + !line.contains('platform :osx') || line.contains("'10.15'"))); + + expect( + pbxproj, + everyElement((String line) => + !line.contains('MACOSX_DEPLOYMENT_TARGET') || + line.contains('10.15'))); + }); + test('handles --output-dir', () async { createFakePlugin('plugina', packagesDir); From 5d2c73532bb15e6180e01c9624c7d423e878fc1d Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:30:21 +0200 Subject: [PATCH 03/10] Skip Podfile change on non-macOS platforms. The Podfile is only generated on a macOS host. --- .../src/create_all_plugins_app_command.dart | 5 +++++ .../create_all_plugins_app_command_test.dart | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index c008d6341066..41fdeeb4f7b1 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -288,6 +288,11 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} } Future _updateMacosPodfile() async { + // Only change the macOS deployment target if the host platform is macOS. + if (!io.Platform.isMacOS) { + return; + } + final File podfileFile = app.platformDirectory(FlutterPlatform.macos).childFile('Podfile'); if (!podfileFile.existsSync()) { diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index 85028f0d6a70..d63fdce557df 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -103,23 +103,28 @@ void main() { baselinePubspec.environment?[dartSdkKey]); }); - test('macOS deployment target is modified', () async { + test('macOS deployment target is modified in Podfile', () async { await runCapturingPrint(runner, ['all-plugins-app']); - final List podfile = command.app .platformDirectory(FlutterPlatform.macos) .childFile('Podfile') .readAsLinesSync(); - final List pbxproj = command.app - .platformDirectory(FlutterPlatform.macos) - .childDirectory('Runner.xcodeproj') - .childFile('project.pbxproj') - .readAsLinesSync(); expect( podfile, everyElement((String line) => !line.contains('platform :osx') || line.contains("'10.15'"))); + }, + // Podfile is only generated on macOS. + skip: !io.Platform.isMacOS); + + test('macOS deployment target is modified in pbxproj', () async { + await runCapturingPrint(runner, ['all-plugins-app']); + final List pbxproj = command.app + .platformDirectory(FlutterPlatform.macos) + .childDirectory('Runner.xcodeproj') + .childFile('project.pbxproj') + .readAsLinesSync(); expect( pbxproj, From 46a360ca081618fbae0d63c9029e36e53a4d435b Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Wed, 26 Oct 2022 21:59:27 +0200 Subject: [PATCH 04/10] Minor changes to error handling. Before throwing a `ToolExit`, a error message is printed. --- .../src/create_all_plugins_app_command.dart | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index 41fdeeb4f7b1..77f0845df630 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -17,6 +17,7 @@ const String _outputDirectoryFlag = 'output-dir'; const int _exitUpdateMacosPodfileFailed = 3; const int _exitUpdateMacosPbxprojFailed = 4; +const int _exitGenNativeBuildFilesFailed = 5; /// A command to create an application that builds all in a single application. class CreateAllPluginsAppCommand extends PackageCommand { @@ -66,10 +67,11 @@ class CreateAllPluginsAppCommand extends PackageCommand { await _genPubspecWithAllPlugins(); - /// Run `flutter pub get` to generate all native build files for macOS. - final int genNativeBuildFilesExitCode = await _genNativeBuildFiles(); - if (genNativeBuildFilesExitCode != 0) { - throw ToolExit(genNativeBuildFilesExitCode); + /// Run `flutter pub get` to generate all native build files. + final bool didGenNativeBuildFilesSucceed = await _genNativeBuildFiles(); + if (!didGenNativeBuildFilesSucceed) { + printError("Failed to generate native build files via 'flutter pub get'"); + throw ToolExit(_exitGenNativeBuildFilesFailed); } await Future.wait(>[ @@ -272,23 +274,21 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} return buffer.toString(); } - Future _genNativeBuildFiles() async { - final io.ProcessResult result = io.Process.runSync( + Future _genNativeBuildFiles() async { + final int exitCode = await processRunner.runAndStream( flutterCommand, [ 'pub', 'get', ], - workingDirectory: _appDirectory.path, + workingDir: _appDirectory, ); - - print(result.stdout); - print(result.stderr); - return result.exitCode; + return exitCode == 0; } Future _updateMacosPodfile() async { - // Only change the macOS deployment target if the host platform is macOS. + /// Only change the macOS deployment target if the host platform is macOS. + /// The Podfile is not generated on other platforms. if (!io.Platform.isMacOS) { return; } @@ -296,6 +296,7 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} final File podfileFile = app.platformDirectory(FlutterPlatform.macos).childFile('Podfile'); if (!podfileFile.existsSync()) { + printError("Can't find Podfile for macOS"); throw ToolExit(_exitUpdateMacosPodfileFailed); } @@ -317,6 +318,7 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} .childDirectory('Runner.xcodeproj') .childFile('project.pbxproj'); if (!pbxprojFile.existsSync()) { + printError("Can't find project.pbxproj for macOS"); throw ToolExit(_exitUpdateMacosPbxprojFailed); } From cc6277fd1b5f6961a54a512240da59003cf55b6a Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Wed, 26 Oct 2022 23:37:27 +0200 Subject: [PATCH 05/10] Mocked out `pub get` while testing 'all-plugins-app'-command. --- script/tool/lib/src/create_all_plugins_app_command.dart | 4 +++- script/tool/test/create_all_plugins_app_command_test.dart | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index 77f0845df630..ce8c35216956 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -11,6 +11,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; import 'common/core.dart'; import 'common/package_command.dart'; +import 'common/process_runner.dart'; import 'common/repository_package.dart'; const String _outputDirectoryFlag = 'output-dir'; @@ -24,8 +25,9 @@ class CreateAllPluginsAppCommand extends PackageCommand { /// Creates an instance of the builder command. CreateAllPluginsAppCommand( Directory packagesDir, { + ProcessRunner processRunner = const ProcessRunner(), Directory? pluginsRoot, - }) : super(packagesDir) { + }) : super(packagesDir, processRunner: processRunner) { final Directory defaultDir = pluginsRoot ?? packagesDir.fileSystem.currentDirectory; argParser.addOption(_outputDirectoryFlag, diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index d63fdce557df..9c565c23519d 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -20,6 +20,7 @@ void main() { late FileSystem fileSystem; late Directory testRoot; late Directory packagesDir; + late RecordingProcessRunner processRunner; setUp(() { // Since the core of this command is a call to 'flutter create', the test @@ -28,9 +29,11 @@ void main() { fileSystem = const LocalFileSystem(); testRoot = fileSystem.systemTempDirectory.createTempSync(); packagesDir = testRoot.childDirectory('packages'); + processRunner = RecordingProcessRunner(); command = CreateAllPluginsAppCommand( packagesDir, + processRunner: processRunner, pluginsRoot: testRoot, ); runner = CommandRunner( From 45ea1cf8433ac2531261516017d4a472d338fd11 Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Thu, 27 Oct 2022 00:23:25 +0200 Subject: [PATCH 06/10] Add additional tests to ensure the mocked out `flutter pub get` call is correct. --- .../src/create_all_plugins_app_command.dart | 4 +- .../create_all_plugins_app_command_test.dart | 63 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index ce8c35216956..e042fcf866a8 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -6,6 +6,7 @@ import 'dart:io' as io; import 'package:file/file.dart'; import 'package:path/path.dart' as p; +import 'package:platform/platform.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; @@ -27,7 +28,8 @@ class CreateAllPluginsAppCommand extends PackageCommand { Directory packagesDir, { ProcessRunner processRunner = const ProcessRunner(), Directory? pluginsRoot, - }) : super(packagesDir, processRunner: processRunner) { + Platform platform = const LocalPlatform(), + }) : super(packagesDir, processRunner: processRunner, platform: platform) { final Directory defaultDir = pluginsRoot ?? packagesDir.fileSystem.currentDirectory; argParser.addOption(_outputDirectoryFlag, diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index 9c565c23519d..0868dadd9492 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -7,10 +7,12 @@ import 'dart:io' as io; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; import 'package:file/local.dart'; +import 'package:flutter_plugin_tools/src/common/core.dart'; import 'package:flutter_plugin_tools/src/create_all_plugins_app_command.dart'; import 'package:platform/platform.dart'; import 'package:test/test.dart'; +import 'mocks.dart'; import 'util.dart'; void main() { @@ -18,6 +20,7 @@ void main() { late CommandRunner runner; late CreateAllPluginsAppCommand command; late FileSystem fileSystem; + late MockPlatform mockPlatform; late Directory testRoot; late Directory packagesDir; late RecordingProcessRunner processRunner; @@ -27,6 +30,7 @@ void main() { // has to use the real filesystem. Put everything possible in a unique // temporary to minimize effect on the host system. fileSystem = const LocalFileSystem(); + mockPlatform = MockPlatform(); testRoot = fileSystem.systemTempDirectory.createTempSync(); packagesDir = testRoot.childDirectory('packages'); processRunner = RecordingProcessRunner(); @@ -35,6 +39,7 @@ void main() { packagesDir, processRunner: processRunner, pluginsRoot: testRoot, + platform: mockPlatform, ); runner = CommandRunner( 'create_all_test', 'Test for $CreateAllPluginsAppCommand'); @@ -107,6 +112,15 @@ void main() { }); test('macOS deployment target is modified in Podfile', () async { + final RepositoryPackage plugin = createFakePlugin('plugina', packagesDir); + final File podfileFile = + plugin.directory.childDirectory('macos').childFile('Podfile'); + podfileFile.createSync(recursive: true); + podfileFile.writeAsStringSync(""" +platform :osx, '10.11' +# some other line +"""); + await runCapturingPrint(runner, ['all-plugins-app']); final List podfile = command.app .platformDirectory(FlutterPlatform.macos) @@ -118,10 +132,21 @@ void main() { everyElement((String line) => !line.contains('platform :osx') || line.contains("'10.15'"))); }, - // Podfile is only generated on macOS. + // Podfile is only generated (and thus only edited) on macOS. skip: !io.Platform.isMacOS); test('macOS deployment target is modified in pbxproj', () async { + final RepositoryPackage plugin = createFakePlugin('plugina', packagesDir); + final File pbxprojFile = plugin.directory + .childDirectory('Runner.xcodeproj') + .childFile('project.pbxproj'); + pbxprojFile.createSync(recursive: true); + pbxprojFile.writeAsStringSync(''' + MACOSX_DEPLOYMENT_TARGET = 10.11; +/* some other line */ + MACOSX_DEPLOYMENT_TARGET = 10.11; +'''); + await runCapturingPrint(runner, ['all-plugins-app']); final List pbxproj = command.app .platformDirectory(FlutterPlatform.macos) @@ -136,6 +161,42 @@ void main() { line.contains('10.15'))); }); + test('calls flutter pub get', () async { + createFakePlugin('plugina', packagesDir); + + await runCapturingPrint(runner, ['all-plugins-app']); + + expect( + processRunner.recordedCalls, + orderedEquals([ + ProcessCall( + getFlutterCommand(mockPlatform), + const ['pub', 'get'], + testRoot.childDirectory('all_plugins').path), + ])); + }); + + test('fails if flutter pub get fails', () async { + createFakePlugin('plugina', packagesDir); + + processRunner + .mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = + [MockProcess(exitCode: 1)]; + Error? commandError; + final List output = await runCapturingPrint( + runner, ['all-plugins-app'], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains( + "Failed to generate native build files via 'flutter pub get'"), + ])); + }); + test('handles --output-dir', () async { createFakePlugin('plugina', packagesDir); From aef364d7a74fc64e5fdef50d21450a467ffceadb Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 27 Oct 2022 09:44:06 -0400 Subject: [PATCH 07/10] Revert mock process to fix Windows unit tests --- .../test/create_all_plugins_app_command_test.dart | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index 0868dadd9492..5f93ba5e23af 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -20,7 +20,6 @@ void main() { late CommandRunner runner; late CreateAllPluginsAppCommand command; late FileSystem fileSystem; - late MockPlatform mockPlatform; late Directory testRoot; late Directory packagesDir; late RecordingProcessRunner processRunner; @@ -30,7 +29,6 @@ void main() { // has to use the real filesystem. Put everything possible in a unique // temporary to minimize effect on the host system. fileSystem = const LocalFileSystem(); - mockPlatform = MockPlatform(); testRoot = fileSystem.systemTempDirectory.createTempSync(); packagesDir = testRoot.childDirectory('packages'); processRunner = RecordingProcessRunner(); @@ -39,7 +37,6 @@ void main() { packagesDir, processRunner: processRunner, pluginsRoot: testRoot, - platform: mockPlatform, ); runner = CommandRunner( 'create_all_test', 'Test for $CreateAllPluginsAppCommand'); @@ -170,7 +167,7 @@ platform :osx, '10.11' processRunner.recordedCalls, orderedEquals([ ProcessCall( - getFlutterCommand(mockPlatform), + getFlutterCommand(const LocalPlatform()), const ['pub', 'get'], testRoot.childDirectory('all_plugins').path), ])); @@ -179,9 +176,10 @@ platform :osx, '10.11' test('fails if flutter pub get fails', () async { createFakePlugin('plugina', packagesDir); - processRunner - .mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = - [MockProcess(exitCode: 1)]; + processRunner.mockProcessesForExecutable[ + getFlutterCommand(const LocalPlatform())] = [ + MockProcess(exitCode: 1) + ]; Error? commandError; final List output = await runCapturingPrint( runner, ['all-plugins-app'], errorHandler: (Error e) { From 08738436816828dde2993d5933b8aabed0def660 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 27 Oct 2022 10:42:29 -0400 Subject: [PATCH 08/10] Skip pub get on Windows --- .../src/create_all_plugins_app_command.dart | 29 +++++++++++-------- .../create_all_plugins_app_command_test.dart | 8 +++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index e042fcf866a8..95c66057efa9 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -71,18 +71,26 @@ class CreateAllPluginsAppCommand extends PackageCommand { await _genPubspecWithAllPlugins(); - /// Run `flutter pub get` to generate all native build files. - final bool didGenNativeBuildFilesSucceed = await _genNativeBuildFiles(); - if (!didGenNativeBuildFilesSucceed) { - printError("Failed to generate native build files via 'flutter pub get'"); - throw ToolExit(_exitGenNativeBuildFilesFailed); + // Run `flutter pub get` to generate all native build files. + // TODO(stuartmorgan): This hangs on Windows for some reason. Since it's + // currently not needed on Windows, skip it there, but we should investigate + // further and/or implement https://github.com/flutter/flutter/issues/93407, + // and remove the need for this conditional. + if (!platform.isWindows) { + if (!await _genNativeBuildFiles()) { + printError( + "Failed to generate native build files via 'flutter pub get'"); + throw ToolExit(_exitGenNativeBuildFilesFailed); + } } await Future.wait(>[ _updateAppGradle(), _updateManifest(), - _updateMacosPodfile(), _updateMacosPbxproj(), + // This step requires the native file generation triggered by + // flutter pub get above, so can't currently be run on Windows. + if (!platform.isWindows) _updateMacosPodfile(), ]); } @@ -197,7 +205,7 @@ class CreateAllPluginsAppCommand extends PackageCommand { }, dependencyOverrides: pluginDeps, ); - app.pubspecFile.writeAsStringSync(_pubspecToString(pubspec)); + app.pubspecFile.writeAsStringSync(_pubspecToString(pubspec), flush: true); } Future> _getValidPathDependencies() async { @@ -281,10 +289,7 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} Future _genNativeBuildFiles() async { final int exitCode = await processRunner.runAndStream( flutterCommand, - [ - 'pub', - 'get', - ], + ['pub', 'get'], workingDir: _appDirectory, ); return exitCode == 0; @@ -293,7 +298,7 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} Future _updateMacosPodfile() async { /// Only change the macOS deployment target if the host platform is macOS. /// The Podfile is not generated on other platforms. - if (!io.Platform.isMacOS) { + if (!platform.isMacOS) { return; } diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index 5f93ba5e23af..71eebfad34f7 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -171,7 +171,9 @@ platform :osx, '10.11' const ['pub', 'get'], testRoot.childDirectory('all_plugins').path), ])); - }); + }, + // See comment about Windows in create_all_plugins_app_command.dart + skip: io.Platform.isWindows); test('fails if flutter pub get fails', () async { createFakePlugin('plugina', packagesDir); @@ -193,7 +195,9 @@ platform :osx, '10.11' contains( "Failed to generate native build files via 'flutter pub get'"), ])); - }); + }, + // See comment about Windows in create_all_plugins_app_command.dart + skip: io.Platform.isWindows); test('handles --output-dir', () async { createFakePlugin('plugina', packagesDir); From c95ea9f285677ed9f699e5c3f689fc5589a5309b Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Thu, 27 Oct 2022 18:55:32 +0200 Subject: [PATCH 09/10] Fixed usage of macOS mock files. Podfile is now generated in the correct location. project.pbxproj uses the real file generated by `flutter create`. --- .../create_all_plugins_app_command_test.dart | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index 71eebfad34f7..cb2347fe9cc8 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -109,9 +109,12 @@ void main() { }); test('macOS deployment target is modified in Podfile', () async { - final RepositoryPackage plugin = createFakePlugin('plugina', packagesDir); - final File podfileFile = - plugin.directory.childDirectory('macos').childFile('Podfile'); + createFakePlugin('plugina', packagesDir); + + final File podfileFile = command.packagesDir.parent + .childDirectory('all_plugins') + .childDirectory('macos') + .childFile('Podfile'); podfileFile.createSync(recursive: true); podfileFile.writeAsStringSync(""" platform :osx, '10.11' @@ -133,16 +136,7 @@ platform :osx, '10.11' skip: !io.Platform.isMacOS); test('macOS deployment target is modified in pbxproj', () async { - final RepositoryPackage plugin = createFakePlugin('plugina', packagesDir); - final File pbxprojFile = plugin.directory - .childDirectory('Runner.xcodeproj') - .childFile('project.pbxproj'); - pbxprojFile.createSync(recursive: true); - pbxprojFile.writeAsStringSync(''' - MACOSX_DEPLOYMENT_TARGET = 10.11; -/* some other line */ - MACOSX_DEPLOYMENT_TARGET = 10.11; -'''); + createFakePlugin('plugina', packagesDir); await runCapturingPrint(runner, ['all-plugins-app']); final List pbxproj = command.app From 76c215277374f03e1a9010022d03b9e85fd56c44 Mon Sep 17 00:00:00 2001 From: Julius Bredemeyer <48645716+IVLIVS-III@users.noreply.github.com> Date: Thu, 27 Oct 2022 22:37:01 +0200 Subject: [PATCH 10/10] Revert unnecessary force-flush. --- script/tool/lib/src/create_all_plugins_app_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/tool/lib/src/create_all_plugins_app_command.dart b/script/tool/lib/src/create_all_plugins_app_command.dart index 95c66057efa9..ea7d5a5c4388 100644 --- a/script/tool/lib/src/create_all_plugins_app_command.dart +++ b/script/tool/lib/src/create_all_plugins_app_command.dart @@ -205,7 +205,7 @@ class CreateAllPluginsAppCommand extends PackageCommand { }, dependencyOverrides: pluginDeps, ); - app.pubspecFile.writeAsStringSync(_pubspecToString(pubspec), flush: true); + app.pubspecFile.writeAsStringSync(_pubspecToString(pubspec)); } Future> _getValidPathDependencies() async {