OLD | NEW |
---|---|
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 library dev_compiler.src.server; | 6 library dev_compiler.src.server; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 19 matching lines...) Expand all Loading... | |
30 import '../info.dart' | 30 import '../info.dart' |
31 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; | 31 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; |
32 import '../options.dart'; | 32 import '../options.dart'; |
33 import '../report.dart'; | 33 import '../report.dart'; |
34 import '../utils.dart'; | 34 import '../utils.dart'; |
35 | 35 |
36 import 'dependency_graph.dart'; | 36 import 'dependency_graph.dart'; |
37 | 37 |
38 /// Encapsulates the logic when the compiler is run as a development server. | 38 /// Encapsulates the logic when the compiler is run as a development server. |
39 class ServerCompiler extends AbstractCompiler { | 39 class ServerCompiler extends AbstractCompiler { |
40 final SourceNode _entryNode; | 40 SourceNode _entryNode; |
41 List<LibraryInfo> _libraries = <LibraryInfo>[]; | 41 List<LibraryInfo> _libraries = <LibraryInfo>[]; |
42 final _generators = <CodeGenerator>[]; | 42 final _generators = <CodeGenerator>[]; |
43 bool _hashing; | 43 bool _hashing; |
44 bool _failure = false; | 44 bool _failure = false; |
45 | 45 |
46 factory ServerCompiler(AnalysisContext context, CompilerOptions options, | 46 factory ServerCompiler(AnalysisContext context, CompilerOptions options, |
47 {AnalysisErrorListener reporter}) { | 47 {AnalysisErrorListener reporter}) { |
48 var srcOpts = options.sourceOptions; | 48 var srcOpts = options.sourceOptions; |
49 var inputFile = options.inputs[0]; | 49 var inputFiles = options.inputs; |
50 var inputUri = | 50 var inputUris = inputFiles.map((String inputFile) => |
51 inputFile.startsWith('dart:') || inputFile.startsWith('package:') | 51 inputFile.startsWith('dart:') || inputFile.startsWith('package:') |
52 ? Uri.parse(inputFile) | 52 ? Uri.parse(inputFile) |
53 : new Uri.file(path.absolute(srcOpts.useImplicitHtml | 53 : new Uri.file(path.absolute(srcOpts.useImplicitHtml |
54 ? SourceResolverOptions.implicitHtmlFile | 54 ? SourceResolverOptions.implicitHtmlFile |
55 : inputFile)); | 55 : inputFile))); |
56 var graph = new SourceGraph(context, reporter, options); | 56 var graph = new SourceGraph(context, reporter, options); |
57 var entryNode = graph.nodeFromUri(inputUri); | 57 var entryNodes = inputUris.map((inputUri) => graph.nodeFromUri(inputUri)); |
58 | 58 |
59 return new ServerCompiler._(context, options, reporter, entryNode); | 59 return new ServerCompiler._(context, options, reporter, graph, entryNodes); |
60 } | 60 } |
61 | 61 |
62 ServerCompiler._(AnalysisContext context, CompilerOptions options, | 62 ServerCompiler._( |
63 AnalysisErrorListener reporter, this._entryNode) | 63 AnalysisContext context, |
64 CompilerOptions options, | |
65 AnalysisErrorListener reporter, | |
66 SourceGraph graph, | |
67 List<SourceNode> entryNodes) | |
64 : super(context, options, reporter) { | 68 : super(context, options, reporter) { |
69 _entryNode = entryNodes.length == 1 | |
70 ? entryNodes.first | |
71 : new EntryNode(graph, new Uri.file(inputBaseDir), entryNodes); | |
72 | |
65 if (outputDir != null) { | 73 if (outputDir != null) { |
66 _generators.add(new JSGenerator(this)); | 74 _generators.add(new JSGenerator(this)); |
67 } | 75 } |
68 // TODO(sigmund): refactor to support hashing of the dart output? | 76 // TODO(sigmund): refactor to support hashing of the dart output? |
69 _hashing = options.enableHashing && _generators.length == 1; | 77 _hashing = options.enableHashing && _generators.length == 1; |
70 } | 78 } |
71 | 79 |
72 Uri get entryPointUri => _entryNode.uri; | |
73 | |
74 CheckerResults run() { | 80 CheckerResults run() { |
75 var clock = new Stopwatch()..start(); | 81 var clock = new Stopwatch()..start(); |
76 | 82 |
77 // TODO(sigmund): we are missing a couple failures here. The | 83 // TODO(sigmund): we are missing a couple failures here. The |
78 // dependency_graph now detects broken imports or unsupported features | 84 // dependency_graph now detects broken imports or unsupported features |
79 // like more than one script tag (see .severe messages in | 85 // like more than one script tag (see .severe messages in |
80 // dependency_graph.dart). Such failures should be reported back | 86 // dependency_graph.dart). Such failures should be reported back |
81 // here so we can mark failure=true in the CheckerResults. | 87 // here so we can mark failure=true in the CheckerResults. |
82 rebuild(_entryNode, _buildSource); | 88 rebuild(_entryNode, _buildSource); |
83 _dumpInfoIfRequested(); | 89 _dumpInfoIfRequested(); |
(...skipping 22 matching lines...) Expand all Loading... | |
106 } | 112 } |
107 | 113 |
108 void _buildHtmlFile(HtmlSourceNode node) { | 114 void _buildHtmlFile(HtmlSourceNode node) { |
109 if (outputDir == null) return; | 115 if (outputDir == null) return; |
110 var output = generateEntryHtml(node, this); | 116 var output = generateEntryHtml(node, this); |
111 if (output == null) { | 117 if (output == null) { |
112 _failure = true; | 118 _failure = true; |
113 return; | 119 return; |
114 } | 120 } |
115 | 121 |
116 var filename = path.basename(node.uri.path); | 122 var filepath = |
117 String outputFile = path.join(outputDir, filename); | 123 resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir); |
118 new File(outputFile).writeAsStringSync(output); | 124 String outputFile = path.join(outputDir, filepath); |
125 var file = new File(outputFile)..createSync(recursive: true); | |
126 file.writeAsStringSync(output); | |
Jennifer Messerly
2016/01/29 16:49:49
same comment, it'd be nice to go all in on the cas
vsm
2016/01/29 18:13:51
Done.
| |
119 } | 127 } |
120 | 128 |
121 void _buildResourceFile(ResourceSourceNode node) { | 129 void _buildResourceFile(ResourceSourceNode node) { |
122 // 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 |
123 // location. These can be external dependencies or pieces of the | 131 // location. These can be external dependencies or pieces of the |
124 // dev_compiler runtime. | 132 // dev_compiler runtime. |
125 if (outputDir == null) return; | 133 if (outputDir == null) return; |
126 var filepath = | 134 var filepath = |
127 resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir); | 135 resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir); |
128 assert(filepath != null); | 136 assert(filepath != null); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 331 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
324 var src = resolver.resolveAbsolute(uri, actualUri); | 332 var src = resolver.resolveAbsolute(uri, actualUri); |
325 return src.exists() ? src : null; | 333 return src.exists() ? src : null; |
326 } | 334 } |
327 | 335 |
328 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); | 336 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); |
329 } | 337 } |
330 | 338 |
331 final _log = new Logger('dev_compiler.src.server'); | 339 final _log = new Logger('dev_compiler.src.server'); |
332 final _earlyErrorResult = new CheckerResults(const [], true); | 340 final _earlyErrorResult = new CheckerResults(const [], true); |
OLD | NEW |