Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_migrate] Reland apply, abandon, and status commands and add environment.dart #2723

Merged
merged 17 commits into from
Nov 7, 2022

Conversation

GaryQian
Copy link
Contributor

@GaryQian GaryQian commented Oct 20, 2022

Re-lands the already-reviewed and landed subcommands apply abandon and status

Adds environment.dart which queries the flutter_tools for details about the environment and other tools properties

Previously landed PRs: flutter/flutter#102785, flutter/flutter#102787, flutter/flutter#102789

@GaryQian GaryQian marked this pull request as ready for review October 21, 2022 16:59
@GaryQian GaryQian changed the title [flutter_migrate] Reland apply, abandon, and status commands [flutter_migrate] Reland apply, abandon, and status commands and add environment.dart Oct 21, 2022
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

I only actually reviewed environment* since the others were existing code from the other repo; let me know if you want a full review of the other files.

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8
Copy link
Contributor

Choose a reason for hiding this comment

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

We should definitely not be landing new non-NNBD code; see flutter/flutter#110016

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, ill change this to be null safe, this package no longer has the overhead of being part of a non-null-safe test suite!

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

packages/flutter_migrate/lib/src/utils.dart Show resolved Hide resolved
}
String commandOutput = result.stdout;
Map<String, Object?> mapping = <String, Object?>{};
if (commandOutput.contains('{') && commandOutput.endsWith('}\n')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the end check so specific here? It seems like it would be a lot less fragile to minor whitespace changes to either use a regex, or to trim() the output and check for } at the end.

if (_mapping.containsKey(key) &&
_mapping[key] != null &&
_mapping[key] is String) {
return _mapping[key]! as String;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the null check and force-unwrap when the return type is nullable? It seems like this whole function could just be:

Object? value = _mapping[key];
return value is String? ? value as String? : null;

if (_mapping.containsKey(key) &&
_mapping[key] != null &&
_mapping[key] is bool) {
return _mapping[key]! as bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

expect(env.getString('invalid key') == null, true);
expect(env.getBool('invalid key') == null, true);

expect(env.getString('FlutterProject.directory') != null, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see dummy process output setup here; is unit test actually calling Flutter?

Thats seems problematic, since it means this test could break at any time if Flutter changes anything. I would expect unit tests to run against mocked process 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.

Good catch, ill mock the flutter dependency part of this to prevent this potential breakage.

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

Just a couple of nits from me. Does this ready for another pass from @stuartmorgan ?

///
/// Each key is the String URI-style description of a value in the Flutter tool
/// and is mapped to a String or boolean value. The mapping should align with the
/// JSON output of `flutter analuze --suggestions --machine`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// JSON output of `flutter analuze --suggestions --machine`.
/// JSON output of `flutter analyze --suggestions --machine`.

processManager = const LocalProcessManager();
});

setUpAll(() {});
Copy link
Member

Choose a reason for hiding this comment

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

Can you delete this?

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM!

@GaryQian GaryQian added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 7, 2022
@auto-submit auto-submit bot merged commit 94014cb into flutter:main Nov 7, 2022
percula pushed a commit to percula/packages that referenced this pull request Nov 17, 2022
…environment.dart (flutter#2723)

* Checkout commands files

* fix licences and tests

* Skip apply test on old flutter version

* Formatting

* Fix version booleans

* Move flutter version test tcheck first

* Working tests

* Formatting

* Env test

* Docs and fix windows test

* Null safe, extra test

* Improve cleanliness checking

* Regex and fake process manager

* Formatting

* Change env test contents

* format

* Nits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: flutter_migrate
Projects
None yet
3 participants