-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bin/devrun.dart, which runs DDC's output with iojs or d8 (issue #…
…225)
- Loading branch information
Showing
20 changed files
with
577 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env dart | ||
// Copyright (c) 2015, 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. | ||
|
||
/// Runs io.js with dev_compiler's generated code. | ||
library dev_compiler.bin.devrun; | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:dev_compiler/src/compiler.dart' show validateOptions, compile; | ||
import 'package:dev_compiler/src/options.dart'; | ||
import 'package:dev_compiler/src/runner/runtime_utils.dart' show | ||
listOutputFiles, getMainModuleName; | ||
import 'package:dev_compiler/src/runner/v8_runner.dart' show V8Runner; | ||
|
||
import 'package:path/path.dart'; | ||
|
||
|
||
void _showUsageAndExit() { | ||
print('usage: dartdevrun [<options>] <file.dart>\n'); | ||
print('<file.dart> is a single Dart file to run.\n'); | ||
print('<options> include:\n'); | ||
print(argParser.usage); | ||
exit(1); | ||
} | ||
|
||
main(List<String> args) async { | ||
args = []..add('--arrow-fn-bind-this')..addAll(args); | ||
|
||
CompilerOptions options = validateOptions(args, forceOutDir: true); | ||
if (options == null || options.help) { | ||
_showUsageAndExit(); | ||
} | ||
if (options.inputs.length != 1) { | ||
stderr.writeln("Please only specify one input to run"); | ||
_showUsageAndExit(); | ||
} | ||
var runner = new V8Runner(options); | ||
|
||
if (!await compile(options)) exit(1); | ||
|
||
var files = await listOutputFiles(options); | ||
var startStatement = 'dart_library.start("${getMainModuleName(options)}");'; | ||
|
||
// TODO(ochafik): Only generate the html when some flag is set. | ||
await _writeHtmlRunner(options, files, startStatement); | ||
|
||
// Give our soul (and streams) away to iojs. | ||
Process process = await runner.start(files, startStatement); | ||
stdin.pipe(process.stdin); | ||
stdout.addStream(process.stdout); | ||
stderr.addStream(process.stderr); | ||
exit(await process.exitCode); | ||
} | ||
|
||
/// Generates an HTML file that can be used to run the output with Chrome Dev. | ||
_writeHtmlRunner(CompilerOptions options, List<File> files, | ||
String startStatement) async { | ||
String outputDir = options.codegenOptions.outputDir; | ||
String htmlOutput = join(outputDir, "run.html"); | ||
await new File(htmlOutput).writeAsString(''' | ||
<html><head></head><body> | ||
${files.map((f) => | ||
'<script src="${relative(f.path, from: outputDir)}"></script>') | ||
.join("\n")} | ||
<script>$startStatement</script> | ||
</body></html> | ||
'''); | ||
|
||
stderr.writeln( | ||
'Wrote $htmlOutput. It can be opened in Chrome Dev with the following flags:\n' | ||
'--js-flags="--harmony-arrow-functions ' | ||
'--harmony-classes ' | ||
'--harmony-computed-property-names ' | ||
'--harmony-spreadcalls"' | ||
'\n'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2015, 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. | ||
|
||
/// File-listing utils used by dartdevrun. | ||
library dev_compiler.src.runner.file_utils; | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
Future<List<File>> listJsFiles(Directory dir) async { | ||
var list = []; | ||
await for (var file in dir.list(recursive: true, followLinks: true)) { | ||
if (file is File && file.path.endsWith(".js")) list.add(file.absolute); | ||
} | ||
return list; | ||
} |
Oops, something went wrong.