Skip to content

[flutter_tools] General info project validator #103653

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

Merged

Conversation

Jasguerrero
Copy link
Contributor

@Jasguerrero Jasguerrero commented May 12, 2022

#2885

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 [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • 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.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label May 12, 2022
@Jasguerrero Jasguerrero added tool Affects the "flutter" command-line tool. See also t: labels. and removed tool Affects the "flutter" command-line tool. See also t: labels. labels May 12, 2022
];
}

class GeneralInfoProjectValidator extends ProjectValidator{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a dartdoc?

Copy link
Contributor

Choose a reason for hiding this comment

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

These actually need to be /// for them to be parsed by the dartdoc tool: https://dart.dev/guides/language/effective-dart/documentation#do-use--doc-comments-to-document-members-and-types

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this should be of the format: single line summary sentence, followed by empty line, then remainder: https://dart.dev/guides/language/effective-dart/documentation#do-separate-the-first-sentence-of-a-doc-comment-into-its-own-paragraph

class GeneralInfoProjectValidator extends ProjectValidator{
@override
Future<List<ProjectValidatorResult>> start(FlutterProject project) async {
final YamlMap pubContent = loadYaml(project.pubspecFile.readAsStringSync()) as YamlMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not have elsewhere in the codebase where we parse a project's pubspec? If not, I would recommend pulling this out into its own file. Parsing Yaml is tricky and error prone, we should ideally have a single source code file that knows about the structure of pubspec.yaml and does all the type checking once.

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, it would be nice if this was a class, that exposed getters for all the fields that we need to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a general package for parsing pubspec but is missing stuff that I need like the flutter key. Agree on making this it's own class

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, also we should generally try not to add any more pub dependencies to this repo. We already have a lot of trouble pub solving.


String getSupportedPlatforms(FlutterProject project) {
final List<SupportedPlatform> supportedPlatforms = project.getSupportedPlatforms();
final List<String> allPlatforms = <String>[];
Copy link
Contributor

@christopherfujino christopherfujino May 12, 2022

Choose a reason for hiding this comment

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

This can be:

Suggested change
final List<String> allPlatforms = <String>[];
final List<String> allPlatforms = project.getSupportedPlatforms().map((SupportedPlatform platform) => platform.name);

return content['flutter'] as YamlMap;
}

bool isFlutterPackage() {
Copy link
Contributor

@christopherfujino christopherfujino May 13, 2022

Choose a reason for hiding this comment

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

style nit: this can be a getter, since it doesn't accept any parameters. All call-sites will need to be updated to omit the empty parentheses.

Suggested change
bool isFlutterPackage() {
bool get isFlutterPackage {

return flutterNode != null;
}

bool usesMaterialDesign() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool usesMaterialDesign() {
bool get usesMaterialDesign {

return flutterNode['uses-material-design'] as bool;
}

bool isPlugin() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool isPlugin() {
bool get isPlugin {

import 'package:yaml/yaml.dart';

class PubContent {
PubContent(this.content);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, this constructor can be const. for the real tool, we probably won't be able to make any instances const (since we will be reading the content from disk), but maybe in tests?

Suggested change
PubContent(this.content);
const PubContent(this.content);


import 'package:yaml/yaml.dart';

class PubContent {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. let's call this PubspecContent, since pub is the name of the tool. Also, can you name this file pubspec_content.dart?

Suggested change
class PubContent {
class PubspecContent {

@christopherfujino
Copy link
Contributor

christopherfujino commented May 13, 2022

Started reviewing this, but then I found https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/flutter_manifest.dart. Let's whether it's worth de-duping logic next week

@Jasguerrero
Copy link
Contributor Author

Started reviewing this, but then I found https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/flutter_manifest.dart. Let's whether it's worth de-duping logic next week

I think I can use this class but I still believe I should make wrappers for its methods inside my current PubContent class. My thinking is as the dart doc for FlutterManifest states /// A wrapper around the flutter section in the pubspec.yaml file. Having said that FlutterManifest also access attributes of the pubspec.yaml that are outside of the flutter section eg: the app name (which conveniently I also need). So thinking ahead, in case this (or any other future project validator) needs info that the current FlutterManifest does not have and is outside of the flutter section that should be added to my PubContent instead of FlutterManifest. @christopherfujino

@christopherfujino
Copy link
Contributor

Started reviewing this, but then I found https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/flutter_manifest.dart. Let's whether it's worth de-duping logic next week

I think I can use this class but I still believe I should make wrappers for its methods inside my current PubContent class. My thinking is as the dart doc for FlutterManifest states /// A wrapper around the flutter section in the pubspec.yaml file. Having said that FlutterManifest also access attributes of the pubspec.yaml that are outside of the flutter section eg: the app name (which conveniently I also need). So thinking ahead, in case this (or any other future project validator) needs info that the current FlutterManifest does not have and is outside of the flutter section that should be added to my PubContent instead of FlutterManifest. @christopherfujino

We could update the dartdoc text, right :) ? I'm not saying I'm sure adding new features to the FlutterManifest for this use case is the right thing to do, but why shouldn't we?

@Jasguerrero
Copy link
Contributor Author

We could update the dartdoc text, right :) ? I'm not saying I'm sure adding new features to the FlutterManifest for this use case is the right thing to do, but why shouldn't we?

Not really an specific reason not to do it just didn't want to add stuff that wasn't meant to be on that class but if we good on changing that dartdoc and add more things as need I can use this class directly for everything related to the pubspec.yml @christopherfujino

@christopherfujino
Copy link
Contributor

christopherfujino commented May 16, 2022

We could update the dartdoc text, right :) ? I'm not saying I'm sure adding new features to the FlutterManifest for this use case is the right thing to do, but why shouldn't we?

Not really an specific reason not to do it just didn't want to add stuff that wasn't meant to be on that class but if we good on changing that dartdoc and add more things as need I can use this class directly for everything related to the pubspec.yml @christopherfujino

It's unfortunate the class is named FlutterManifest, but other than that I don't see any reason not to extend (by extend I mean add new fields to the existing one) that class. The other thing to look out for is that we don't want to significantly slow down the other code paths that use this class--however, from a cursory look it looks like the existing fields lazily load from the pubspec (rather than crawling the entire Yaml file and parsing it at startup) so I don't think this should be a problem.

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

Some nits, otherwise LGTM

];
}

/// Validator run for all platforms that extract information from the pubspec.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Validator run for all platforms that extract information from the pubspec.yaml
/// Validator run for all platforms that extract information from the pubspec.yaml.


/// Validator run for all platforms that extract information from the pubspec.yaml
///
/// Specific info from different platforms should be written in their own ProjectValidator
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Specific info from different platforms should be written in their own ProjectValidator
/// Specific info from different platforms should be written in their own ProjectValidator.

class GeneralInfoProjectValidator extends ProjectValidator{
@override
Future<List<ProjectValidatorResult>> start(FlutterProject project, {required Logger logger, required FileSystem fileSystem}) async {
final FlutterManifest? flutterManifest = FlutterManifest.createFromPath(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the project already has a getter for a FlutterManifest https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/project.dart#L126.

If so, I think this method wouldn't need to take a FileSystem or a Logger

final ProjectValidatorResult appNameValidatorResult = getAppNameResult(flutterManifest);
final String supportedPlatforms = getSupportedPlatforms(project);
if (supportedPlatforms.isEmpty) {
return <ProjectValidatorResult>[appNameValidatorResult];
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than returning a list literal, can you create an empty list at the start of this function, adding to it as you go, and if we need to return early, return that reference. This will be more resilient in the future when we add more validators, we won't have to update all subsequent list literals.

}

ProjectValidatorResult isFlutterPackageValidatorResult(FlutterManifest flutterManifest) {
String value;
Copy link
Contributor

Choose a reason for hiding this comment

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

These two can be final

);
}

ProjectValidatorResult isFlutterPackageValidatorResult(FlutterManifest flutterManifest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please mark @visibleForTesting if used from tests, otherwise private.

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Cirrus statuses were expected has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Cirrus statuses were expected has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Cirrus statuses were expected has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Mac build_ios_framework_module_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac build_tests_1_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac build_tests_2_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac build_tests_3_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac build_tests_4_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac customer_testing has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac dart_plugin_registry_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac framework_tests_libraries has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac framework_tests_misc has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac framework_tests_widgets has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac module_custom_host_app_name_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac module_host_with_custom_build_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac module_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac module_test_ios has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac plugin_dependencies_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac plugin_lint_mac has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac plugin_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac plugin_test_ios has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_host_cross_arch_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_integration_tests_1_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_integration_tests_2_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_integration_tests_3_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_integration_tests_4_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_tests_commands has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_tests_general has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac web_tool_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac native_ui_tests_macos has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac run_release_test_macos has failed. Please fix the issues identified (or deflake) before re-applying this label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants