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

Unified Diff: lib/devc.dart

Issue 1130093007: Create html if needed in server mode (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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
Index: lib/devc.dart
diff --git a/lib/devc.dart b/lib/devc.dart
index 8ab4257675a499d9f31465f2fb025f0636ebccce..a2170e07507478fdc8267d970e79bb6d3073e8e4 100644
--- a/lib/devc.dart
+++ b/lib/devc.dart
@@ -25,6 +25,7 @@ import 'src/codegen/dart_codegen.dart';
import 'src/codegen/html_codegen.dart';
import 'src/codegen/js_codegen.dart';
import 'src/dependency_graph.dart';
+import 'src/in_memory.dart';
import 'src/info.dart' show LibraryInfo, CheckerResults, LibraryUnit;
import 'src/options.dart';
import 'src/report.dart';
@@ -54,12 +55,35 @@ class Compiler {
final bool _hashing;
bool _failure = false;
+ static const String _implicitEntryFile = 'index.html';
+
factory Compiler(CompilerOptions options,
- [TypeResolver resolver, CheckerReporter reporter]) {
+ {TypeResolver resolver, CheckerReporter reporter, implicitHtml: false}) {
+ var inputFile = options.entryPointFile;
+ var inputUri = inputFile.startsWith('dart:') ||
+ inputFile.startsWith('package:')
+ ? Uri.parse(inputFile)
+ : new Uri.file(path.absolute(inputFile));
+
if (resolver == null) {
+ InMemoryUriResolver entryResolver = null;
Jennifer Messerly 2015/05/13 19:31:55 per suggestion below, moving implicitHtml into opt
vsm 2015/05/14 00:04:07 Done. Pushed it down to Resolver.
+ if (implicitHtml) {
+ inputFile = _implicitEntryFile;
+ var entry = path.absolute(inputFile);
+ inputUri = new Uri.file(entry);
+ var src = path.absolute(options.entryPointFile);
+ var index = <String, String>{
+ '$entry':
+ '<html><body><script type="application/dart" src="$src"></script></body></html>'
Jennifer Messerly 2015/05/13 19:31:55 long line. sadly formatter won't fix these or even
vsm 2015/05/14 00:04:08 Moved.
+ };
+ entryResolver =
+ new InMemoryUriResolver(index, representNonExistingFiles: false);
+ }
resolver = options.useMockSdk
- ? new TypeResolver.fromMock(mockSdkSources, options)
- : new TypeResolver.fromDir(options.dartSdkPath, options);
+ ? new TypeResolver.fromMock(mockSdkSources, options,
+ entryResolver: entryResolver)
+ : new TypeResolver.fromDir(options.dartSdkPath, options,
+ entryResolver: entryResolver);
}
if (reporter == null) {
@@ -71,12 +95,8 @@ class Compiler {
var rules =
new RestrictedRules(resolver.context.typeProvider, options: options);
var checker = new CodeChecker(rules, reporter, options);
- var inputFile = options.entryPointFile;
- var uri = inputFile.startsWith('dart:') || inputFile.startsWith('package:')
- ? Uri.parse(inputFile)
- : new Uri.file(path.absolute(inputFile));
- var entryNode = graph.nodeFromUri(uri);
+ var entryNode = graph.nodeFromUri(inputUri);
var outputDir = options.outputDir;
var generators = <CodeGenerator>[];
if (options.dumpSrcDir != null) {
@@ -247,9 +267,16 @@ class CompilerServer {
factory CompilerServer(CompilerOptions options) {
var entryPath = path.basename(options.entryPointFile);
- if (path.extension(entryPath) != '.html') {
- print('error: devc in server mode requires an HTML entry point.');
- exit(1);
+ var extension = path.extension(entryPath);
+ bool implicitHtml = false;
Jennifer Messerly 2015/05/13 19:31:55 suggestion: move this into options. It can still b
vsm 2015/05/14 00:04:07 Done.
+ if (extension != '.html') {
+ if (extension == '.dart') {
+ implicitHtml = true;
+ } else {
+ print(
+ 'error: devc in server mode requires an HTML or Dart entry point.');
+ exit(1);
+ }
}
// TODO(sigmund): allow running without a dir, but keep output in memory?
@@ -261,8 +288,9 @@ class CompilerServer {
}
var port = options.port;
var host = options.host;
- var compiler = new Compiler(options);
- return new CompilerServer._(compiler, outDir, host, port, entryPath);
+ var compiler = new Compiler(options, implicitHtml: implicitHtml);
+ return new CompilerServer._(compiler, outDir, host, port,
+ implicitHtml ? Compiler._implicitEntryFile : entryPath);
}
CompilerServer._(
« no previous file with comments | « karma.conf.js ('k') | lib/src/checker/resolver.dart » ('j') | lib/src/in_memory.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698