Skip to content

Commit

Permalink
Make HotRunner call pub get automatically if the pubspec is out of da…
Browse files Browse the repository at this point in the history
…te. (flutter#19183)

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.

Fixes flutter#15879
  • Loading branch information
gspencergoog authored Jul 11, 2018
1 parent acf3f3d commit 2d76b46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 0 additions & 4 deletions packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,6 @@ class _AppRunLogger extends Logger {
bool expectSlowOperation = false,
int progressIndicatorPadding = 52,
}) {
// Ignore nested progresses; return a no-op status object.
if (_status != null)
return new Status();

final int id = _nextProgressId++;

_sendProgressEvent(<String, dynamic>{
Expand Down
24 changes: 21 additions & 3 deletions packages/flutter_tools/lib/src/run_hot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import 'package:json_rpc_2/error_code.dart' as rpc_error_code;
import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
import 'package:meta/meta.dart';

import 'base/common.dart';
import 'base/context.dart';
import 'base/file_system.dart';
import 'base/logger.dart';
import 'base/utils.dart';
import 'build_info.dart';
import 'compile.dart';
import 'dart/dependencies.dart';
import 'dart/pub.dart';
import 'device.dart';
import 'globals.dart';
import 'resident_runner.dart';
Expand Down Expand Up @@ -77,7 +79,7 @@ class HotRunner extends ResidentRunner {
benchmarkData[name].add(value);
}

bool _refreshDartDependencies() {
Future<bool> _refreshDartDependencies() async {
if (!hotRunnerConfig.computeDartDependencies) {
// Disabled.
return true;
Expand All @@ -86,6 +88,22 @@ class HotRunner extends ResidentRunner {
// Already computed.
return true;
}

try {
// Will return immediately if pubspec.yaml is up-to-date.
await pubGet(
context: PubContext.pubGet,
directory: projectRootPath,
);
} on ToolExit catch (error) {
printError(
'Unable to reload your application because "flutter packages get" failed to update '
'package dependencies.\n'
'$error'
);
return false;
}

final DartDependencySetBuilder dartDependencySetBuilder =
new DartDependencySetBuilder(mainPath, packagesFilePath);
try {
Expand Down Expand Up @@ -230,7 +248,7 @@ class HotRunner extends ResidentRunner {
}

// Determine the Dart dependencies eagerly.
if (!_refreshDartDependencies()) {
if (!await _refreshDartDependencies()) {
// Some kind of source level error or missing file in the Dart code.
return 1;
}
Expand Down Expand Up @@ -282,7 +300,7 @@ class HotRunner extends ResidentRunner {
}

Future<bool> _updateDevFS({ bool fullRestart = false }) async {
if (!_refreshDartDependencies()) {
if (!await _refreshDartDependencies()) {
// Did not update DevFS because of a Dart source error.
return false;
}
Expand Down

0 comments on commit 2d76b46

Please sign in to comment.