Skip to content

Commit 0125d95

Browse files
authored
Update flutter pub get to use flutter.version.json (instead of version) (flutter#172798)
Towards flutter#171900. Discovered during flutter#172793. It's unfortunate that `DefaultPub` (and tests) need some massaging to work, but the fact the tool is so inconsistent about global versus local state is not a new thing, so I didn't worry about it in the context of this PR.
1 parent 7de7baf commit 0125d95

File tree

2 files changed

+148
-93
lines changed

2 files changed

+148
-93
lines changed

packages/flutter_tools/lib/src/dart/pub.dart

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import '../base/process.dart';
2121
import '../cache.dart';
2222
import '../convert.dart';
2323
import '../dart/package_map.dart';
24+
import '../git.dart';
2425
import '../project.dart';
2526
import '../version.dart';
2627

@@ -208,7 +209,9 @@ class _DefaultPub implements Pub {
208209
_botDetector = botDetector,
209210
_processUtils = ProcessUtils(logger: logger, processManager: processManager),
210211
_processManager = processManager,
211-
_stdio = null;
212+
_stdio = null {
213+
_git = Git(currentPlatform: platform, runProcessWith: _processUtils);
214+
}
212215

213216
@visibleForTesting
214217
_DefaultPub.test({
@@ -224,7 +227,9 @@ class _DefaultPub implements Pub {
224227
_botDetector = botDetector,
225228
_processUtils = ProcessUtils(logger: logger, processManager: processManager),
226229
_processManager = processManager,
227-
_stdio = stdio;
230+
_stdio = stdio {
231+
_git = Git(currentPlatform: platform, runProcessWith: _processUtils);
232+
}
228233

229234
final FileSystem _fileSystem;
230235
final Logger _logger;
@@ -233,6 +238,7 @@ class _DefaultPub implements Pub {
233238
final BotDetector _botDetector;
234239
final ProcessManager _processManager;
235240
final Stdio? _stdio;
241+
late final Git _git;
236242

237243
@override
238244
Future<void> get({
@@ -285,8 +291,10 @@ class _DefaultPub implements Pub {
285291
if (packageConfigFile.existsSync()) {
286292
final Directory workspaceRoot = packageConfigFile.parent.parent;
287293
final File lastVersion = workspaceRoot.childDirectory('.dart_tool').childFile('version');
288-
final File currentVersion = _fileSystem.file(
289-
_fileSystem.path.join(Cache.flutterRoot!, 'version'),
294+
final versionFromFile = FlutterVersion(
295+
flutterRoot: Cache.flutterRoot!,
296+
fs: _fileSystem,
297+
git: _git,
290298
);
291299
final File pubspecYaml = project.pubspecFile;
292300
final File pubLockFile = workspaceRoot.childFile('pubspec.lock');
@@ -319,7 +327,7 @@ class _DefaultPub implements Pub {
319327
pubspecYaml.lastModifiedSync().isBefore(pubLockFile.lastModifiedSync()) &&
320328
pubspecYaml.lastModifiedSync().isBefore(packageConfigFile.lastModifiedSync()) &&
321329
lastVersion.existsSync() &&
322-
lastVersion.readAsStringSync() == currentVersion.readAsStringSync()) {
330+
lastVersion.readAsStringSync() == versionFromFile.frameworkVersion) {
323331
_logger.printTrace('Skipping pub get: version match.');
324332
return;
325333
}
@@ -675,10 +683,12 @@ class _DefaultPub implements Pub {
675683
final File lastVersion = _fileSystem.file(
676684
_fileSystem.path.join(packageConfig.parent.path, 'version'),
677685
);
678-
final File currentVersion = _fileSystem.file(
679-
_fileSystem.path.join(Cache.flutterRoot!, 'version'),
686+
final versionFromFile = FlutterVersion(
687+
flutterRoot: Cache.flutterRoot!,
688+
fs: _fileSystem,
689+
git: _git,
680690
);
681-
lastVersion.writeAsStringSync(currentVersion.readAsStringSync());
691+
lastVersion.writeAsStringSync(versionFromFile.frameworkVersion);
682692

683693
if (project.hasExampleApp && project.example.pubspecFile.existsSync()) {
684694
final File? examplePackageConfig = findPackageConfigFile(project.example.directory);

0 commit comments

Comments
 (0)