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

Side by Side Diff: pkg/compiler/lib/src/apiimpl.dart

Issue 1803303002: Move all flags to CompilerOptions (first step to stop passing the compiler to (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library leg_apiimpl; 5 library leg_apiimpl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:package_config/packages.dart'; 10 import 'package:package_config/packages.dart';
(...skipping 12 matching lines...) Expand all
23 import 'compiler.dart'; 23 import 'compiler.dart';
24 import 'diagnostics/diagnostic_listener.dart' show 24 import 'diagnostics/diagnostic_listener.dart' show
25 DiagnosticOptions; 25 DiagnosticOptions;
26 import 'diagnostics/messages.dart' show 26 import 'diagnostics/messages.dart' show
27 Message; 27 Message;
28 import 'elements/elements.dart' as elements; 28 import 'elements/elements.dart' as elements;
29 import 'io/source_file.dart'; 29 import 'io/source_file.dart';
30 import 'platform_configuration.dart' as platform_configuration; 30 import 'platform_configuration.dart' as platform_configuration;
31 import 'script.dart'; 31 import 'script.dart';
32 32
33 const bool forceIncrementalSupport =
34 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');
35
36 /// For every 'dart:' library, a corresponding environment variable is set 33 /// For every 'dart:' library, a corresponding environment variable is set
37 /// to "true". The environment variable's name is the concatenation of 34 /// to "true". The environment variable's name is the concatenation of
38 /// this prefix and the name (without the 'dart:'. 35 /// this prefix and the name (without the 'dart:'.
39 /// 36 ///
40 /// For example 'dart:html' has the environment variable 'dart.library.html' set 37 /// For example 'dart:html' has the environment variable 'dart.library.html' set
41 /// to "true". 38 /// to "true".
42 const String dartLibraryEnvironmentPrefix = 'dart.library.'; 39 const String dartLibraryEnvironmentPrefix = 'dart.library.';
43 40
44 /// Locations of the platform descriptor files relative to the library root.
45 const String _clientPlatform = "lib/dart_client.platform";
46 const String _serverPlatform = "lib/dart_server.platform";
47 const String _sharedPlatform = "lib/dart_shared.platform";
48 const String _dart2dartPlatform = "lib/dart2dart.platform";
49 41
50 /// Implements the [Compiler] using a [api.CompilerInput] for supplying the 42 /// Implements the [Compiler] using a [api.CompilerInput] for supplying the
51 /// sources. 43 /// sources.
52 class CompilerImpl extends Compiler { 44 class CompilerImpl extends Compiler {
53 api.CompilerInput provider; 45 api.CompilerInput provider;
54 api.CompilerDiagnostics handler; 46 api.CompilerDiagnostics handler;
55 final Uri platformConfigUri;
56 final Uri packageConfig;
57 final Uri packageRoot;
58 final api.PackagesDiscoveryProvider packagesDiscoveryProvider;
59 Packages packages; 47 Packages packages;
60 List<String> options;
61 Map<String, dynamic> environment;
62 bool mockableLibraryUsed = false; 48 bool mockableLibraryUsed = false;
63 49
64 /// A mapping of the dart: library-names to their location. 50 /// A mapping of the dart: library-names to their location.
65 /// 51 ///
66 /// Initialized in [setupSdk]. 52 /// Initialized in [setupSdk].
67 Map<String, Uri> sdkLibraries; 53 Map<String, Uri> sdkLibraries;
68 54
69 GenericTask userHandlerTask; 55 GenericTask userHandlerTask;
70 GenericTask userProviderTask; 56 GenericTask userProviderTask;
71 GenericTask userPackagesDiscoveryTask; 57 GenericTask userPackagesDiscoveryTask;
72 58
73 Uri get libraryRoot => platformConfigUri.resolve("."); 59 Uri get libraryRoot => options.platformConfigUri.resolve(".");
74 60
75 CompilerImpl(this.provider, 61 CompilerImpl(this.provider, api.CompilerOutput outputProvider,
76 api.CompilerOutput outputProvider, 62 this.handler, api.CompilerOptions options)
77 this.handler, 63 : super(options: options, outputProvider: outputProvider) {
78 Uri libraryRoot,
79 this.packageRoot,
80 List<String> options,
81 this.environment,
82 [this.packageConfig,
83 this.packagesDiscoveryProvider])
84 : this.options = options,
85 this.platformConfigUri = resolvePlatformConfig(libraryRoot, options),
86 super(
87 outputProvider: outputProvider,
88 enableTypeAssertions: hasOption(options, Flags.enableCheckedMode),
89 enableUserAssertions: hasOption(options, Flags.enableCheckedMode),
90 trustTypeAnnotations:
91 hasOption(options, Flags.trustTypeAnnotations),
92 trustPrimitives:
93 hasOption(options, Flags.trustPrimitives),
94 trustJSInteropTypeAnnotations:
95 hasOption(options, Flags.trustJSInteropTypeAnnotations),
96 enableMinification: hasOption(options, Flags.minify),
97 useFrequencyNamer:
98 !hasOption(options, Flags.noFrequencyBasedMinification),
99 preserveUris: hasOption(options, Flags.preserveUris),
100 enableNativeLiveTypeAnalysis:
101 !hasOption(options, Flags.disableNativeLiveTypeAnalysis),
102 emitJavaScript: !(hasOption(options, '--output-type=dart') ||
103 hasOption(options, '--output-type=dart-multi')),
104 dart2dartMultiFile: hasOption(options, '--output-type=dart-multi'),
105 generateSourceMap: !hasOption(options, Flags.noSourceMaps),
106 analyzeAllFlag: hasOption(options, Flags.analyzeAll),
107 analyzeOnly: hasOption(options, Flags.analyzeOnly),
108 analyzeMain: hasOption(options, Flags.analyzeMain),
109 analyzeSignaturesOnly:
110 hasOption(options, Flags.analyzeSignaturesOnly),
111 strips: extractCsvOption(options, '--force-strip='),
112 disableTypeInferenceFlag:
113 hasOption(options, Flags.disableTypeInference),
114 preserveComments: hasOption(options, Flags.preserveComments),
115 useCpsIr: hasOption(options, Flags.useCpsIr),
116 verbose: hasOption(options, Flags.verbose),
117 sourceMapUri: extractUriOption(options, '--source-map='),
118 outputUri: extractUriOption(options, '--out='),
119 deferredMapUri: extractUriOption(options, '--deferred-map='),
120 dumpInfo: hasOption(options, Flags.dumpInfo),
121 buildId: extractStringOption(
122 options, '--build-id=',
123 "build number could not be determined"),
124 useContentSecurityPolicy:
125 hasOption(options, Flags.useContentSecurityPolicy),
126 useStartupEmitter: hasOption(options, Flags.fastStartup),
127 enableConditionalDirectives:
128 hasOption(options, Flags.conditionalDirectives),
129 useNewSourceInfo: hasOption(options, Flags.useNewSourceInfo),
130 hasIncrementalSupport:
131 forceIncrementalSupport ||
132 hasOption(options, Flags.incrementalSupport),
133 diagnosticOptions: new DiagnosticOptions(
134 suppressWarnings: hasOption(options, Flags.suppressWarnings),
135 fatalWarnings: hasOption(options, Flags.fatalWarnings),
136 suppressHints: hasOption(options, Flags.suppressHints),
137 terseDiagnostics: hasOption(options, Flags.terse),
138 shownPackageWarnings: extractOptionalCsvOption(
139 options, Flags.showPackageWarnings)),
140 enableExperimentalMirrors:
141 hasOption(options, Flags.enableExperimentalMirrors),
142 enableAssertMessage:
143 hasOption(options, Flags.enableAssertMessage),
144 generateCodeWithCompileTimeErrors:
145 hasOption(options, Flags.generateCodeWithCompileTimeErrors),
146 testMode: hasOption(options, Flags.testMode),
147 allowNativeExtensions:
148 hasOption(options, Flags.allowNativeExtensions)) {
149 tasks.addAll([ 64 tasks.addAll([
150 userHandlerTask = new GenericTask('Diagnostic handler', this), 65 userHandlerTask = new GenericTask('Diagnostic handler', this),
151 userProviderTask = new GenericTask('Input provider', this), 66 userProviderTask = new GenericTask('Input provider', this),
152 userPackagesDiscoveryTask = 67 userPackagesDiscoveryTask =
153 new GenericTask('Package discovery', this), 68 new GenericTask('Package discovery', this),
154 ]); 69 ]);
155 if (libraryRoot == null) {
156 throw new ArgumentError("[libraryRoot] is null.");
157 }
158 if (!libraryRoot.path.endsWith("/")) {
159 throw new ArgumentError("[libraryRoot] must end with a /.");
160 }
161 if (packageRoot != null && packageConfig != null) {
162 throw new ArgumentError("Only one of [packageRoot] or [packageConfig] "
163 "may be given.");
164 }
165 if (packageRoot != null && !packageRoot.path.endsWith("/")) {
166 throw new ArgumentError("[packageRoot] must end with a /.");
167 }
168 if (!analyzeOnly) {
169 if (allowNativeExtensions) {
170 throw new ArgumentError(
171 "${Flags.allowNativeExtensions} is only supported in combination "
172 "with ${Flags.analyzeOnly}");
173 }
174 }
175 } 70 }
176 71
177 static String extractStringOption(List<String> options,
178 String prefix,
179 String defaultValue) {
180 for (String option in options) {
181 if (option.startsWith(prefix)) {
182 return option.substring(prefix.length);
183 }
184 }
185 return defaultValue;
186 }
187
188 static Uri extractUriOption(List<String> options, String prefix) {
189 var option = extractStringOption(options, prefix, null);
190 return (option == null) ? null : Uri.parse(option);
191 }
192
193 // CSV: Comma separated values.
194 static List<String> extractCsvOption(List<String> options, String prefix) {
195 for (String option in options) {
196 if (option.startsWith(prefix)) {
197 return option.substring(prefix.length).split(',');
198 }
199 }
200 return const <String>[];
201 }
202
203 /// Extract list of comma separated values provided for [flag]. Returns an
204 /// empty list if [option] contain [flag] without arguments. Returns `null` if
205 /// [option] doesn't contain [flag] with or without arguments.
206 static List<String> extractOptionalCsvOption(
207 List<String> options, String flag) {
208 String prefix = '$flag=';
209 for (String option in options) {
210 if (option == flag) {
211 return const <String>[];
212 }
213 if (option.startsWith(flag)) {
214 return option.substring(prefix.length).split(',');
215 }
216 }
217 return null;
218 }
219
220 static Uri resolvePlatformConfig(Uri libraryRoot,
221 List<String> options) {
222 String platformConfigPath =
223 extractStringOption(options, "--platform-config=", null);
224 if (platformConfigPath != null) {
225 return libraryRoot.resolve(platformConfigPath);
226 } else if (hasOption(options, '--output-type=dart')) {
227 return libraryRoot.resolve(_dart2dartPlatform);
228 } else {
229 Iterable<String> categories = extractCsvOption(options, '--categories=');
230 if (categories.length == 0) {
231 return libraryRoot.resolve(_clientPlatform);
232 }
233 assert(categories.length <= 2);
234 if (categories.contains("Client")) {
235 if (categories.contains("Server")) {
236 return libraryRoot.resolve(_sharedPlatform);
237 }
238 return libraryRoot.resolve(_clientPlatform);
239 }
240 assert(categories.contains("Server"));
241 return libraryRoot.resolve(_serverPlatform);
242 }
243 }
244
245 static bool hasOption(List<String> options, String option) {
246 return options.indexOf(option) >= 0;
247 }
248 72
249 void log(message) { 73 void log(message) {
250 callUserHandler( 74 callUserHandler(
251 null, null, null, null, message, api.Diagnostic.VERBOSE_INFO); 75 null, null, null, null, message, api.Diagnostic.VERBOSE_INFO);
252 } 76 }
253 77
254 /// See [Compiler.translateResolvedUri]. 78 /// See [Compiler.translateResolvedUri].
255 Uri translateResolvedUri(elements.LibraryElement importingLibrary, 79 Uri translateResolvedUri(elements.LibraryElement importingLibrary,
256 Uri resolvedUri, Spannable spannable) { 80 Uri resolvedUri, Spannable spannable) {
257 if (resolvedUri.scheme == 'dart') { 81 if (resolvedUri.scheme == 'dart') {
(...skipping 28 matching lines...) Expand all
286 node, 110 node,
287 MessageKind.READ_SCRIPT_ERROR, 111 MessageKind.READ_SCRIPT_ERROR,
288 {'uri': readableUri, 'exception': exception}); 112 {'uri': readableUri, 'exception': exception});
289 }); 113 });
290 } 114 }
291 } 115 }
292 116
293 Uri resourceUri = translateUri(node, readableUri); 117 Uri resourceUri = translateUri(node, readableUri);
294 if (resourceUri == null) return synthesizeScript(node, readableUri); 118 if (resourceUri == null) return synthesizeScript(node, readableUri);
295 if (resourceUri.scheme == 'dart-ext') { 119 if (resourceUri.scheme == 'dart-ext') {
296 if (!allowNativeExtensions) { 120 if (!options.allowNativeExtensions) {
297 reporter.withCurrentElement(element, () { 121 reporter.withCurrentElement(element, () {
298 reporter.reportErrorMessage( 122 reporter.reportErrorMessage(
299 node, MessageKind.DART_EXT_NOT_SUPPORTED); 123 node, MessageKind.DART_EXT_NOT_SUPPORTED);
300 }); 124 });
301 } 125 }
302 return synthesizeScript(node, readableUri); 126 return synthesizeScript(node, readableUri);
303 } 127 }
304 128
305 // TODO(johnniwinther): Wrap the result from [provider] in a specialized 129 // TODO(johnniwinther): Wrap the result from [provider] in a specialized
306 // [Future] to ensure that we never execute an asynchronous action without 130 // [Future] to ensure that we never execute an asynchronous action without
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 * See [LibraryLoader] for terminology on URIs. 167 * See [LibraryLoader] for terminology on URIs.
344 */ 168 */
345 Uri translateUri(Spannable node, Uri readableUri) { 169 Uri translateUri(Spannable node, Uri readableUri) {
346 switch (readableUri.scheme) { 170 switch (readableUri.scheme) {
347 case 'package': return translatePackageUri(node, readableUri); 171 case 'package': return translatePackageUri(node, readableUri);
348 default: return readableUri; 172 default: return readableUri;
349 } 173 }
350 } 174 }
351 175
352 /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative 176 /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative
353 /// to [platformConfigUri] according to the information in the file at 177 /// to `options.platformConfigUri` according to the information in the file at
354 /// [platformConfigUri]. 178 /// `options.platformConfigUri`.
355 /// 179 ///
356 /// Returns null and emits an error if the library could not be found or 180 /// Returns null and emits an error if the library could not be found or
357 /// imported into [importingLibrary]. 181 /// imported into [importingLibrary].
358 /// 182 ///
359 /// Internal libraries (whose name starts with '_') can be only resolved if 183 /// Internal libraries (whose name starts with '_') can be only resolved if
360 /// [importingLibrary] is a platform or patch library. 184 /// [importingLibrary] is a platform or patch library.
361 Uri translateDartUri(elements.LibraryElement importingLibrary, 185 Uri translateDartUri(elements.LibraryElement importingLibrary,
362 Uri resolvedUri, Spannable spannable) { 186 Uri resolvedUri, Spannable spannable) {
363 187
364 Uri location = lookupLibraryUri(resolvedUri.path); 188 Uri location = lookupLibraryUri(resolvedUri.path);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 if (packages == null) { 268 if (packages == null) {
445 setupFutures.add(setupPackages(uri)); 269 setupFutures.add(setupPackages(uri));
446 } 270 }
447 return Future.wait(setupFutures).then((_) { 271 return Future.wait(setupFutures).then((_) {
448 return super.analyzeUri(uri, 272 return super.analyzeUri(uri,
449 skipLibraryWithPartOfTag: skipLibraryWithPartOfTag); 273 skipLibraryWithPartOfTag: skipLibraryWithPartOfTag);
450 }); 274 });
451 } 275 }
452 276
453 Future setupPackages(Uri uri) { 277 Future setupPackages(Uri uri) {
454 if (packageRoot != null) { 278 if (options.packageRoot != null) {
455 // Use "non-file" packages because the file version requires a [Directory] 279 // Use "non-file" packages because the file version requires a [Directory]
456 // and we can't depend on 'dart:io' classes. 280 // and we can't depend on 'dart:io' classes.
457 packages = new NonFilePackagesDirectoryPackages(packageRoot); 281 packages = new NonFilePackagesDirectoryPackages(options.packageRoot);
458 } else if (packageConfig != null) { 282 } else if (options.packageConfig != null) {
459 return callUserProvider(packageConfig).then((packageConfigContents) { 283 return callUserProvider(options.packageConfig).then((configContents) {
460 if (packageConfigContents is String) { 284 if (configContents is String) {
461 packageConfigContents = UTF8.encode(packageConfigContents); 285 configContents = UTF8.encode(configContents);
462 } 286 }
463 // The input provider may put a trailing 0 byte when it reads a source 287 // The input provider may put a trailing 0 byte when it reads a source
464 // file, which confuses the package config parser. 288 // file, which confuses the package config parser.
465 if (packageConfigContents.length > 0 && 289 if (configContents.length > 0 &&
466 packageConfigContents.last == 0) { 290 configContents.last == 0) {
467 packageConfigContents = packageConfigContents.sublist( 291 configContents = configContents.sublist(0, configContents.length - 1);
468 0, packageConfigContents.length - 1);
469 } 292 }
470 packages = 293 packages = new MapPackages(
471 new MapPackages(pkgs.parse(packageConfigContents, packageConfig)); 294 pkgs.parse(configContents, options.packageConfig));
472 }).catchError((error) { 295 }).catchError((error) {
473 reporter.reportErrorMessage( 296 reporter.reportErrorMessage(
474 NO_LOCATION_SPANNABLE, 297 NO_LOCATION_SPANNABLE,
475 MessageKind.INVALID_PACKAGE_CONFIG, 298 MessageKind.INVALID_PACKAGE_CONFIG,
476 {'uri': packageConfig, 'exception': error}); 299 {'uri': options.packageConfig, 'exception': error});
477 packages = Packages.noPackages; 300 packages = Packages.noPackages;
478 }); 301 });
479 } else { 302 } else {
480 if (packagesDiscoveryProvider == null) { 303 if (options.packagesDiscoveryProvider == null) {
481 packages = Packages.noPackages; 304 packages = Packages.noPackages;
482 } else { 305 } else {
483 return callUserPackagesDiscovery(uri).then((p) { 306 return callUserPackagesDiscovery(uri).then((p) {
484 packages = p; 307 packages = p;
485 }); 308 });
486 } 309 }
487 } 310 }
488 return new Future.value(); 311 return new Future.value();
489 } 312 }
490 313
491 Future<Null> setupSdk() { 314 Future<Null> setupSdk() {
492 if (sdkLibraries == null) { 315 if (sdkLibraries == null) {
493 return platform_configuration.load(platformConfigUri, provider) 316 return platform_configuration.load(options.platformConfigUri, provider)
494 .then((Map<String, Uri> mapping) { 317 .then((Map<String, Uri> mapping) {
495 sdkLibraries = mapping; 318 sdkLibraries = mapping;
496 }); 319 });
497 } else { 320 } else {
498 // The incremental compiler sets up the sdk before run. 321 // The incremental compiler sets up the sdk before run.
499 // Therefore this will be called a second time. 322 // Therefore this will be called a second time.
500 return new Future.value(null); 323 return new Future.value(null);
501 } 324 }
502 } 325 }
503 326
504 Future<bool> run(Uri uri) { 327 Future<bool> run(Uri uri) {
505 log('Using platform configuration at ${platformConfigUri}'); 328 log('Using platform configuration at ${options.platformConfigUri}');
506 329
507 return Future.wait([setupSdk(), setupPackages(uri)]).then((_) { 330 return Future.wait([setupSdk(), setupPackages(uri)]).then((_) {
508 assert(sdkLibraries != null); 331 assert(sdkLibraries != null);
509 assert(packages != null); 332 assert(packages != null);
510 333
511 return super.run(uri).then((bool success) { 334 return super.run(uri).then((bool success) {
512 int cumulated = 0; 335 int cumulated = 0;
513 for (final task in tasks) { 336 for (final task in tasks) {
514 int elapsed = task.timing; 337 int elapsed = task.timing;
515 if (elapsed != 0) { 338 if (elapsed != 0) {
(...skipping 29 matching lines...) Expand all
545 SourceSpan span = diagnosticMessage.sourceSpan; 368 SourceSpan span = diagnosticMessage.sourceSpan;
546 Message message = diagnosticMessage.message; 369 Message message = diagnosticMessage.message;
547 if (span == null || span.uri == null) { 370 if (span == null || span.uri == null) {
548 callUserHandler(message, null, null, null, '$message', kind); 371 callUserHandler(message, null, null, null, '$message', kind);
549 } else { 372 } else {
550 callUserHandler( 373 callUserHandler(
551 message, span.uri, span.begin, span.end, '$message', kind); 374 message, span.uri, span.begin, span.end, '$message', kind);
552 } 375 }
553 } 376 }
554 377
555 bool get isMockCompilation { 378 bool get isMockCompilation =>
556 return mockableLibraryUsed 379 mockableLibraryUsed && options.allowMockCompilation;
557 && (options.indexOf(Flags.allowMockCompilation) != -1);
558 }
559 380
560 void callUserHandler(Message message, Uri uri, int begin, int end, 381 void callUserHandler(Message message, Uri uri, int begin, int end,
561 String text, api.Diagnostic kind) { 382 String text, api.Diagnostic kind) {
562 try { 383 try {
563 userHandlerTask.measure(() { 384 userHandlerTask.measure(() {
564 handler.report(message, uri, begin, end, text, kind); 385 handler.report(message, uri, begin, end, text, kind);
565 }); 386 });
566 } catch (ex, s) { 387 } catch (ex, s) {
567 diagnoseCrashInUserCode( 388 diagnoseCrashInUserCode(
568 'Uncaught exception in diagnostic handler', ex, s); 389 'Uncaught exception in diagnostic handler', ex, s);
569 rethrow; 390 rethrow;
570 } 391 }
571 } 392 }
572 393
573 Future callUserProvider(Uri uri) { 394 Future callUserProvider(Uri uri) {
574 try { 395 try {
575 return userProviderTask.measure(() => provider.readFromUri(uri)); 396 return userProviderTask.measure(() => provider.readFromUri(uri));
576 } catch (ex, s) { 397 } catch (ex, s) {
577 diagnoseCrashInUserCode('Uncaught exception in input provider', ex, s); 398 diagnoseCrashInUserCode('Uncaught exception in input provider', ex, s);
578 rethrow; 399 rethrow;
579 } 400 }
580 } 401 }
581 402
582 Future<Packages> callUserPackagesDiscovery(Uri uri) { 403 Future<Packages> callUserPackagesDiscovery(Uri uri) {
583 try { 404 try {
584 return userPackagesDiscoveryTask.measure( 405 return userPackagesDiscoveryTask.measure(
585 () => packagesDiscoveryProvider(uri)); 406 () => options.packagesDiscoveryProvider(uri));
586 } catch (ex, s) { 407 } catch (ex, s) {
587 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); 408 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s);
588 rethrow; 409 rethrow;
589 } 410 }
590 } 411 }
591 412
592 fromEnvironment(String name) { 413 fromEnvironment(String name) {
593 assert(invariant(NO_LOCATION_SPANNABLE, 414 assert(invariant(NO_LOCATION_SPANNABLE,
594 sdkLibraries != null, message: "setupSdk() has not been run")); 415 sdkLibraries != null, message: "setupSdk() has not been run"));
595 416
596 var result = environment[name]; 417 var result = options.environment[name];
597 if (result != null || environment.containsKey(name)) return result; 418 if (result != null || options.environment.containsKey(name)) return result;
598 if (!name.startsWith(dartLibraryEnvironmentPrefix)) return null; 419 if (!name.startsWith(dartLibraryEnvironmentPrefix)) return null;
599 420
600 String libraryName = name.substring(dartLibraryEnvironmentPrefix.length); 421 String libraryName = name.substring(dartLibraryEnvironmentPrefix.length);
601 422
602 // Private libraries are not exposed to the users. 423 // Private libraries are not exposed to the users.
603 if (libraryName.startsWith("_")) return null; 424 if (libraryName.startsWith("_")) return null;
604 425
605 if (sdkLibraries.containsKey(libraryName)) { 426 if (sdkLibraries.containsKey(libraryName)) {
606 // Dart2js always "supports" importing 'dart:mirrors' but will abort 427 // Dart2js always "supports" importing 'dart:mirrors' but will abort
607 // the compilation at a later point if the backend doesn't support 428 // the compilation at a later point if the backend doesn't support
608 // mirrors. In this case 'mirrors' should not be in the environment. 429 // mirrors. In this case 'mirrors' should not be in the environment.
609 if (libraryName == 'mirrors') { 430 if (libraryName == 'mirrors') {
610 return backend.supportsReflection ? "true" : null; 431 return backend.supportsReflection ? "true" : null;
611 } 432 }
612 return "true"; 433 return "true";
613 } 434 }
614 return null; 435 return null;
615 } 436 }
616 437
617 Uri lookupLibraryUri(String libraryName) { 438 Uri lookupLibraryUri(String libraryName) {
618 assert(invariant(NO_LOCATION_SPANNABLE, 439 assert(invariant(NO_LOCATION_SPANNABLE,
619 sdkLibraries != null, message: "setupSdk() has not been run")); 440 sdkLibraries != null, message: "setupSdk() has not been run"));
620 return sdkLibraries[libraryName]; 441 return sdkLibraries[libraryName];
621 } 442 }
622 443
623 Uri resolvePatchUri(String libraryName) { 444 Uri resolvePatchUri(String libraryName) {
624 return backend.resolvePatchUri(libraryName, platformConfigUri); 445 return backend.resolvePatchUri(libraryName, options.platformConfigUri);
625 } 446 }
626 } 447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698