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

[flutter_plugin_tools] Introduce a class for packages #4252

Merged
merged 3 commits into from Aug 24, 2021

Conversation

stuartmorgan
Copy link
Contributor

Packages are the primary conceptual object in the tool, but currently they are represented simply as Directory (or occasionally a path string). This introduces an object for packages and:

  • moves a number of existing utility methods into it
  • sweeps the code for the obvious cases of using Directory to represent a package, especially in method signatures and migrates them
  • notes a few places where we should migrate later, to avoid ballooning the size of the PR

There are no doubt other cases not caught in the sweep, but this gives us a foundation both for new code, and to migrate incrementally toward as we find existing code that was missed.

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.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Slick, this really cleans stuff up. LGTM modulo I think RepositoryPackage should be immutable.


await initializeRun();

final List<PackageEnumerationEntry> packages = includeSubpackages
final List<PackageEnumerationEntry> packageEnumeration = includeSubpackages
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/packageEnumeration/targetPackages I wouldn't call something an enumeration unless its purpose is to assign a number to items, plus targetPackages matches the verbiage of the function.

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. (I actually made this change initially because you'd expressed concern about referring to a PackageEnumerationEntry as a package in the earlier review discussion; I like targetPackages better myself.)

As for enumeration, I was using it in what I think of as the common CS sense (Wikipedia: "An enumeration is a complete, ordered listing of all the items in a collection. The term is commonly used in mathematics and computer science to refer to a listing of all of the elements of a set.")


/// The package's location.
final Directory directory;
/// The package.
Copy link
Member

Choose a reason for hiding this comment

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

nit: not really a helpful comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a warning about excluded to this, as making sure that's not missed seemed like the only useful thing to say here. (I have to say something, because the repo has the lint requiring comments on public fields.

{required String package}) async {
assert(package.isNotEmpty);
{required String packageName}) async {
assert(packageName.isNotEmpty);
Copy link
Member

Choose a reason for hiding this comment

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

fyi: It would be nice if Dart could statically assert this. In many places in my code I just traded null checks for isEmpty checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just traded null checks for isEmpty checks

Well, not really; you traded code that was wrong without you noticing for code that is correct 🙂. Because if an empty string wasn't valid, but the check you had before was foo != null rather than foo != null && !foo.isEmpty, then the old code was wrong.

RepositoryPackage(this.directory);

/// The location of the package.
Directory directory;
Copy link
Member

Choose a reason for hiding this comment

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

Make this final please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, fixed.

Copy link
Contributor Author

@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 think RepositoryPackage should be immutable.

I was going to do that when I first wrote it, but one of the things I want to add to this later (per the TODO) is a lazy cached accessor for the parsed pubspec, as that's something that's used in several places (and caching it would improve some APIs that are currently passing around the package and its parsed pubspec to avoid re-parsing). That doesn't work if it's immutable, I don't want to thrash on adding and then later removing all the consts at creation sites when removing immutability at that point.


await initializeRun();

final List<PackageEnumerationEntry> packages = includeSubpackages
final List<PackageEnumerationEntry> packageEnumeration = includeSubpackages
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. (I actually made this change initially because you'd expressed concern about referring to a PackageEnumerationEntry as a package in the earlier review discussion; I like targetPackages better myself.)

As for enumeration, I was using it in what I think of as the common CS sense (Wikipedia: "An enumeration is a complete, ordered listing of all the items in a collection. The term is commonly used in mathematics and computer science to refer to a listing of all of the elements of a set.")


/// The package's location.
final Directory directory;
/// The package.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a warning about excluded to this, as making sure that's not missed seemed like the only useful thing to say here. (I have to say something, because the repo has the lint requiring comments on public fields.

RepositoryPackage(this.directory);

/// The location of the package.
Directory directory;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, fixed.

@gaaclarke
Copy link
Member

immutable

Yea makes sense. When I saw those methods I thought memoizing them could be helpful, but ultimately I'm not sure how many times you call them. Immutable minus whatever is needed for memoization sounds good to me.

Copy link
Member

@gaaclarke gaaclarke 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 stuartmorgan merged commit fb66220 into flutter:master Aug 24, 2021
@stuartmorgan stuartmorgan deleted the tool-package-class branch August 24, 2021 20:30
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 24, 2021
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
Packages are the primary conceptual object in the tool, but currently they are represented simply as Directory (or occasionally a path string). This introduces an object for packages and:
- moves a number of existing utility methods into it
- sweeps the code for the obvious cases of using `Directory` to represent a package, especially in method signatures and migrates them
- notes a few places where we should migrate later, to avoid ballooning the size of the PR

There are no doubt other cases not caught in the sweep, but this gives us a foundation both for new code, and to migrate incrementally toward as we find existing code that was missed.
amantoux pushed a commit to amantoux/plugins that referenced this pull request Sep 27, 2021
Packages are the primary conceptual object in the tool, but currently they are represented simply as Directory (or occasionally a path string). This introduces an object for packages and:
- moves a number of existing utility methods into it
- sweeps the code for the obvious cases of using `Directory` to represent a package, especially in method signatures and migrates them
- notes a few places where we should migrate later, to avoid ballooning the size of the PR

There are no doubt other cases not caught in the sweep, but this gives us a foundation both for new code, and to migrate incrementally toward as we find existing code that was missed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants