Skip to content

Commit 3a60aa9

Browse files
bkonyisuryaKommana2662
authored andcommitted
Reland "[flutter_tools] forward --offline flag to pub.get in update-packages" (flutter#193838)
Relands flutter#193619 (reverted in flutter#193808) with `const` added to `DelegatingToolContext()` in `update_packages_test.dart` to satisfy `prefer_const_constructors`. When running `flutter update-packages --offline`, the `--offline` flag was parsed and used to validate incompatible option combinations (such as `--force-upgrade` and `--cherry-pick-package`), but was not forwarded to the underlying `pub.get` invocations. Read `boolArg(_keyOffline)` in `_pubGet` and forward it to `pub.get` so that `pub` does not attempt network operations in offline environments. Fixes flutter#193423 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [breaking change policy]: https://flutter.dev/to/breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 23ddd19 commit 3a60aa9

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎packages/flutter_tools/lib/src/commands/update_packages.dart‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,20 +257,30 @@ class UpdatePackagesCommand extends FlutterCommand {
257257
_checkPins(rootDirectory);
258258

259259
// Pub get for the workspace.
260-
await _pubGet(rootProject, !forceUpgrade && cherryPicks.isEmpty && !updateHashes);
260+
await _pubGet(
261+
rootProject,
262+
enforceLockfile: !forceUpgrade && cherryPicks.isEmpty && !updateHashes,
263+
);
261264

262265
// Manually do a pub get for packages not part of the workspace.
263266
// See https://github.com/flutter/flutter/pull/170364.
264-
await _pubGet(toolProject, false);
265-
await _pubGet(projectFactory.fromDirectory(hooksUserDefineIntegrationTestDirectory), false);
267+
await _pubGet(toolProject, enforceLockfile: false);
268+
await _pubGet(
269+
projectFactory.fromDirectory(hooksUserDefineIntegrationTestDirectory),
270+
enforceLockfile: false,
271+
);
266272

267273
await _downloadCoverageData();
268274

269275
return FlutterCommandResult.success();
270276
}
271277

272-
Future<void> _pubGet(FlutterProject project, bool enforceLockfile) async =>
273-
_pub.get(context: PubContext.pubGet, project: project, enforceLockfile: enforceLockfile);
278+
Future<void> _pubGet(FlutterProject project, {required bool enforceLockfile}) async => _pub.get(
279+
context: PubContext.pubGet,
280+
project: project,
281+
enforceLockfile: enforceLockfile,
282+
offline: boolArg(_keyOffline),
283+
);
274284

275285
Future<List<_ProjectDeps>> _upgrade({
276286
required bool forceUpgrade,

‎packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,30 @@ void main() {
303303
pub.pubspecs[flutterSdk.absolute.path]!.first.dependencies,
304304
Pubspec.parse(kFlutterWorkspacePubspecYaml).dependencies,
305305
);
306+
expect(pub.recordedPubGets, hasLength(3));
307+
expect(pub.recordedPubGets.map((r) => r.offline), everyElement(isFalse));
308+
expect(pub.recordedPubGets[0].enforceLockfile, isTrue);
309+
expect(pub.recordedPubGets[1].enforceLockfile, isFalse);
310+
expect(pub.recordedPubGets[2].enforceLockfile, isFalse);
311+
});
312+
313+
testWithoutContext('updates packages --offline passes offline flag to pub get', () async {
314+
final command = UpdatePackagesCommand(
315+
toolContext: toolContext,
316+
httpClientFactory: FakeHttpClient.any,
317+
pub: pub,
318+
verboseHelp: false,
319+
);
320+
await createTestCommandRunner(command).run(<String>['update-packages', '--offline']);
321+
expect(
322+
pub.pubspecs[flutterSdk.absolute.path]!.first.dependencies,
323+
Pubspec.parse(kFlutterWorkspacePubspecYaml).dependencies,
324+
);
325+
expect(pub.recordedPubGets, hasLength(3));
326+
expect(pub.recordedPubGets.map((r) => r.offline), everyElement(isTrue));
327+
expect(pub.recordedPubGets[0].enforceLockfile, isTrue);
328+
expect(pub.recordedPubGets[1].enforceLockfile, isFalse);
329+
expect(pub.recordedPubGets[2].enforceLockfile, isFalse);
306330
});
307331

308332
testWithoutContext('--force-upgrade updates packages', () async {
@@ -592,6 +616,9 @@ class _FakePub extends Fake implements Pub {
592616
(pubspecs[project.directory.path] ??= <Pubspec>[]).add(pubspec);
593617
}
594618

619+
final recordedPubGets =
620+
<({PubContext context, FlutterProject project, bool enforceLockfile, bool offline})>[];
621+
595622
@override
596623
Future<void> get({
597624
required PubContext context,
@@ -604,6 +631,12 @@ class _FakePub extends Fake implements Pub {
604631
bool enforceLockfile = false,
605632
PubOutputMode outputMode = PubOutputMode.all,
606633
}) async {
634+
recordedPubGets.add((
635+
context: context,
636+
project: project,
637+
enforceLockfile: enforceLockfile,
638+
offline: offline,
639+
));
607640
(pubspecs[project.directory.path] ??= <Pubspec>[]).add(
608641
Pubspec.parse(project.pubspecFile.readAsStringSync()),
609642
);

0 commit comments

Comments
 (0)