Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: pkg/barback/lib/src/transform.dart

Issue 16854005: First pass at build dependency graph for barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Handle unprovided sources and errors a bit better. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/phase.dart ('k') | pkg/barback/lib/src/transform_node.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/transform.dart
diff --git a/pkg/barback/lib/src/transform.dart b/pkg/barback/lib/src/transform.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8023d0edb65818296f6200a214ea9f163af3bf0d
--- /dev/null
+++ b/pkg/barback/lib/src/transform.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library barback.transform;
+
+import 'dart:async';
+
+import 'asset.dart';
+import 'asset_id.dart';
+import 'asset_node.dart';
+import 'errors.dart';
+import 'transform_node.dart';
+
+/// Creates a [Transform] by forwarding to the private constructor.
+///
+/// Lets [TransformNode] create [Transforms] without giving a [Transform]
+/// itself a public constructor, which would be visible to external users.
+/// Unlike the [Transform] class, this function is not exported by barback.dart.
+Transform createTransform(TransformNode node, Set<AssetNode> inputs,
+ Map<AssetId, Asset> outputs) =>
+ new Transform._(node, inputs, outputs);
+
+/// While a [Transformer] represents a *kind* of transformation, this defines
+/// one specific usage of it on a set of files.
+///
+/// This ephemeral object exists only during an actual transform application to
+/// facilitate communication between the [Transformer] and the code hosting
+/// the transformation. It lets the [Transformer] access inputs and generate
+/// outputs.
+class Transform {
+ final TransformNode _node;
+
+ final Set<AssetNode> _inputs;
+ final Map<AssetId, Asset> _outputs;
+
+ /// Gets the ID of the primary input for this transformation.
+ ///
+ /// While a transformation can use multiple input assets, one must be a
+ /// special "primary" asset. This will be the "entrypoint" or "main" input
+ /// file for a transformation.
+ ///
+ /// For example, with a dart2js transform, the primary input would be the
+ /// entrypoint Dart file. All of the other Dart files that that imports
+ /// would be secondary inputs.
+ AssetId get primaryId => _node.primary.id;
+
+ /// Gets the asset for the primary input.
+ Future<Asset> get primaryInput => getInput(primaryId);
+
+ Transform._(this._node, this._inputs, this._outputs);
+
+ /// Gets the asset for for an input [id].
+ ///
+ /// If an input with that ID cannot be found, throws an
+ /// [AssetNotFoundException].
+ Future<Asset> getInput(AssetId id) {
+ return new Future(() {
+ var node = _node.phase.inputs[id];
+ // TODO(rnystrom): Need to handle passthrough where an asset from a
+ // previous phase can be found.
+
+ // Throw if the input isn't found. This ensures the transformer's apply
+ // is exited. We'll then catch this and report it through the proper
+ // results stream.
+ if (node == null) throw new MissingInputException(id);
+
+ // Keep track of which assets this transform depends on.
+ _inputs.add(node);
+ return node.asset;
+ });
+ }
+
+ /// Stores [output] as the output created by this transformation for asset
+ /// [id]. A transformation can output as many assets as it wants.
+ void addOutput(AssetId id, Asset output) {
+ _outputs[id] = output;
+ }
+}
« no previous file with comments | « pkg/barback/lib/src/phase.dart ('k') | pkg/barback/lib/src/transform_node.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698