@@ -53,7 +53,7 @@ abstract class AbstractCompiler {
53
53
class Compiler implements AbstractCompiler {
54
54
final CompilerOptions options;
55
55
final AnalysisContext context;
56
- final CheckerReporter _reporter;
56
+ final CompilerReporter _reporter;
57
57
final TypeRules rules;
58
58
final CodeChecker _checker;
59
59
final SourceNode _entryNode;
@@ -63,24 +63,29 @@ class Compiler implements AbstractCompiler {
63
63
bool _failure = false ;
64
64
65
65
factory Compiler (CompilerOptions options,
66
- {AnalysisContext context, CheckerReporter reporter}) {
67
- if (context == null ) context = createAnalysisContext (options);
66
+ {AnalysisContext context, CompilerReporter reporter}) {
67
+ var strongOpts = options.strongOptions;
68
+ var sourceOpts = options.sourceOptions;
69
+ if (context == null ) {
70
+ context = createAnalysisContextWithSources (strongOpts, sourceOpts);
71
+ }
68
72
69
73
if (reporter == null ) {
70
74
reporter = options.dumpInfo
71
75
? new SummaryReporter (context, options.logLevel)
72
76
: new LogReporter (context, useColors: options.useColors);
73
77
}
74
78
var graph = new SourceGraph (context, reporter, options);
75
- var rules = new RestrictedRules (context.typeProvider, options: options);
76
- var checker = new CodeChecker (rules, reporter, options);
79
+ var rules = new RestrictedRules (context.typeProvider,
80
+ options: options.strongOptions);
81
+ var checker = new CodeChecker (rules, reporter, strongOpts);
77
82
78
- var inputFile = options .entryPointFile;
83
+ var inputFile = sourceOpts .entryPointFile;
79
84
var inputUri = inputFile.startsWith ('dart:' ) ||
80
85
inputFile.startsWith ('package:' )
81
86
? Uri .parse (inputFile)
82
- : new Uri .file (path.absolute (options .useImplicitHtml
83
- ? ResolverOptions .implicitHtmlFile
87
+ : new Uri .file (path.absolute (sourceOpts .useImplicitHtml
88
+ ? SourceResolverOptions .implicitHtmlFile
84
89
: inputFile));
85
90
var entryNode = graph.nodeFromUri (inputUri);
86
91
@@ -90,14 +95,15 @@ class Compiler implements AbstractCompiler {
90
95
91
96
Compiler ._(this .options, this .context, this ._reporter, this .rules,
92
97
this ._checker, this ._entryNode) {
93
- if (options. outputDir != null ) {
98
+ if (outputDir != null ) {
94
99
_generators.add (new JSGenerator (this ));
95
100
}
96
101
// TODO(sigmund): refactor to support hashing of the dart output?
97
102
_hashing = options.enableHashing && _generators.length == 1 ;
98
103
}
99
104
100
105
Uri get entryPointUri => _entryNode.uri;
106
+ String get outputDir => options.codegenOptions.outputDir;
101
107
102
108
bool _buildSource (SourceNode node) {
103
109
if (node is HtmlSourceNode ) {
@@ -116,7 +122,7 @@ class Compiler implements AbstractCompiler {
116
122
}
117
123
118
124
void _buildHtmlFile (HtmlSourceNode node) {
119
- if (options. outputDir == null ) return ;
125
+ if (outputDir == null ) return ;
120
126
var uri = node.source.uri;
121
127
_reporter.enterHtml (uri);
122
128
var output = generateEntryHtml (node, options);
@@ -126,18 +132,18 @@ class Compiler implements AbstractCompiler {
126
132
}
127
133
_reporter.leaveHtml ();
128
134
var filename = path.basename (node.uri.path);
129
- String outputFile = path.join (options. outputDir, filename);
135
+ String outputFile = path.join (outputDir, filename);
130
136
new File (outputFile).writeAsStringSync (output);
131
137
}
132
138
133
139
void _buildResourceFile (ResourceSourceNode node) {
134
140
// ResourceSourceNodes files that just need to be copied over to the output
135
141
// location. These can be external dependencies or pieces of the
136
142
// dev_compiler runtime.
137
- if (options. outputDir == null ) return ;
143
+ if (outputDir == null ) return ;
138
144
var filepath = resourceOutputPath (node.uri, _entryNode.uri);
139
145
assert (filepath != null );
140
- filepath = path.join (options. outputDir, filepath);
146
+ filepath = path.join (outputDir, filepath);
141
147
var dir = path.dirname (filepath);
142
148
new Directory (dir).createSync (recursive: true );
143
149
new File .fromUri (node.source.uri).copySync (filepath);
@@ -182,7 +188,7 @@ class Compiler implements AbstractCompiler {
182
188
}
183
189
if (failureInLib) {
184
190
_failure = true ;
185
- if (! options.forceCompile) return ;
191
+ if (! options.codegenOptions. forceCompile) return ;
186
192
}
187
193
188
194
for (var cg in _generators) {
@@ -221,7 +227,7 @@ class Compiler implements AbstractCompiler {
221
227
var time = (clock.elapsedMilliseconds / 1000 ).toStringAsFixed (2 );
222
228
_log.fine ('Compiled ${_libraries .length } libraries in ${time } s\n ' );
223
229
return new CheckerResults (
224
- _libraries, rules, _failure || options.forceCompile);
230
+ _libraries, rules, _failure || options.codegenOptions. forceCompile);
225
231
}
226
232
227
233
void _runAgain () {
@@ -245,7 +251,7 @@ class Compiler implements AbstractCompiler {
245
251
var result = (_reporter as SummaryReporter ).result;
246
252
if (! options.serverMode) print (summaryToString (result));
247
253
var filepath = options.serverMode
248
- ? path.join (options. outputDir, 'messages.json' )
254
+ ? path.join (outputDir, 'messages.json' )
249
255
: options.dumpInfoFile;
250
256
if (filepath == null ) return ;
251
257
new File (filepath).writeAsStringSync (JSON .encode (result.toJsonMap ()));
@@ -260,15 +266,15 @@ class CompilerServer {
260
266
final String _entryPath;
261
267
262
268
factory CompilerServer (CompilerOptions options) {
263
- var entryPath = path.basename (options.entryPointFile);
269
+ var entryPath = path.basename (options.sourceOptions. entryPointFile);
264
270
var extension = path.extension (entryPath);
265
- if (extension != '.html' && ! options.useImplicitHtml) {
271
+ if (extension != '.html' && ! options.sourceOptions. useImplicitHtml) {
266
272
print ('error: devc in server mode requires an HTML or Dart entry point.' );
267
273
exit (1 );
268
274
}
269
275
270
276
// TODO(sigmund): allow running without a dir, but keep output in memory?
271
- var outDir = options.outputDir;
277
+ var outDir = options.codegenOptions. outputDir;
272
278
if (outDir == null ) {
273
279
print ('error: devc in server mode also requires specifying and '
274
280
'output location for generated code.' );
@@ -283,8 +289,9 @@ class CompilerServer {
283
289
CompilerServer ._(
284
290
Compiler compiler, this .outDir, this .host, this .port, String entryPath)
285
291
: this .compiler = compiler,
286
- this ._entryPath = compiler.options.useImplicitHtml
287
- ? ResolverOptions .implicitHtmlFile
292
+ // TODO(jmesserly): this logic is duplicated in a few places
293
+ this ._entryPath = compiler.options.sourceOptions.useImplicitHtml
294
+ ? SourceResolverOptions .implicitHtmlFile
288
295
: entryPath;
289
296
290
297
Future start () async {
0 commit comments