@@ -6,22 +6,30 @@ import 'dart:io' as io;
6
6
7
7
import 'package:file/file.dart' ;
8
8
import 'package:path/path.dart' as p;
9
+ import 'package:platform/platform.dart' ;
9
10
import 'package:pub_semver/pub_semver.dart' ;
10
11
import 'package:pubspec_parse/pubspec_parse.dart' ;
11
12
12
13
import 'common/core.dart' ;
13
14
import 'common/package_command.dart' ;
15
+ import 'common/process_runner.dart' ;
14
16
import 'common/repository_package.dart' ;
15
17
16
18
const String _outputDirectoryFlag = 'output-dir' ;
17
19
20
+ const int _exitUpdateMacosPodfileFailed = 3 ;
21
+ const int _exitUpdateMacosPbxprojFailed = 4 ;
22
+ const int _exitGenNativeBuildFilesFailed = 5 ;
23
+
18
24
/// A command to create an application that builds all in a single application.
19
25
class CreateAllPluginsAppCommand extends PackageCommand {
20
26
/// Creates an instance of the builder command.
21
27
CreateAllPluginsAppCommand (
22
28
Directory packagesDir, {
29
+ ProcessRunner processRunner = const ProcessRunner (),
23
30
Directory ? pluginsRoot,
24
- }) : super (packagesDir) {
31
+ Platform platform = const LocalPlatform (),
32
+ }) : super (packagesDir, processRunner: processRunner, platform: platform) {
25
33
final Directory defaultDir =
26
34
pluginsRoot ?? packagesDir.fileSystem.currentDirectory;
27
35
argParser.addOption (_outputDirectoryFlag,
@@ -61,10 +69,28 @@ class CreateAllPluginsAppCommand extends PackageCommand {
61
69
print ('' );
62
70
}
63
71
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
+
64
87
await Future .wait (< Future <void >> [
65
- _genPubspecWithAllPlugins (),
66
88
_updateAppGradle (),
67
89
_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 (),
68
94
]);
69
95
}
70
96
@@ -259,4 +285,61 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
259
285
260
286
return buffer.toString ();
261
287
}
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
+ }
262
345
}
0 commit comments