-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[tool] Update tool to set macOS deployment target to 10.15. #6605
Conversation
As mentioned here by @stuartmorgan, it looks like this PR needs some additional tests.
However, I do not know where to start adding such tests and what exactly such additional tests should cover. |
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
final File podfileFile = | ||
app.platformDirectory(FlutterPlatform.macos).childFile('Podfile'); | ||
if (!podfileFile.existsSync()) { | ||
throw ToolExit(64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why 64
is the ToolExit code. Could that be documented here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially it was suggested to me, to look at the implementation of _updateAppGradle
to see how changes to project configuration files could be made (see this comment).
This would be done in
script/tool/lib/src/create_all_plugins_app_command.dart
. See_updateAppGradle
for an example of making a similar change to some Android values.
There, this (to me arbitrary) exit code 64
was thrown in case the relevant android config file didn't exist.
I don't know the meaning of this value either. Looking back at git history, the value was introduced two years ago in #3544.
The value itself seems to date back even further tho, since the PR mentioned above only moved some files around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does look it was arbitrary. The way we're handling error codes for any current code is to define file-level constants starting with 3 (since 1 and 2 are global errors) for each failure, and using those, so that it's self-documenting. Let's do that here; it's fine that it's inconsistent with the older code in the file since those values aren't meaningful anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks great other than some minor nits. This will need a unit test though; it should be straightforward following the pattern of the existing tests for this file: run the command, then read the files that are expected to be modified and make sure they match expectations (e.g., that every line in the project file that contains MACOS_DEPLOYMENT_TARGET
also contains 10.15
).
Future<int> _genNativeBuildFiles() async { | ||
// Only run on macOS. | ||
// Other platforms don't need generation of additional files. | ||
if (!io.Platform.isMacOS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need this for other platforms in the future, and pub get
will be part of building the app anyway, so we can just do this unconditionally and keep the codepaths the same on all platforms.
final File podfileFile = | ||
app.platformDirectory(FlutterPlatform.macos).childFile('Podfile'); | ||
if (!podfileFile.existsSync()) { | ||
throw ToolExit(64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does look it was arbitrary. The way we're handling error codes for any current code is to define file-level constants starting with 3 (since 1 and 2 are global errors) for each failure, and using those, so that it's self-documenting. Let's do that here; it's fine that it's inconsistent with the older code in the file since those values aren't meaningful anyway.
} | ||
|
||
Future<void> _updateMacosPbxproj() async { | ||
// Only change the macOS deployment target if the host platform is macOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same; this can be unconditional.
419bea0
to
b8573eb
Compare
From all the failing tests, it looks like we need the host platform guards after all, since the macOS configuration files are not found / generated on any platform except for macOS. |
Sorry about that; most of the Flutter tool's platform build file generation is unconditional, and I didn't realize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed a few details in the implementation review.
On the test side, it looks like your changes broke the Dart unit tests for this command.
/// Run `flutter pub get` to generate all native build files for macOS. | ||
final int genNativeBuildFilesExitCode = await _genNativeBuildFiles(); | ||
if (genNativeBuildFilesExitCode != 0) { | ||
throw ToolExit(genNativeBuildFilesExitCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should instead printError
a message (e.g., "Failed to generate native build files"), then throw a new defined error like the ones you added above. We don't actually need the underlying exit code.
@@ -61,10 +64,19 @@ class CreateAllPluginsAppCommand extends PackageCommand { | |||
print(''); | |||
} | |||
|
|||
await _genPubspecWithAllPlugins(); | |||
|
|||
/// Run `flutter pub get` to generate all native build files for macOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Remove the "for macOS" here since it's all platform (even if we only happen to be using it for macOS right now).
@@ -259,4 +271,64 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} | |||
|
|||
return buffer.toString(); | |||
} | |||
|
|||
Future<int> _genNativeBuildFiles() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a boolean.
@@ -259,4 +271,64 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)} | |||
|
|||
return buffer.toString(); | |||
} | |||
|
|||
Future<int> _genNativeBuildFiles() async { | |||
final io.ProcessResult result = io.Process.runSync( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this method by using processRunner.runAndStream
, which will automatically print all of the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh neat, didn't know this existed.
f050c8c
to
8e06f2c
Compare
Ohh right, I think I found where the existing tests break: Fake plugins (e.g. Is it really necessary to edit the code generating fake plugins or is there an easier change that I didn't think of? |
Ah right, I didn't think about that aspect. I think the best approach would be:
|
This change is necessary for flutter#6517.
The Podfile is only generated on a macOS host.
Before throwing a `ToolExit`, a error message is printed.
8e06f2c
to
45ea1cf
Compare
Tests are still failing on Windows, but I'm not sure what causes these failures. |
It's the introduction of the I'll push a fix here shortly to fix the Windows tests. |
The other Windows failures are because |
I spent a while looking at this, and I have no idea what's going on. It hangs inside Since I don't have more time to investigate it right now, and I don't want to block the PR chain indefinitely on this, I re-added conditionals to bypass some steps on Windows after all, with TODOs to investigate further and unwind them so we don't have to maintain the conditional logic forever. |
test('macOS deployment target is modified in Podfile', () async { | ||
final RepositoryPackage plugin = createFakePlugin('plugina', packagesDir); | ||
final File podfileFile = | ||
plugin.directory.childDirectory('macos').childFile('Podfile'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is being created in the wrong directory; the podfile should be in the created app, not the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved creation of the mock Podfile to the app directory.
Podfile is now generated in the correct location. project.pbxproj uses the real file generated by `flutter create`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! @tarrinneal or @bparrishMines could you do the secondary review here since it's repo tooling?
@@ -179,7 +205,7 @@ class CreateAllPluginsAppCommand extends PackageCommand { | |||
}, | |||
dependencyOverrides: pluginDeps, | |||
); | |||
app.pubspecFile.writeAsStringSync(_pubspecToString(pubspec)); | |||
app.pubspecFile.writeAsStringSync(_pubspecToString(pubspec), flush: true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I didn't mean to push this; I was trying it locally when I was grasping at straws on the pub get
hang issue. You can revert this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change is a necessary precondition for #6517.
Adding support for macOS to
in_app_purchase
requires the macOS apps deployment target to be set to 10.15.This PR makes the necessary changes to the
all-plugins-app
command.Closes flutter/flutter#113913
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.