Thanks to visit codestin.com
Credit goes to github.com

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

[flutter_plugin_tool] Add support for building UWP plugins #4047

Merged
merged 20 commits into from
Aug 26, 2021

Conversation

stuartmorgan-g
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g commented Jun 11, 2021

This allows building UWP plugin examples with build-examples --winuwp. As with previous pre-stable-template desktop support, this avoids the issue of unstable app templates by running flutter create on the fly before trying to build, so a template that will bitrot doesn't need to be checked in.

Also adds no-op "support" for drive-examples --winuwp, with warnings about it not doing anything. This is to handle the fact that the LUCI recipe is shared between Win32 and UWP, and didn't conditionalize drive. Rather than change that, then change it back later, this just adds the no-op support now (since changing the tooling is much easier than changing LUCI recipes currently).

This required some supporting tool changes:

  • Adds the ability to check for the new platform variants in a pubspec
  • Adds the ability to write test pubspecs that include variants, for testing

Part of flutter/flutter#82817

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. (Note that 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.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

@stuartmorgan-g stuartmorgan-g requested a review from cbracken June 11, 2021 20:08
@google-cla google-cla bot added the cla: yes label Jun 11, 2021
@stuartmorgan-g
Copy link
Contributor Author

Sorry this turned into a yak-shave; once I was changing that test utility method it was very hard to stop...

@stuartmorgan-g
Copy link
Contributor Author

Hold off on reviewing; I re-implemented most of the yak as a prequel PR.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft June 17, 2021 16:07
@stuartmorgan-g stuartmorgan-g marked this pull request as ready for review June 21, 2021 20:36
@stuartmorgan-g
Copy link
Contributor Author

Now with 100% less yak.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

lgtm modulo a few nits.

// needs to be created on the fly with 'flutter create .'
Directory? temporaryPlatformDirectory;
if (flutterBuildType == 'winuwp') {
final Directory uwpFolder = example.childDirectory('winuwp');
Copy link
Member

Choose a reason for hiding this comment

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

pedantic nit: consider uwpDirectory for consistent naming with the APIs, unless folder is used consistently throughout the tool already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed (that's my macOS showing).

if (!uwpFolder.existsSync()) {
print('Creating temporary winuwp folder');
final int exitCode = await processRunner.runAndStream(
flutterCommand, <String>['create', '--platforms=winuwp', '.'],
Copy link
Member

Choose a reason for hiding this comment

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

Is this winuwp the same as the platformVariantWinUwp or kPlatformWinUwp const in core.dart? If so consider using a string interpolation here both to indicate the connection, and because it'll break this code if we ever removed that const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this winuwp the same as the platformVariantWinUwp or kPlatformWinUwp const in core.dart?

Hm. I guess it's probably the same as kPlatformWinUwp now that you mention it ("UWP is a platform for the purposes of flutter commands like build and run"); presumably the fact that build and create are using the same string in flutter isn't an accident.

The "platform" situation is kind of a disaster. I think the thing to do is to explore doing a follow-up PR that makes a tool-wide platform class that's based on the _PlatformDetails I had to define here, because it's a more general problem (as indicated by the constant names we have globally). That can have accessors for each different usage; mostly that will be the same thing in each case, but not always, and we can pass around that object internally everywhere instead of strings (and only convert to strings at the last minute when interfacing with things outside the tool).

FileSystemEntity entity, {
PlatformSupport? requiredMode,
String? variant,
}) {
assert(platform == kPlatformIos ||
Copy link
Member

Choose a reason for hiding this comment

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

Should this be updated to include kPlatformWinUwp or is that always passed as kPlatformWindows with the uwp variant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The latter; from the standpoint of a plugin, UWP isn't a platform.

(But see my other comment; I think I could avoid this kind of confusion with a generic platform class.)

Copy link
Member

Choose a reason for hiding this comment

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

Agreed; the backward compatibility makes this a bit of a pain. As you say, modelling this with classes might result in better readability than with logic in various bits of the tool. Agree that approach is worth exploring.

// The UWP template is not yet stable, so the UWP directory
// needs to be created on the fly with 'flutter create .'
Directory? temporaryPlatformDirectory;
if (flutterBuildType == 'winuwp') {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like these are currently literals for all the platforms; consider extracting them to build type consts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -656,6 +656,40 @@ void main() {
]));
});

test('driving UWP is a no-op', () async {
Copy link
Member

Choose a reason for hiding this comment

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

Might be useful to add a TODO here and elsewhere with a link to a bug.

@stuartmorgan-g
Copy link
Contributor Author

The red is a flaky test that I have a PR out for review to disable, so I'm going to land without wasting the resources of re-running it until it's green.

@stuartmorgan-g stuartmorgan-g merged commit a011b30 into flutter:master Aug 26, 2021
@stuartmorgan-g stuartmorgan-g deleted the uwp-build-example branch August 26, 2021 19:07
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 26, 2021
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
)

This allows building UWP plugin examples with `build-examples --winuwp`. As with previous pre-stable-template desktop support, this avoids the issue of unstable app templates by running `flutter create` on the fly before trying to build, so a template that will bitrot doesn't need to be checked in.

Also adds no-op "support" for `drive-examples --winuwp`, with warnings about it not doing anything. This is to handle the fact that the LUCI recipe is shared between Win32 and UWP, and didn't conditionalize `drive`. Rather than change that, then change it back later, this just adds the no-op support now (since changing the tooling is much easier than changing LUCI recipes currently).

This required some supporting tool changes:
- Adds the ability to check for the new platform variants in a pubspec
- Adds the ability to write test pubspecs that include variants, for testing

Part of flutter/flutter#82817
amantoux pushed a commit to amantoux/plugins that referenced this pull request Sep 27, 2021
)

This allows building UWP plugin examples with `build-examples --winuwp`. As with previous pre-stable-template desktop support, this avoids the issue of unstable app templates by running `flutter create` on the fly before trying to build, so a template that will bitrot doesn't need to be checked in.

Also adds no-op "support" for `drive-examples --winuwp`, with warnings about it not doing anything. This is to handle the fact that the LUCI recipe is shared between Win32 and UWP, and didn't conditionalize `drive`. Rather than change that, then change it back later, this just adds the no-op support now (since changing the tooling is much easier than changing LUCI recipes currently).

This required some supporting tool changes:
- Adds the ability to check for the new platform variants in a pubspec
- Adds the ability to write test pubspecs that include variants, for testing

Part of flutter/flutter#82817
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants