Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e_example/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/*.txt.copy
web/_packages
42 changes: 42 additions & 0 deletions e2e_example/lib/packages_dir_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2016, 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.
import 'dart:async';

import 'package:path/path.dart' as p;

import 'package:build/build.dart';
import 'package:build/src/generate/input_set.dart';
import 'package:build/src/generate/phase.dart';

// Makes copies of things!
class PackagesDirBuilder extends Builder {
final String outputDir;
final String outputPackage;

PackagesDirBuilder(this.outputPackage, this.outputDir);

@override
Future build(BuildStep buildStep) async {
var input = buildStep.input;
var copy = new Asset(_copiedAssetId(input.id), input.stringContents);
await buildStep.writeAsString(copy);
}

@override
List<AssetId> declareOutputs(AssetId inputId) => [_copiedAssetId(inputId)];

static void addPhases(PhaseGroup group, PackageGraph graph) {
var builder = new PackagesDirBuilder(graph.root.name, 'web');
var phase = group.newPhase();
for (var package in graph.allPackages.values) {
phase.addAction(builder, new InputSet(package.name, ['lib/**']));
}
}

AssetId _copiedAssetId(AssetId inputId) => new AssetId(
outputPackage,
// Creating a folder actually called `packages` breaks things.
p.join(outputDir, '_packages', inputId.package,
inputId.path.replaceFirst('lib/', '')));
}
12 changes: 8 additions & 4 deletions e2e_example/tool/watch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import 'dart:async';
import 'package:build/build.dart';

import 'package:e2e_example/copy_builder.dart';
import 'package:e2e_example/packages_dir_builder.dart';

Future main() async {
/// Builds a full package dependency graph for the current package.
// Builds a full package dependency graph for the current package.
var graph = new PackageGraph.forThisPackage();
var phases = new PhaseGroup();

/// Give [Builder]s access to a [PackageGraph] so they can choose which
/// packages to run on. This simplifies user code a lot, and helps to mitigate
/// the transitive deps issue.
// Give [Builder]s access to a [PackageGraph] so they can choose which
// packages to run on. This simplifies user code a lot, and helps to mitigate
// the transitive deps issue.
CopyBuilder.addPhases(phases, graph);

// Adds all the phases necessary to copy all files into a fake packages dir!
PackagesDirBuilder.addPhases(phases, graph);

watch(phases);
}
6 changes: 5 additions & 1 deletion lib/src/asset/file_based.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ class FileBasedAssetReader implements AssetReader {
var packageNode = packageGraph[inputSet.package];
if (packageNode == null) {
throw new ArgumentError(
"Could not find inputSet.package '${inputSet.package}'.");
"Could not find package '${inputSet.package}' which was listed as "
"an input. Please ensure you have that package in your deps, or "
"remove it from your input sets.");
}
var packagePath = packageNode.location.toFilePath();
for (var glob in inputSet.globs) {
var fileStream = glob.list(followLinks: false, root: packagePath).where(
(e) => e is File && !ignoredDirs.contains(path.split(e.path)[1]));
await for (var entity in fileStream) {
// TODO(jakemac): Where do these files come from???
if (path.basename(entity.path).startsWith('._')) continue;
var id = _fileToAssetId(entity, packageNode);
if (!seenAssets.add(id)) continue;
yield id;
Expand Down
7 changes: 6 additions & 1 deletion lib/src/generate/build_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ class BuildImpl {
node is! GeneratedAssetNode ||
(node as GeneratedAssetNode).wasOutput)
.map((node) async {
var exists = await _reader.hasInput(node.id);
bool exists;
try {
exists = await _reader.hasInput(node.id);
} on PackageNotFoundException catch(_) {
exists = false;
}
if (!exists) {
updates[node.id] = ChangeType.REMOVE;
return;
Expand Down