-
Notifications
You must be signed in to change notification settings - Fork 214
added top level watch function #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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:io'; | ||
|
||
import 'package:build/build.dart'; | ||
|
||
import 'package:e2e_example/copy_builder.dart'; | ||
|
||
main() async { | ||
/// Builds a full package dependency graph for the current package. | ||
var graph = new PackageGraph.forThisPackage(); | ||
|
||
/// 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. | ||
var phases = CopyBuilder.buildPhases(graph); | ||
|
||
await for (var result in watch([phases])) { | ||
if (result.status == BuildStatus.Success) { | ||
stdout.writeln(result); | ||
} else { | ||
stderr.writeln(result); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ import 'dart:async'; | |
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:logging/logging.dart'; | ||
import 'package:path/path.dart' as path; | ||
|
||
import '../asset/asset.dart'; | ||
import '../asset/cache.dart'; | ||
import '../asset/exceptions.dart'; | ||
import '../asset/id.dart'; | ||
import '../asset/reader.dart'; | ||
|
@@ -31,9 +33,10 @@ class BuildImpl { | |
final List<List<Phase>> _phaseGroups; | ||
final _inputsByPackage = <String, Set<AssetId>>{}; | ||
bool _buildRunning = false; | ||
final _logger = new Logger('Build'); | ||
|
||
BuildImpl(this._assetGraph, this._reader, this._writer, this._packageGraph, | ||
this._phaseGroups); | ||
BuildImpl(this._assetGraph, this._reader, this._writer, | ||
this._packageGraph, this._phaseGroups); | ||
|
||
/// Runs a build | ||
/// | ||
|
@@ -48,12 +51,15 @@ class BuildImpl { | |
_buildRunning = true; | ||
|
||
/// Wait while all inputs are collected. | ||
_logger.info('Initializing inputs'); | ||
await _initializeInputsByPackage(); | ||
|
||
/// Delete all previous outputs! | ||
_logger.info('Deleting previous outputs'); | ||
await _deletePreviousOutputs(); | ||
|
||
/// Run a fresh build. | ||
_logger.info('Running build phases'); | ||
var result = await _runPhases(); | ||
|
||
// Write out the new build_outputs file. | ||
|
@@ -112,7 +118,8 @@ class BuildImpl { | |
|
||
groupOutputIds.addAll(outputs); | ||
for (var output in outputs) { | ||
if (tempInputsByPackage[output.package]?.contains(output) == true) { | ||
if (tempInputsByPackage[output.package]?.contains(output) == | ||
true) { | ||
conflictingOutputs.add(output); | ||
} | ||
} | ||
|
@@ -139,10 +146,11 @@ class BuildImpl { | |
while (!done) { | ||
stdout.write('Delete these files (y/n) (or list them (l))?: '); | ||
var input = stdin.readLineSync(); | ||
switch (input) { | ||
switch (input.toLowerCase()) { | ||
case 'y': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add handling for upper case (or just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point |
||
stdout.writeln('Deleting files...'); | ||
await Future.wait(conflictingOutputs.map((output) { | ||
_inputsByPackage[output.package]?.remove(output); | ||
return _writer.delete(output); | ||
})); | ||
done = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,26 @@ class BuildResult { | |
BuildResult(this.status, this.buildType, List<Asset> outputs, | ||
{this.exception, this.stackTrace}) | ||
: outputs = new List.unmodifiable(outputs); | ||
|
||
@override | ||
String toString() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (status == BuildStatus.Success) { | ||
return ''' | ||
|
||
Build Succeeded! | ||
Type: ${buildType} | ||
'''; | ||
} else { | ||
return ''' | ||
|
||
Build Failed :( | ||
Type: ${buildType} | ||
Exception: ${exception} | ||
Stack Trace: | ||
${stackTrace} | ||
'''; | ||
} | ||
} | ||
} | ||
|
||
/// The status of a build. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// 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 'package:watcher/watcher.dart'; | ||
|
||
typedef DirectoryWatcher DirectoryWatcherFactory(String path); | ||
|
||
DirectoryWatcher defaultDirectoryWatcherFactory(String path) => | ||
new DirectoryWatcher(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move
terminateEventStream
logic to a helperThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call