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

Skip to content

Make HotRunner call pub get automatically if the pubspec is out of date. #19183

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
merged 2 commits into from
Jul 11, 2018

Conversation

gspencergoog
Copy link
Contributor

This adds a call to 'pub get' if the pubspec.yaml is out of date wrt the .packages file when a hot reload is requested.

This PR is missing tests, however there is a dearth of tests for HotRunner because of the effort needed to set up an appropriate test environment. I'd like to fix that, but I think it's out of scope for this PR.

Fixes #15879

@gspencergoog
Copy link
Contributor Author

@devoncarew should this also add a new PubContext value that describes how the pub get is being called?

Copy link
Member

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

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

Two questions about the stdout output and whether to run on every reload and restart or just on restarts.

In terms of testing, you could investigate the integration tests in https://github.com/flutter/flutter/tree/master/packages/flutter_tools/test/integration; @DanTup has added several for reload + debugging, so if unit testing isn't feasible, that would be a good option.

@@ -282,7 +300,7 @@ class HotRunner extends ResidentRunner {
}

Future<bool> _updateDevFS({ bool fullRestart = false }) async {
if (!_refreshDartDependencies()) {
if (!await _refreshDartDependencies()) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to run pub if dirty on reload, or just on restart? Only on restart feels slightly more natural to me, as its handling a bigger change.

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 issue I was trying to fix specifically requests hot reload, and I think I agree with that: hot reload should incorporate any changes that it can. In my mind, the main conceptual difference between the two should simply be if you want to preserve state or not (in practice, of course, you are required to restart for other reasons too).

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. We could also message on reload (You pubspec is out of date, perform a hot restart to get new dependencies), but users would then just need to perform the restart. So, this change looks good for both reload and restart.


try {
// Will return immediately if pubspec.yaml is up-to-date.
await pubGet(
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 confirm that this does print some appropriate message (so the user knows that a pub get is running)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well.. it wasn't. This turned out to be because hot reload calls startProgress on the logger, and then pubGet does the same, and the daemon code uses a custom logger that completely ignores nested progress messages.

I've changed it to print nested progress messages again. You appear to have disabled them (#6677) to make the messages for hot reload and hot restart the same, however, so that might not be the right answer. Other alternatives would be to add an argument to tell startProgress to not ignore specific messages, or to change pubGet to not start its own progress (but that's nice to have on the command line).

Copy link
Member

Choose a reason for hiding this comment

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

Ah, Nov 3, 2016. I think I was trying to address having many small progress items flash by, instead of having a single, unified progress.

IDEs would likely need to upgraded to handle nested progresses, but let me take a look through the PR.

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 progress bar is an indeterminate bar on IntelliJ, and it does actually seem to work (it turns on the indeterminate progress bar in the status area when the reload starts, and turns it off when it's done). For this case, there are only a couple of steps (running pub get, and syncing to the device), but I imagine there could be some where it was a lot of steps flying by.

Of course, it looks fine in the IntelliJ "Run" console output, and on the regular command line.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good! Two steps, where they both don't just flash by, isn't a concern for me. I would just get concerned if we had many very short steps - the text would flash by too quickly for users to read.


try {
// Will return immediately if pubspec.yaml is up-to-date.
await pubGet(
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 also add a new PubContext value that describes how the pub get is being called?

Ah, possibly, based on what the current message says? We may want it tweaked so it says slightly different things based on an initial flutter run vs. a restart.

@gspencergoog gspencergoog merged commit 2d76b46 into flutter:master Jul 11, 2018
@gspencergoog gspencergoog deleted the reload_pub_get branch July 11, 2018 01:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hot reload doesn't rerun pub get if pubspec.yaml has changed
3 participants