Skip to content

Commit 76cbc46

Browse files
author
Jonah Williams
authored
[flutter_tools] remove all pub caching logic (flutter#66776)
There have been some more additional reports of a missing 'package:characters' import after upgrading flutter, as well as problems with detecting the correct language version. This has me concerned that our pub caching logic is incorrect. Instead of the tool attempting to guess when pub should be run, always delegate to pub.
1 parent 826b704 commit 76cbc46

File tree

12 files changed

+43
-180
lines changed

12 files changed

+43
-180
lines changed

packages/flutter_tools/lib/src/cache.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,6 @@ class PubDependencies extends ArtifactSet {
700700
context: PubContext.pubGet,
701701
directory: _fileSystem.path.join(_flutterRoot(), 'packages', 'flutter_tools'),
702702
generateSyntheticPackage: false,
703-
skipPubspecYamlCheck: true,
704-
checkLastModified: false,
705703
);
706704
}
707705
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class PackagesGetCommand extends FlutterCommand {
117117
directory: directory,
118118
upgrade: upgrade ,
119119
offline: boolArg('offline'),
120-
checkLastModified: false,
121120
generateSyntheticPackage: flutterProject.manifest.generateSyntheticPackage,
122121
);
123122
pubGetTimer.stop();

packages/flutter_tools/lib/src/commands/test.dart

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import '../asset.dart';
88
import '../base/common.dart';
99
import '../base/file_system.dart';
1010
import '../build_info.dart';
11-
import '../build_system/build_system.dart';
1211
import '../bundle.dart';
1312
import '../cache.dart';
14-
import '../dart/generate_synthetic_packages.dart';
15-
import '../dart/pub.dart';
1613
import '../devfs.dart';
1714
import '../globals.dart' as globals;
1815
import '../project.dart';
@@ -169,32 +166,6 @@ class TestCommand extends FlutterCommand {
169166
'directory (or one of its subdirectories).');
170167
}
171168
final FlutterProject flutterProject = FlutterProject.current();
172-
if (shouldRunPub) {
173-
if (flutterProject.manifest.generateSyntheticPackage) {
174-
final Environment environment = Environment(
175-
artifacts: globals.artifacts,
176-
logger: globals.logger,
177-
cacheDir: globals.cache.getRoot(),
178-
engineVersion: globals.flutterVersion.engineRevision,
179-
fileSystem: globals.fs,
180-
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
181-
outputDir: globals.fs.directory(getBuildDirectory()),
182-
processManager: globals.processManager,
183-
projectDir: flutterProject.directory,
184-
);
185-
186-
await generateLocalizationsSyntheticPackage(
187-
environment: environment,
188-
buildSystem: globals.buildSystem,
189-
);
190-
}
191-
192-
await pub.get(
193-
context: PubContext.getVerifyContext(name),
194-
skipPubspecYamlCheck: true,
195-
generateSyntheticPackage: flutterProject.manifest.generateSyntheticPackage,
196-
);
197-
}
198169
final bool buildTestAssets = boolArg('test-assets');
199170
final List<String> names = stringsArg('name');
200171
final List<String> plainNames = stringsArg('plain-name');

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ class UpdatePackagesCommand extends FlutterCommand {
330330
context: PubContext.updatePackages,
331331
directory: tempDir.path,
332332
upgrade: true,
333-
checkLastModified: false,
334333
offline: offline,
335334
flutterRootOverride: upgrade
336335
? temporaryFlutterSdk.path
@@ -413,7 +412,6 @@ class UpdatePackagesCommand extends FlutterCommand {
413412
await pub.get(
414413
context: PubContext.updatePackages,
415414
directory: dir.path,
416-
checkLastModified: false,
417415
offline: offline,
418416
generateSyntheticPackage: false,
419417
);

packages/flutter_tools/lib/src/commands/upgrade.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ class UpgradeCommandRunner {
296296
context: PubContext.pubUpgrade,
297297
directory: projectRoot,
298298
upgrade: true,
299-
checkLastModified: false,
300299
generateSyntheticPackage: false,
301300
);
302301
}

packages/flutter_tools/lib/src/commands/version.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class VersionCommand extends FlutterCommand {
151151
context: PubContext.pubUpgrade,
152152
directory: projectRoot,
153153
upgrade: true,
154-
checkLastModified: false,
155154
generateSyntheticPackage: false,
156155
);
157156
}

