Skip to content

Commit

Permalink
add a bin/grind.dart and a bin/grinder.dart script
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew committed Sep 22, 2014
1 parent 5846e01 commit 0af59d5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
11 changes: 11 additions & 0 deletions 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);
39 changes: 39 additions & 0 deletions 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<String> arguments) {
Process.start(executable, arguments).then((Process process) {
process.stdout.listen((List<int> data) {
stdout.write(new String.fromCharCodes(data));
});

process.stderr.listen((List<int> data) {
stderr.write(new String.fromCharCodes(data));
});

return process.exitCode.then((int code) {
if (code != 0) exit(code);
});
});
}
11 changes: 10 additions & 1 deletion lib/grinder.dart
Expand Up @@ -115,7 +115,7 @@ ArgParser _createArgsParser() {
}

void _printUsage(ArgParser parser, Grinder grinder) {
print('usage: dart ${Platform.script} <options> target1 target2 ...');
print('usage: dart ${_currentScript()} <options> target1 target2 ...');
print('');
print('valid options:');
print(parser.getUsage().replaceAll('\n\n', '\n'));
Expand All @@ -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);
Expand Down

0 comments on commit 0af59d5

Please sign in to comment.