Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1000)

Unified Diff: web/main.dart

Issue 2183603003: Working compiler in browser. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Git merged master Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « web/index.html ('k') | web/web_command.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: web/main.dart
diff --git a/bin/dartdevc.dart b/web/main.dart
similarity index 63%
copy from bin/dartdevc.dart
copy to web/main.dart
index 98c3e450a2eb691b46021867f761740fa085c7f5..32d1ba6583c4c9e5dce187a7361eed8a85f0a4cd 100755
--- a/bin/dartdevc.dart
+++ b/web/main.dart
@@ -35,60 +35,41 @@
/// local file servers, and users have an expectation of it now, even though
/// it doesn't scale to typical apps that need their own real servers.
+@JS()
+library dev_compiler.web.main;
+
import 'dart:async';
-import 'dart:io';
-import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
+
import 'package:args/command_runner.dart';
-import 'package:bazel_worker/bazel_worker.dart';
-import 'package:dev_compiler/src/compiler/command.dart';
+import 'package:js/js.dart';
-Future main(List<String> args) async {
- // Always returns a new modifiable list.
- args = _preprocessArgs(args);
+import 'web_command.dart';
- if (args.contains('--persistent_worker')) {
- new _CompilerWorker(args..remove('--persistent_worker')).run();
- } else {
- exitCode = await _runCommand(args);
- }
+@JS()
+external set compileDartExpression(Function function);
+
+typedef String CompileFn(String dart);
+typedef void OnLoadFn(CompileFn compile);
+
+Future main() async {
+ var args = ['compile'];
+ _runCommand((result) {
+ compileDartExpression = allowInterop(result);
+ }, args);
}
/// Runs a single compile command, and returns an exit code.
-Future<int> _runCommand(List<String> args,
+Future<int> _runCommand(OnLoadFn onload, List<String> args,
{MessageHandler messageHandler}) async {
try {
- if (args.isEmpty || args.first != 'compile' && args.first != 'help') {
- // TODO(jmesserly): we should deprecate the commands. For now they are
- // still supported for backwards compatibility.
- args.insert(0, 'compile');
- }
var runner = new CommandRunner('dartdevc', 'Dart Development Compiler');
- runner.addCommand(new CompileCommand(messageHandler: messageHandler));
+ runner
+ .addCommand(new WebCompileCommand(onload, messageHandler: messageHandler));
await runner.run(args);
} catch (e, s) {
return _handleError(e, s, args, messageHandler: messageHandler);
}
- return EXIT_CODE_OK;
-}
-
-/// Runs the compiler worker loop.
-class _CompilerWorker extends AsyncWorkerLoop {
- /// The original args supplied to the executable.
- final List<String> _startupArgs;
-
- _CompilerWorker(this._startupArgs) : super();
-
- /// Performs each individual work request.
- Future<WorkResponse> performRequest(WorkRequest request) async {
- var args = _startupArgs.toList()..addAll(request.arguments);
-
- var output = new StringBuffer();
- var exitCode = await _runCommand(args, messageHandler: output.writeln);
- AnalysisEngine.instance.clearCaches();
- return new WorkResponse()
- ..exitCode = exitCode
- ..output = output.toString();
- }
+ return 1;
}
/// Handles [error] in a uniform fashion. Returns the proper exit code and calls
@@ -123,7 +104,6 @@ int _handleError(dynamic error, dynamic stackTrace, List<String> args,
"any other information that may help us track it down. Thanks!");
messageHandler("");
messageHandler(" dartdevc arguments: " + args.join(' '));
- messageHandler(" dart --version: ${Platform.version}");
messageHandler("");
messageHandler("```");
messageHandler(error);
@@ -132,19 +112,3 @@ int _handleError(dynamic error, dynamic stackTrace, List<String> args,
return 70;
}
}
-
-/// Always returns a new modifiable list.
-///
-/// If the final arg is `@file_path` then read in all the lines of that file
-/// and add those as args.
-///
-/// Bazel actions that support workers must provide all their per-WorkRequest
-/// arguments in a file like this instead of as normal args.
-List<String> _preprocessArgs(List<String> args) {
- args = new List.from(args);
- if (args.isNotEmpty && args.last.startsWith('@')) {
- var fileArg = args.removeLast();
- args.addAll(new File(fileArg.substring(1)).readAsLinesSync());
- }
- return args;
-}
« no previous file with comments | « web/index.html ('k') | web/web_command.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698