packages/flutter_tools/lib/src/context_runner.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ Future<T> runInContext<T>(
236236
botDetector: globals.botDetector,
237237
platform: globals.platform,
238238
usage: globals.flutterUsage,
239-
// Avoid a circular dependency by making this access lazy.
240-
toolStampFile: () => globals.cache.getStampFileFor('flutter_tools'),
241239
),
242240
ShutdownHooks: () => ShutdownHooks(logger: globals.logger),
243241
Stdio: () => Stdio(),

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

Lines changed: 32 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ abstract class Pub {
8080
@required Platform platform,
8181
@required BotDetector botDetector,
8282
@required Usage usage,
83-
File Function() toolStampFile,
8483
}) = _DefaultPub;
8584

8685
/// Runs `pub get`.
@@ -93,8 +92,6 @@ abstract class Pub {
9392
bool skipIfAbsent = false,
9493
bool upgrade = false,
9594
bool offline = false,
96-
bool checkLastModified = true,
97-
bool skipPubspecYamlCheck = false,
9895
bool generateSyntheticPackage = false,
9996
String flutterRootOverride,
10097
});
@@ -141,9 +138,7 @@ class _DefaultPub implements Pub {
141138
@required Platform platform,
142139
@required BotDetector botDetector,
143140
@required Usage usage,
144-
File Function() toolStampFile,
145-
}) : _toolStampFile = toolStampFile,
146-
_fileSystem = fileSystem,
141+
}) : _fileSystem = fileSystem,
147142
_logger = logger,
148143
_platform = platform,
149144
_botDetector = botDetector,
@@ -159,7 +154,6 @@ class _DefaultPub implements Pub {
159154
final Platform _platform;
160155
final BotDetector _botDetector;
161156
final Usage _usage;
162-
final File Function() _toolStampFile;
163157

164158
@override
165159
Future<void> get({
@@ -168,88 +162,52 @@ class _DefaultPub implements Pub {
168162
bool skipIfAbsent = false,
169163
bool upgrade = false,
170164
bool offline = false,
171-
bool checkLastModified = true,
172-
bool skipPubspecYamlCheck = false,
173165
bool generateSyntheticPackage = false,
174166
String flutterRootOverride,
175167
}) async {
176168
directory ??= _fileSystem.currentDirectory.path;
177-
178-
final File pubSpecYaml = _fileSystem.file(
179-
_fileSystem.path.join(directory, 'pubspec.yaml'));
180169
final File packageConfigFile = _fileSystem.file(
181170
_fileSystem.path.join(directory, '.dart_tool', 'package_config.json'));
182171
final Directory generatedDirectory = _fileSystem.directory(
183172
_fileSystem.path.join(directory, '.dart_tool', 'flutter_gen'));
184173

185-
if (!skipPubspecYamlCheck && !pubSpecYaml.existsSync()) {
186-
if (!skipIfAbsent) {
187-
throwToolExit('$directory: no pubspec.yaml found');
188-
}
189-
return;
190-
}
191-
192-
final DateTime originalPubspecYamlModificationTime = pubSpecYaml.lastModifiedSync();
193-
194-
if (!checkLastModified || _shouldRunPubGet(
195-
pubSpecYaml: pubSpecYaml,
196-
packageConfigFile: packageConfigFile,
197-
)) {
198-
final String command = upgrade ? 'upgrade' : 'get';
199-
final Status status = _logger.startProgress(
200-
'Running "flutter pub $command" in ${_fileSystem.path.basename(directory)}...',
201-
timeout: const TimeoutConfiguration().slowOperation,
174+
final String command = upgrade ? 'upgrade' : 'get';
175+
final Status status = _logger.startProgress(
176+
'Running "flutter pub $command" in ${_fileSystem.path.basename(directory)}...',
177+
timeout: const TimeoutConfiguration().slowOperation,
178+
);
179+
final bool verbose = _logger.isVerbose;
180+
final List<String> args = <String>[
181+
if (verbose)
182+
'--verbose'
183+
else
184+
'--verbosity=warning',
185+
...<String>[
186+
command,
187+
'--no-precompile',
188+
],
189+
if (offline)
190+
'--offline',
191+
];
192+
try {
193+
await batch(
194+
args,
195+
context: context,
196+
directory: directory,
197+
failureMessage: 'pub $command failed',
198+
retry: true,
199+
flutterRootOverride: flutterRootOverride,
202200
);
203-
final bool verbose = _logger.isVerbose;
204-
final List<String> args = <String>[
205-
if (verbose)
206-
'--verbose'
207-
else
208-
'--verbosity=warning',
209-
...<String>[
210-
command,
211-
'--no-precompile',
212-
],
213-
if (offline)
214-
'--offline',
215-
];
216-
try {
217-
await batch(
218-
args,
219-
context: context,
220-
directory: directory,
221-
failureMessage: 'pub $command failed',
222-
retry: true,
223-
flutterRootOverride: flutterRootOverride,
224-
);
225-
status.stop();
226-
// The exception is rethrown, so don't catch only Exceptions.
227-
} catch (exception) { // ignore: avoid_catches_without_on_clauses
228-
status.cancel();
229-
rethrow;
230-
}
201+
status.stop();
202+
// The exception is rethrown, so don't catch only Exceptions.
203+
} catch (exception) { // ignore: avoid_catches_without_on_clauses
204+
status.cancel();
205+
rethrow;
231206
}
232207

233208
if (!packageConfigFile.existsSync()) {
234209
throwToolExit('$directory: pub did not create .dart_tools/package_config.json file.');
235210
}
236-
if (pubSpecYaml.lastModifiedSync() != originalPubspecYamlModificationTime) {
237-
throwToolExit(
238-
'$directory: unexpected concurrent modification of '
239-
'pubspec.yaml while running pub.');
240-
}
241-
// We don't check if dotPackages was actually modified, because as far as we can tell sometimes
242-
// pub will decide it does not need to actually modify it.
243-
final DateTime now = DateTime.now();
244-
if (now.isBefore(originalPubspecYamlModificationTime)) {
245-
_logger.printError(
246-
'Warning: File "${_fileSystem.path.absolute(pubSpecYaml.path)}" was created in the future. '
247-
'Optimizations that rely on comparing time stamps will be unreliable. Check your '
248-
'system clock for accuracy.\n'
249-
'The timestamp was: $originalPubspecYamlModificationTime\n'
250-
'The time now is: $now'
251-
);
252-
}
253211
await _updatePackageConfig(
254212
packageConfigFile,
255213
generatedDirectory,
@@ -392,23 +350,6 @@ class _DefaultPub implements Pub {
392350
return <String>[sdkPath, ...arguments];
393351
}
394352

395-
bool _shouldRunPubGet({ @required File pubSpecYaml, @required File packageConfigFile }) {
396-
if (!packageConfigFile.existsSync()) {
397-
return true;
398-
}
399-
final DateTime dotPackagesLastModified = packageConfigFile.lastModifiedSync();
400-
if (pubSpecYaml.lastModifiedSync().isAfter(dotPackagesLastModified)) {
401-
return true;
402-
}
403-
final File toolStampFile = _toolStampFile != null ? _toolStampFile() : null;
404-
if (toolStampFile != null &&
405-
toolStampFile.existsSync() &&
406-
toolStampFile.lastModifiedSync().isAfter(dotPackagesLastModified)) {
407-
return true;
408-
}
409-
return false;
410-
}
411-
412353
// Returns the environment value that should be used when running pub.
413354
//
414355
// Includes any existing environment variable, if one exists.

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,9 @@ abstract class FlutterCommand extends Command<void> {
950950
// First always update universal artifacts, as some of these (e.g.
951951
// ios-deploy on macOS) are required to determine `requiredArtifacts`.
952952
await globals.cache.updateAll(<DevelopmentArtifact>{DevelopmentArtifact.universal});
953-
954953
await globals.cache.updateAll(await requiredArtifacts);
955954
}
955+
Cache.releaseLock();
956956

957957
await validateCommand();
958958

@@ -979,11 +979,7 @@ abstract class FlutterCommand extends Command<void> {
979979
context: PubContext.getVerifyContext(name),
980980
generateSyntheticPackage: project.manifest.generateSyntheticPackage,
981981
);
982-
// All done updating dependencies. Release the cache lock.
983-
Cache.releaseLock();
984982
await project.ensureReadyForPlatformSpecificTooling(checkProjects: true);
985-
} else {
986-
Cache.releaseLock();
987983
}
988984

989985
setupApplicationPackages();

packages/flutter_tools/test/general.shard/cache_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,6 @@ void main() {
743743
verify(pub.get(
744744
context: PubContext.pubGet,
745745
directory: 'packages/flutter_tools',
746-
generateSyntheticPackage: false,
747-
skipPubspecYamlCheck: true,
748-
checkLastModified: false,
749746
)).called(1);
750747
});
751748
}

0 commit comments

Comments
 (0)