Index: sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart |
diff --git a/sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart b/sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3ef02b3258944c4c4d885fd84898e05290f3e1b9 |
--- /dev/null |
+++ b/sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart |
@@ -0,0 +1,86 @@ |
+library pub.barback.transformer_cache; |
+import 'package:path/path.dart' as p; |
+import '../io.dart'; |
+import '../log.dart' as log; |
+import '../package_graph.dart'; |
+import '../sdk.dart' as sdk; |
+import '../source/cached.dart'; |
+import '../utils.dart'; |
+import 'asset_environment.dart'; |
+import 'transformer_id.dart'; |
+class TransformerCache { |
+ final PackageGraph _graph; |
+ bool _saveSnapshots; |
+ List<Set<TransformerId>> _oldSnapshotPhases; |
+ final _newSnapshotPhases = new List<Set<TransformerId>>(); |
+ String _dir; |
+ String get _manifestPath => p.join(_dir, "manifest.txt"); |
+ TransformerCache.load(AssetEnvironment environment) |
+ : _graph = environment.graph, |
+ _saveSnapshots = environment.rootPackage.dir != null { |
+ if (_saveSnapshots) { |
+ _dir = p.join( |
+ environment.rootPackage.dir, |
+ ".pub", |
+ "transformers", |
+ Uri.encodeComponent(environment.mode.name)); |
+ _oldSnapshotPhases = _parseManifest(); |
+ } else { |
+ _oldSnapshotPhases = const []; |
+ _dir = null; |
+ } |
+ } |
+ String snapshotPath(Set<TransformerId> phase, int phaseNumber) { |
+ if (!_saveSnapshots) return null; |
+ var usesMutableTransformer = phase.any((id) { |
+ var package = _graph.lockFile.packages[id.package]; |
+ if (package == null) return true; |
+ var source = _graph.entrypoint.cache.sources[package.source]; |
+ return source is! CachedSource; |
+ }); |
+ var path = p.join(_dir, "phase$phaseNumber.snapshot"); |
+ if (usesMutableTransformer) { |
+ log.fine( |
+ "Phase $phaseNumber contains mutable transformers, not " "caching."); |
+ _saveSnapshots = false; |
+ deleteEntry(path); |
+ return null; |
+ } |
+ if (_oldSnapshotPhases.length >= phaseNumber && |
+ !_oldSnapshotPhases[phaseNumber - 1].containsAll(phase)) { |
+ log.fine("Cached phase $phaseNumber is out-of-date, deleting."); |
+ deleteEntry(path); |
+ } |
+ _newSnapshotPhases.add(phase); |
+ return path; |
+ } |
+ void save() { |
+ if (_newSnapshotPhases.isEmpty) { |
+ if (_dir != null) deleteEntry(_dir); |
+ return; |
+ } |
+ ensureDir(_dir); |
+ writeTextFile( |
+ _manifestPath, |
+ "${sdk.version}\n" + _newSnapshotPhases.map((phase) { |
+ return ordered(phase.map((id) => id.toString())).join(","); |
+ }).join("\n")); |
+ for (var i = |
+ _newSnapshotPhases.length + |
+ 1; i < _oldSnapshotPhases.length + 1; i++) { |
+ deleteEntry(p.join(_dir, "phase$i.snapshot")); |
+ } |
+ } |
+ List<Set<TransformerId>> _parseManifest() { |
+ if (!fileExists(_manifestPath)) return []; |
+ var manifest = readTextFile(_manifestPath).split("\n"); |
+ if (manifest.removeAt(0) != sdk.version.toString()) { |
+ deleteEntry(_dir); |
+ return []; |
+ } |
+ return manifest.map((line) { |
+ return line.split( |
+ ",").map((id) => new TransformerId.parse(id, null)).toSet(); |
+ }).toList(); |
+ } |
+} |