@@ -6,22 +6,30 @@ import 'dart:io' as io;
66
77import 'package:file/file.dart' ;
88import 'package:path/path.dart' as p;
9+ import 'package:platform/platform.dart' ;
910import 'package:pub_semver/pub_semver.dart' ;
1011import 'package:pubspec_parse/pubspec_parse.dart' ;
1112
1213import 'common/core.dart' ;
1314import 'common/package_command.dart' ;
15+ import 'common/process_runner.dart' ;
1416import 'common/repository_package.dart' ;
1517
1618const String _outputDirectoryFlag = 'output-dir' ;
1719
20+ const int _exitUpdateMacosPodfileFailed = 3 ;
21+ const int _exitUpdateMacosPbxprojFailed = 4 ;
22+ const int _exitGenNativeBuildFilesFailed = 5 ;
23+
1824/// A command to create an application that builds all in a single application.
1925class CreateAllPluginsAppCommand extends PackageCommand {
2026 /// Creates an instance of the builder command.
2127 CreateAllPluginsAppCommand (
2228 Directory packagesDir, {
29+ ProcessRunner processRunner = const ProcessRunner (),
2330 Directory ? pluginsRoot,
24- }) : super (packagesDir) {
31+ Platform platform = const LocalPlatform (),
32+ }) : super (packagesDir, processRunner: processRunner, platform: platform) {
2533 final Directory defaultDir =
2634 pluginsRoot ?? packagesDir.fileSystem.currentDirectory;
2735 argParser.addOption (_outputDirectoryFlag,
@@ -61,10 +69,28 @@ class CreateAllPluginsAppCommand extends PackageCommand {
6169 print ('' );
6270 }
6371
72+ await _genPubspecWithAllPlugins ();
73+
74+ // Run `flutter pub get` to generate all native build files.
75+ // TODO(stuartmorgan): This hangs on Windows for some reason. Since it's
76+ // currently not needed on Windows, skip it there, but we should investigate
77+ // further and/or implement https://github.com/flutter/flutter/issues/93407,
78+ // and remove the need for this conditional.
79+ if (! platform.isWindows) {
80+ if (! await _genNativeBuildFiles ()) {
81+ printError (
82+ "Failed to generate native build files via 'flutter pub get'" );
83+ throw ToolExit (_exitGenNativeBuildFilesFailed);
84+ }
85+ }
86+
6487 await Future .wait (< Future <void >> [
65- _genPubspecWithAllPlugins (),
6688 _updateAppGradle (),
6789 _updateManifest (),
90+ _updateMacosPbxproj (),
91+ // This step requires the native file generation triggered by
92+ // flutter pub get above, so can't currently be run on Windows.
93+ if (! platform.isWindows) _updateMacosPodfile (),
6894 ]);
6995 }
7096
@@ -259,4 +285,61 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
259285
260286 return buffer.toString ();
261287 }
288+
289+ Future <bool > _genNativeBuildFiles () async {
290+ final int exitCode = await processRunner.runAndStream (
291+ flutterCommand,
292+ < String > ['pub' , 'get' ],
293+ workingDir: _appDirectory,
294+ );
295+ return exitCode == 0 ;
296+ }
297+
298+ Future <void > _updateMacosPodfile () async {
299+ /// Only change the macOS deployment target if the host platform is macOS.
300+ /// The Podfile is not generated on other platforms.
301+ if (! platform.isMacOS) {
302+ return ;
303+ }
304+
305+ final File podfileFile =
306+ app.platformDirectory (FlutterPlatform .macos).childFile ('Podfile' );
307+ if (! podfileFile.existsSync ()) {
308+ printError ("Can't find Podfile for macOS" );
309+ throw ToolExit (_exitUpdateMacosPodfileFailed);
310+ }
311+
312+ final StringBuffer newPodfile = StringBuffer ();
313+ for (final String line in podfileFile.readAsLinesSync ()) {
314+ if (line.contains ('platform :osx' )) {
315+ // macOS 10.15 is required by in_app_purchase.
316+ newPodfile.writeln ("platform :osx, '10.15'" );
317+ } else {
318+ newPodfile.writeln (line);
319+ }
320+ }
321+ podfileFile.writeAsStringSync (newPodfile.toString ());
322+ }
323+
324+ Future <void > _updateMacosPbxproj () async {
325+ final File pbxprojFile = app
326+ .platformDirectory (FlutterPlatform .macos)
327+ .childDirectory ('Runner.xcodeproj' )
328+ .childFile ('project.pbxproj' );
329+ if (! pbxprojFile.existsSync ()) {
330+ printError ("Can't find project.pbxproj for macOS" );
331+ throw ToolExit (_exitUpdateMacosPbxprojFailed);
332+ }
333+
334+ final StringBuffer newPbxproj = StringBuffer ();
335+ for (final String line in pbxprojFile.readAsLinesSync ()) {
336+ if (line.contains ('MACOSX_DEPLOYMENT_TARGET' )) {
337+ // macOS 10.15 is required by in_app_purchase.
338+ newPbxproj.writeln (' MACOSX_DEPLOYMENT_TARGET = 10.15;' );
339+ } else {
340+ newPbxproj.writeln (line);
341+ }
342+ }
343+ pbxprojFile.writeAsStringSync (newPbxproj.toString ());
344+ }
262345}
0 commit comments