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

[tool] Update tool to set macOS deployment target to 10.15. #6605

Merged
merged 11 commits into from
Oct 28, 2022

Conversation

IVLIVS-III
Copy link
Contributor

@IVLIVS-III IVLIVS-III commented Oct 23, 2022

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@IVLIVS-III
Copy link
Contributor Author

As mentioned here by @stuartmorgan, it looks like this PR needs some additional tests.

It needs some review, and also its own test changes

However, I do not know where to start adding such tests and what exactly such additional tests should cover.

@IVLIVS-III IVLIVS-III marked this pull request as ready for review October 23, 2022 15:01
@flutter-dashboard
Copy link

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);

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link

@a-wallen a-wallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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) {
Copy link
Contributor

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);
Copy link
Contributor

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.
Copy link
Contributor

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.

@a-wallen a-wallen requested a review from cyanglaz October 24, 2022 16:56
@IVLIVS-III IVLIVS-III force-pushed the iap_macos/tool-change branch from 419bea0 to b8573eb Compare October 26, 2022 15:40
@IVLIVS-III
Copy link
Contributor Author

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.

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Oct 26, 2022

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 Podfile wasn't. The rest of it should be fine.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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);
Copy link
Contributor

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.
Copy link
Contributor

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 {
Copy link
Contributor

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@IVLIVS-III IVLIVS-III force-pushed the iap_macos/tool-change branch from f050c8c to 8e06f2c Compare October 26, 2022 20:00
@IVLIVS-III
Copy link
Contributor Author

Ohh right, I think I found where the existing tests break:

Fake plugins (e.g. plugina) are generated to test e.g. the exclusion flag. It seems like those fake plugins are not generated with all files included, that are expected by pub get. But pub get is now invoked earlier (i.e. within the all-plugins-app command and not afterwards).

Is it really necessary to edit the code generating fake plugins or is there an easier change that I didn't think of?

@stuartmorgan-g
Copy link
Contributor

Ah right, I didn't think about that aspect.

I think the best approach would be:

@IVLIVS-III IVLIVS-III force-pushed the iap_macos/tool-change branch from 8e06f2c to 45ea1cf Compare October 26, 2022 22:23
@IVLIVS-III
Copy link
Contributor Author

Tests are still failing on Windows, but I'm not sure what causes these failures.
Also, my host platform is macOS, so I'm unable to personally (locally) test on Windows.

@stuartmorgan-g
Copy link
Contributor

It's the introduction of the MockProcess, which breaks things because we're actually calling flutter create in the tests. The way we test this command is problematic; I filed flutter/flutter#114153 to track improving it.

I'll push a fix here shortly to fix the Windows tests.

@stuartmorgan-g
Copy link
Contributor

The other Windows failures are because pub get is hanging. I can reproduce this locally, but I'm still trying to figure out why (it works fine when run in the same directory outside of the context of the script.)

@stuartmorgan-g
Copy link
Contributor

I spent a while looking at this, and I have no idea what's going on. It hangs inside pub get early in the command (almost nothing is printed in verbose mode), it doesn't seem to be a race with some earlier step not having fully finished (adding a long delay just before it doesn't help), but if I comment it out, run the script, then run the same command manually in the directory, everything is fine.

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');
Copy link
Contributor

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.

Copy link
Contributor Author

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`.
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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);
Copy link
Contributor

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.

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stuartmorgan-g stuartmorgan-g added autosubmit Merge PR when tree becomes green via auto submit App and removed needs tests labels Oct 28, 2022
@auto-submit auto-submit bot merged commit 6f91122 into flutter:main Oct 28, 2022
adam-harwood pushed a commit to adam-harwood/flutter_plugins that referenced this pull request Nov 3, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[tool] Update tool to set macOS deployment target to 10.15.
4 participants