Skip to content

Commit c1d39f6

Browse files
authored
Merge branch 'master' into constructor-tearoffs-smoke
2 parents 9c36806 + 462fce2 commit c1d39f6

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

lib/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class Dartdoc {
262262
return dartdocResults;
263263
} finally {
264264
// Clear out any cached tool snapshots and temporary directories.
265-
SnapshotCache.instance?.dispose();
265+
SnapshotCache.instanceFor(config.resourceProvider).dispose();
266266
// ignore: unawaited_futures
267267
ToolTempFileTracker.instance?.dispose();
268268
}

lib/src/tool_definition.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class DartToolDefinition extends ToolDefinition {
109109
assert(args[0] == command.first);
110110
// Set up flags to create a new snapshot, if needed, and use the first run
111111
// as the training run.
112-
SnapshotCache.createInstance(_resourceProvider);
113-
var snapshot = SnapshotCache.instance.getSnapshot(command.first);
112+
var snapshotCache = SnapshotCache.instanceFor(_resourceProvider);
113+
var snapshot = snapshotCache.getSnapshot(command.first);
114114
var snapshotFile = snapshot._snapshotFile;
115115
var snapshotPath =
116116
_resourceProvider.pathContext.absolute(snapshotFile.path);
@@ -212,11 +212,11 @@ class _Snapshot {
212212
void _snapshotCompleted() => _snapshotCompleter.complete();
213213
}
214214

215-
/// A singleton that keeps track of cached snapshot files. The [dispose]
215+
/// A class that keeps track of cached snapshot files. The [dispose]
216216
/// function must be called before process exit to clean up snapshots in the
217217
/// cache.
218218
class SnapshotCache {
219-
static SnapshotCache _instance;
219+
static final _instances = <ResourceProvider, SnapshotCache>{};
220220

221221
final Folder snapshotCache;
222222
final ResourceProvider _resourceProvider;
@@ -227,10 +227,12 @@ class SnapshotCache {
227227
: snapshotCache =
228228
_resourceProvider.createSystemTemp('dartdoc_snapshot_cache_');
229229

230-
static SnapshotCache get instance => _instance;
231-
232-
static SnapshotCache createInstance(ResourceProvider resourceProvider) =>
233-
_instance ??= SnapshotCache._(resourceProvider);
230+
/// Returns a [SnapshotCache] for a given [ResourceProvider], creating one
231+
/// only if one doesn't exist yet for the given [ResourceProvider].
232+
factory SnapshotCache.instanceFor(ResourceProvider resourceProvider) {
233+
return _instances.putIfAbsent(
234+
resourceProvider, () => SnapshotCache._(resourceProvider));
235+
}
234236

235237
_Snapshot getSnapshot(String toolPath) {
236238
if (snapshots.containsKey(toolPath)) {
@@ -243,7 +245,7 @@ class SnapshotCache {
243245
}
244246

245247
void dispose() {
246-
_instance = null;
248+
_instances.remove(_resourceProvider);
247249
if (snapshotCache != null && snapshotCache.exists) {
248250
return snapshotCache.delete();
249251
}

lib/src/tool_runner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class ToolRunner {
175175
// find out where their script was coming from as an absolute path on the
176176
// filesystem.
177177
envWithInput['DART_SNAPSHOT_CACHE'] = pathContext.absolute(
178-
SnapshotCache.createInstance(resourceProvider).snapshotCache.path);
178+
SnapshotCache.instanceFor(resourceProvider).snapshotCache.path);
179179
if (toolDefinition.setupCommand != null) {
180180
envWithInput['DART_SETUP_COMMAND'] = toolDefinition.setupCommand[0];
181181
}

test/tool_runner_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ echo:
9595
tearDownAll(() {
9696
tempDir?.deleteSync(recursive: true);
9797
tracker?.dispose();
98-
SnapshotCache.instance?.dispose();
98+
SnapshotCache.instanceFor(pubPackageMetaProvider.resourceProvider)
99+
.dispose();
99100
setupFile = null;
100101
tempDir = null;
101102
});

0 commit comments

Comments
 (0)