diff --git a/bin/grind.dart b/bin/grind.dart new file mode 100644 index 00000000..5971b5f9 --- /dev/null +++ b/bin/grind.dart @@ -0,0 +1,11 @@ +// Copyright 2014 Google. All rights reserved. Use of this source code is +// governed by a BSD-style license that can be found in the LICENSE file. + +/** + * Look for `tool/grind.dart` relative to the current directory and run it. + */ +library grinder.grind; + +import 'grinder.dart' as g; + +void main(List args) => g.runScript('tool/grind.dart', args); diff --git a/bin/grinder.dart b/bin/grinder.dart new file mode 100644 index 00000000..fc4a664c --- /dev/null +++ b/bin/grinder.dart @@ -0,0 +1,39 @@ +// Copyright 2014 Google. All rights reserved. Use of this source code is +// governed by a BSD-style license that can be found in the LICENSE file. + +/** + * Look for `tool/grinder.dart` relative to the current directory and run it. + */ +library grinder.grinder; + +import 'dart:io'; + +void main(List args) => runScript('tool/grinder.dart', args); + +void runScript(String script, List args) { + File file = new File(script); + + if (!file.existsSync()) { + print("Error: expected to find a '${script}' script."); + exit(1); + } + + List newArgs = [script]..addAll(args); + _runProcessAsync(Platform.isWindows ? 'dart.exe' : 'dart', newArgs); +} + +void _runProcessAsync(String executable, List arguments) { + Process.start(executable, arguments).then((Process process) { + process.stdout.listen((List data) { + stdout.write(new String.fromCharCodes(data)); + }); + + process.stderr.listen((List data) { + stderr.write(new String.fromCharCodes(data)); + }); + + return process.exitCode.then((int code) { + if (code != 0) exit(code); + }); + }); +} diff --git a/lib/grinder.dart b/lib/grinder.dart index 216cc218..2b1551e0 100644 --- a/lib/grinder.dart +++ b/lib/grinder.dart @@ -115,7 +115,7 @@ ArgParser _createArgsParser() { } void _printUsage(ArgParser parser, Grinder grinder) { - print('usage: dart ${Platform.script} target1 target2 ...'); + print('usage: dart ${_currentScript()} target1 target2 ...'); print(''); print('valid options:'); print(parser.getUsage().replaceAll('\n\n', '\n')); @@ -131,6 +131,15 @@ void _printUsage(ArgParser parser, Grinder grinder) { } } +String _currentScript() { + String script = Platform.script.toString(); + String uriBase = Uri.base.toString(); + if (script.startsWith(uriBase)) { + script = script.substring(uriBase.length); + } + return script; +} + void _printDeps(Grinder grinder) { // calculate the dependencies grinder.start([], dontRun: true);