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

Side by Side Diff: lib/src/server/server.dart

Issue 1645343002: Builds / serves multiple HTML files. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « lib/src/server/dependency_graph.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Development server that compiles Dart to JS on the fly. 5 /// Development server that compiles Dart to JS on the fly.
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 18 matching lines...) Expand all
29 import '../info.dart' 29 import '../info.dart'
30 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; 30 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit;
31 import '../options.dart'; 31 import '../options.dart';
32 import '../report.dart'; 32 import '../report.dart';
33 import '../utils.dart'; 33 import '../utils.dart';
34 34
35 import 'dependency_graph.dart'; 35 import 'dependency_graph.dart';
36 36
37 /// Encapsulates the logic when the compiler is run as a development server. 37 /// Encapsulates the logic when the compiler is run as a development server.
38 class ServerCompiler extends AbstractCompiler { 38 class ServerCompiler extends AbstractCompiler {
39 final SourceNode _entryNode; 39 SourceNode _entryNode;
40 List<LibraryInfo> _libraries = <LibraryInfo>[]; 40 List<LibraryInfo> _libraries = <LibraryInfo>[];
41 final _generators = <CodeGenerator>[]; 41 final _generators = <CodeGenerator>[];
42 bool _hashing; 42 bool _hashing;
43 bool _failure = false; 43 bool _failure = false;
44 44
45 factory ServerCompiler(AnalysisContext context, CompilerOptions options, 45 factory ServerCompiler(AnalysisContext context, CompilerOptions options,
46 {AnalysisErrorListener reporter}) { 46 {AnalysisErrorListener reporter}) {
47 var srcOpts = options.sourceOptions; 47 var srcOpts = options.sourceOptions;
48 var inputFile = options.inputs[0]; 48 var inputFiles = options.inputs;
49 var inputUri = 49 var inputUris = inputFiles.map((String inputFile) =>
50 inputFile.startsWith('dart:') || inputFile.startsWith('package:') 50 inputFile.startsWith('dart:') || inputFile.startsWith('package:')
51 ? Uri.parse(inputFile) 51 ? Uri.parse(inputFile)
52 : new Uri.file(path.absolute(srcOpts.useImplicitHtml 52 : new Uri.file(path.absolute(srcOpts.useImplicitHtml
53 ? SourceResolverOptions.implicitHtmlFile 53 ? SourceResolverOptions.implicitHtmlFile
54 : inputFile)); 54 : inputFile)));
55 var graph = new SourceGraph(context, reporter, options); 55 var graph = new SourceGraph(context, reporter, options);
56 var entryNode = graph.nodeFromUri(inputUri); 56 var entryNodes = inputUris.map((inputUri) => graph.nodeFromUri(inputUri));
57 57
58 return new ServerCompiler._(context, options, reporter, entryNode); 58 return new ServerCompiler._(context, options, reporter, graph, entryNodes);
59 } 59 }
60 60
61 ServerCompiler._(AnalysisContext context, CompilerOptions options, 61 ServerCompiler._(
62 AnalysisErrorListener reporter, this._entryNode) 62 AnalysisContext context,
63 CompilerOptions options,
64 AnalysisErrorListener reporter,
65 SourceGraph graph,
66 List<SourceNode> entryNodes)
63 : super(context, options, reporter) { 67 : super(context, options, reporter) {
68 _entryNode = entryNodes.length == 1
69 ? entryNodes.first
70 : new EntryNode(graph, new Uri.file(inputBaseDir), entryNodes);
71
64 if (outputDir != null) { 72 if (outputDir != null) {
65 _generators.add(new JSGenerator(this)); 73 _generators.add(new JSGenerator(this));
66 } 74 }
67 // TODO(sigmund): refactor to support hashing of the dart output? 75 // TODO(sigmund): refactor to support hashing of the dart output?
68 _hashing = options.enableHashing && _generators.length == 1; 76 _hashing = options.enableHashing && _generators.length == 1;
69 } 77 }
70 78
71 Uri get entryPointUri => _entryNode.uri;
72
73 CheckerResults run() { 79 CheckerResults run() {
74 var clock = new Stopwatch()..start(); 80 var clock = new Stopwatch()..start();
75 81
76 // TODO(sigmund): we are missing a couple failures here. The 82 // TODO(sigmund): we are missing a couple failures here. The
77 // dependency_graph now detects broken imports or unsupported features 83 // dependency_graph now detects broken imports or unsupported features
78 // like more than one script tag (see .severe messages in 84 // like more than one script tag (see .severe messages in
79 // dependency_graph.dart). Such failures should be reported back 85 // dependency_graph.dart). Such failures should be reported back
80 // here so we can mark failure=true in the CheckerResults. 86 // here so we can mark failure=true in the CheckerResults.
81 rebuild(_entryNode, _buildSource); 87 rebuild(_entryNode, _buildSource);
82 _dumpInfoIfRequested(); 88 _dumpInfoIfRequested();
(...skipping 22 matching lines...) Expand all
105 } 111 }
106 112
107 void _buildHtmlFile(HtmlSourceNode node) { 113 void _buildHtmlFile(HtmlSourceNode node) {
108 if (outputDir == null) return; 114 if (outputDir == null) return;
109 var output = generateEntryHtml(node, this); 115 var output = generateEntryHtml(node, this);
110 if (output == null) { 116 if (output == null) {
111 _failure = true; 117 _failure = true;
112 return; 118 return;
113 } 119 }
114 120
115 var filename = path.basename(node.uri.path); 121 var filepath =
116 String outputFile = path.join(outputDir, filename); 122 resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir);
117 new File(outputFile).writeAsStringSync(output); 123 String outputFile = path.join(outputDir, filepath);
124 new File(outputFile)
125 ..createSync(recursive: true)
126 ..writeAsStringSync(output);
118 } 127 }
119 128
120 void _buildResourceFile(ResourceSourceNode node) { 129 void _buildResourceFile(ResourceSourceNode node) {
121 // ResourceSourceNodes files that just need to be copied over to the output 130 // ResourceSourceNodes files that just need to be copied over to the output
122 // location. These can be external dependencies or pieces of the 131 // location. These can be external dependencies or pieces of the
123 // dev_compiler runtime. 132 // dev_compiler runtime.
124 if (outputDir == null) return; 133 if (outputDir == null) return;
125 var filepath = 134 var filepath =
126 resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir); 135 resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir);
127 assert(filepath != null); 136 assert(filepath != null);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 331 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
323 var src = resolver.resolveAbsolute(uri, actualUri); 332 var src = resolver.resolveAbsolute(uri, actualUri);
324 return src.exists() ? src : null; 333 return src.exists() ? src : null;
325 } 334 }
326 335
327 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); 336 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source);
328 } 337 }
329 338
330 final _log = new Logger('dev_compiler.src.server'); 339 final _log = new Logger('dev_compiler.src.server');
331 final _earlyErrorResult = new CheckerResults(const [], true); 340 final _earlyErrorResult = new CheckerResults(const [], true);
OLDNEW
« no previous file with comments | « lib/src/server/dependency_graph.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698