Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 419bea0

Browse files
committed
Update tool to set macOS deployment target to 10.15.
This change is necessary for #6517.
1 parent f55c7ff commit 419bea0

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

script/tool/lib/src/create_all_plugins_app_command.dart

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ class CreateAllPluginsAppCommand extends PackageCommand {
6161
print('');
6262
}
6363

64+
await _genPubspecWithAllPlugins();
65+
66+
/// Run `flutter pub get` to generate all native build files for macOS.
67+
final int genNativeBuildFilesExitCode = await _genNativeBuildFiles();
68+
if (genNativeBuildFilesExitCode != 0) {
69+
throw ToolExit(genNativeBuildFilesExitCode);
70+
}
71+
6472
await Future.wait(<Future<void>>[
65-
_genPubspecWithAllPlugins(),
6673
_updateAppGradle(),
6774
_updateManifest(),
75+
_updateMacosPodfile(),
76+
_updateMacosPbxproj(),
6877
]);
6978
}
7079

@@ -259,4 +268,75 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
259268

260269
return buffer.toString();
261270
}
271+
272+
Future<int> _genNativeBuildFiles() async {
273+
// Only run on macOS.
274+
// Other platforms don't need generation of additional files.
275+
if (!io.Platform.isMacOS) {
276+
return 0;
277+
}
278+
279+
final io.ProcessResult result = io.Process.runSync(
280+
flutterCommand,
281+
<String>[
282+
'pub',
283+
'get',
284+
],
285+
workingDirectory: _appDirectory.path,
286+
);
287+
288+
print(result.stdout);
289+
print(result.stderr);
290+
return result.exitCode;
291+
}
292+
293+
Future<void> _updateMacosPodfile() async {
294+
// Only change the macOS deployment target if the host platform is macOS.
295+
if (!io.Platform.isMacOS) {
296+
return;
297+
}
298+
299+
final File podfileFile =
300+
app.platformDirectory(FlutterPlatform.macos).childFile('Podfile');
301+
if (!podfileFile.existsSync()) {
302+
throw ToolExit(64);
303+
}
304+
305+
final StringBuffer newPodfile = StringBuffer();
306+
for (final String line in podfileFile.readAsLinesSync()) {
307+
if (line.contains('platform :osx')) {
308+
// macOS 10.15 is required by in_app_purchase.
309+
newPodfile.writeln("platform :osx, '10.15'");
310+
} else {
311+
newPodfile.writeln(line);
312+
}
313+
}
314+
podfileFile.writeAsStringSync(newPodfile.toString());
315+
}
316+
317+
Future<void> _updateMacosPbxproj() async {
318+
// Only change the macOS deployment target if the host platform is macOS.
319+
if (!io.Platform.isMacOS) {
320+
return;
321+
}
322+
323+
final File pbxprojFile = app
324+
.platformDirectory(FlutterPlatform.macos)
325+
.childDirectory('Runner.xcodeproj')
326+
.childFile('project.pbxproj');
327+
if (!pbxprojFile.existsSync()) {
328+
throw ToolExit(64);
329+
}
330+
331+
final StringBuffer newPbxproj = StringBuffer();
332+
for (final String line in pbxprojFile.readAsLinesSync()) {
333+
if (line.contains('MACOSX_DEPLOYMENT_TARGET')) {
334+
// macOS 10.15 is required by in_app_purchase.
335+
newPbxproj.writeln(' MACOSX_DEPLOYMENT_TARGET = 10.15;');
336+
} else {
337+
newPbxproj.writeln(line);
338+
}
339+
}
340+
pbxprojFile.writeAsStringSync(newPbxproj.toString());
341+
}
262342
}

0 commit comments

Comments
 (0)