| OLD | NEW |
| 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 '../compiler.dart' as api; | 10 import '../compiler_new.dart' as api; |
| 11 import 'dart2jslib.dart' as leg; | 11 import 'dart2jslib.dart' as leg; |
| 12 import 'tree/tree.dart' as tree; | 12 import 'tree/tree.dart' as tree; |
| 13 import 'elements/elements.dart' as elements; | 13 import 'elements/elements.dart' as elements; |
| 14 import 'package:sdk_library_metadata/libraries.dart' hide LIBRARIES; | 14 import 'package:sdk_library_metadata/libraries.dart' hide LIBRARIES; |
| 15 import 'package:sdk_library_metadata/libraries.dart' as library_info show LIBRAR
IES; | 15 import 'package:sdk_library_metadata/libraries.dart' as library_info show LIBRAR
IES; |
| 16 import 'io/source_file.dart'; | 16 import 'io/source_file.dart'; |
| 17 import 'package:package_config/packages.dart'; | 17 import 'package:package_config/packages.dart'; |
| 18 import 'package:package_config/packages_file.dart' as pkgs; | 18 import 'package:package_config/packages_file.dart' as pkgs; |
| 19 import 'package:package_config/src/packages_impl.dart' | 19 import 'package:package_config/src/packages_impl.dart' |
| 20 show NonFilePackagesDirectoryPackages, MapPackages; | 20 show NonFilePackagesDirectoryPackages, MapPackages; |
| 21 import 'package:package_config/src/util.dart' show checkValidPackageUri; | 21 import 'package:package_config/src/util.dart' show checkValidPackageUri; |
| 22 | 22 |
| 23 const bool forceIncrementalSupport = | 23 const bool forceIncrementalSupport = |
| 24 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); | 24 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); |
| 25 | 25 |
| 26 class Compiler extends leg.Compiler { | 26 class Compiler extends leg.Compiler { |
| 27 api.CompilerInputProvider provider; | 27 api.CompilerInput provider; |
| 28 api.DiagnosticHandler handler; | 28 api.CompilerDiagnostics handler; |
| 29 final Uri libraryRoot; | 29 final Uri libraryRoot; |
| 30 final Uri packageConfig; | 30 final Uri packageConfig; |
| 31 final Uri packageRoot; | 31 final Uri packageRoot; |
| 32 final api.PackagesDiscoveryProvider packagesDiscoveryProvider; | 32 final api.PackagesDiscoveryProvider packagesDiscoveryProvider; |
| 33 Packages packages; | 33 Packages packages; |
| 34 List<String> options; | 34 List<String> options; |
| 35 Map<String, dynamic> environment; | 35 Map<String, dynamic> environment; |
| 36 bool mockableLibraryUsed = false; | 36 bool mockableLibraryUsed = false; |
| 37 final Set<String> allowedLibraryCategories; | 37 final Set<String> allowedLibraryCategories; |
| 38 | 38 |
| 39 leg.GenericTask userHandlerTask; | 39 leg.GenericTask userHandlerTask; |
| 40 leg.GenericTask userProviderTask; | 40 leg.GenericTask userProviderTask; |
| 41 leg.GenericTask userPackagesDiscoveryTask; | 41 leg.GenericTask userPackagesDiscoveryTask; |
| 42 | 42 |
| 43 Compiler(this.provider, | 43 Compiler(this.provider, |
| 44 api.CompilerOutputProvider outputProvider, | 44 api.CompilerOutput outputProvider, |
| 45 this.handler, | 45 this.handler, |
| 46 this.libraryRoot, | 46 this.libraryRoot, |
| 47 this.packageRoot, | 47 this.packageRoot, |
| 48 List<String> options, | 48 List<String> options, |
| 49 this.environment, | 49 this.environment, |
| 50 [this.packageConfig, | 50 [this.packageConfig, |
| 51 this.packagesDiscoveryProvider]) | 51 this.packagesDiscoveryProvider]) |
| 52 : this.options = options, | 52 : this.options = options, |
| 53 this.allowedLibraryCategories = getAllowedLibraryCategories(options), | 53 this.allowedLibraryCategories = getAllowedLibraryCategories(options), |
| 54 super( | 54 super( |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 String lookupPatchPath(String dartLibraryName) { | 189 String lookupPatchPath(String dartLibraryName) { |
| 190 LibraryInfo info = lookupLibraryInfo(dartLibraryName); | 190 LibraryInfo info = lookupLibraryInfo(dartLibraryName); |
| 191 if (info == null) return null; | 191 if (info == null) return null; |
| 192 if (!info.isDart2jsLibrary) return null; | 192 if (!info.isDart2jsLibrary) return null; |
| 193 String path = info.dart2jsPatchPath; | 193 String path = info.dart2jsPatchPath; |
| 194 if (path == null) return null; | 194 if (path == null) return null; |
| 195 return "lib/$path"; | 195 return "lib/$path"; |
| 196 } | 196 } |
| 197 | 197 |
| 198 void log(message) { | 198 void log(message) { |
| 199 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); | 199 callUserHandler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
| 200 } | 200 } |
| 201 | 201 |
| 202 /// See [leg.Compiler.translateResolvedUri]. | 202 /// See [leg.Compiler.translateResolvedUri]. |
| 203 Uri translateResolvedUri(elements.LibraryElement importingLibrary, | 203 Uri translateResolvedUri(elements.LibraryElement importingLibrary, |
| 204 Uri resolvedUri, tree.Node node) { | 204 Uri resolvedUri, tree.Node node) { |
| 205 if (resolvedUri.scheme == 'dart') { | 205 if (resolvedUri.scheme == 'dart') { |
| 206 return translateDartUri(importingLibrary, resolvedUri, node); | 206 return translateDartUri(importingLibrary, resolvedUri, node); |
| 207 } | 207 } |
| 208 return resolvedUri; | 208 return resolvedUri; |
| 209 } | 209 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 return null; | 366 return null; |
| 367 }); | 367 }); |
| 368 } | 368 } |
| 369 | 369 |
| 370 Future setupPackages(Uri uri) { | 370 Future setupPackages(Uri uri) { |
| 371 if (packageRoot != null) { | 371 if (packageRoot != null) { |
| 372 // Use "non-file" packages because the file version requires a [Directory] | 372 // Use "non-file" packages because the file version requires a [Directory] |
| 373 // and we can't depend on 'dart:io' classes. | 373 // and we can't depend on 'dart:io' classes. |
| 374 packages = new NonFilePackagesDirectoryPackages(packageRoot); | 374 packages = new NonFilePackagesDirectoryPackages(packageRoot); |
| 375 } else if (packageConfig != null) { | 375 } else if (packageConfig != null) { |
| 376 return provider(packageConfig).then((packageConfigContents) { | 376 return callUserProvider(packageConfig).then((packageConfigContents) { |
| 377 if (packageConfigContents is String) { | 377 if (packageConfigContents is String) { |
| 378 packageConfigContents = UTF8.encode(packageConfigContents); | 378 packageConfigContents = UTF8.encode(packageConfigContents); |
| 379 } | 379 } |
| 380 packages = | 380 packages = |
| 381 new MapPackages(pkgs.parse(packageConfigContents, packageConfig)); | 381 new MapPackages(pkgs.parse(packageConfigContents, packageConfig)); |
| 382 }); | 382 }); |
| 383 } else { | 383 } else { |
| 384 if (packagesDiscoveryProvider == null) { | 384 if (packagesDiscoveryProvider == null) { |
| 385 packages = Packages.noPackages; | 385 packages = Packages.noPackages; |
| 386 } else { | 386 } else { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 435 |
| 436 bool get isMockCompilation { | 436 bool get isMockCompilation { |
| 437 return mockableLibraryUsed | 437 return mockableLibraryUsed |
| 438 && (options.indexOf('--allow-mock-compilation') != -1); | 438 && (options.indexOf('--allow-mock-compilation') != -1); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void callUserHandler(Uri uri, int begin, int end, | 441 void callUserHandler(Uri uri, int begin, int end, |
| 442 String message, api.Diagnostic kind) { | 442 String message, api.Diagnostic kind) { |
| 443 try { | 443 try { |
| 444 userHandlerTask.measure(() { | 444 userHandlerTask.measure(() { |
| 445 handler(uri, begin, end, message, kind); | 445 handler.report(uri, begin, end, message, kind); |
| 446 }); | 446 }); |
| 447 } catch (ex, s) { | 447 } catch (ex, s) { |
| 448 diagnoseCrashInUserCode( | 448 diagnoseCrashInUserCode( |
| 449 'Uncaught exception in diagnostic handler', ex, s); | 449 'Uncaught exception in diagnostic handler', ex, s); |
| 450 rethrow; | 450 rethrow; |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| 454 Future callUserProvider(Uri uri) { | 454 Future callUserProvider(Uri uri) { |
| 455 try { | 455 try { |
| 456 return userProviderTask.measure(() => provider(uri)); | 456 return userProviderTask.measure(() => provider.readFromUri(uri)); |
| 457 } catch (ex, s) { | 457 } catch (ex, s) { |
| 458 diagnoseCrashInUserCode('Uncaught exception in input provider', ex, s); | 458 diagnoseCrashInUserCode('Uncaught exception in input provider', ex, s); |
| 459 rethrow; | 459 rethrow; |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 Future<Packages> callUserPackagesDiscovery(Uri uri) { | 463 Future<Packages> callUserPackagesDiscovery(Uri uri) { |
| 464 try { | 464 try { |
| 465 return userPackagesDiscoveryTask.measure( | 465 return userPackagesDiscoveryTask.measure( |
| 466 () => packagesDiscoveryProvider(uri)); | 466 () => packagesDiscoveryProvider(uri)); |
| 467 } catch (ex, s) { | 467 } catch (ex, s) { |
| 468 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); | 468 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); |
| 469 rethrow; | 469 rethrow; |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 | 472 |
| 473 void diagnoseCrashInUserCode(String message, exception, stackTrace) { | 473 void diagnoseCrashInUserCode(String message, exception, stackTrace) { |
| 474 hasCrashed = true; | 474 hasCrashed = true; |
| 475 print('$message: ${tryToString(exception)}'); | 475 print('$message: ${tryToString(exception)}'); |
| 476 print(tryToString(stackTrace)); | 476 print(tryToString(stackTrace)); |
| 477 } | 477 } |
| 478 | 478 |
| 479 fromEnvironment(String name) => environment[name]; | 479 fromEnvironment(String name) => environment[name]; |
| 480 | 480 |
| 481 LibraryInfo lookupLibraryInfo(String libraryName) { | 481 LibraryInfo lookupLibraryInfo(String libraryName) { |
| 482 return library_info.LIBRARIES[libraryName]; | 482 return library_info.LIBRARIES[libraryName]; |
| 483 } | 483 } |
| 484 } | 484 } |
| OLD | NEW |