OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.analyzer.loader; | 4 library kernel.analyzer.loader; |
5 | 5 |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:io' as io; | 7 import 'dart:io' as io; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
11 import 'package:analyzer/file_system/physical_file_system.dart'; | 11 import 'package:analyzer/file_system/physical_file_system.dart'; |
12 import 'package:analyzer/source/package_map_resolver.dart'; | 12 import 'package:analyzer/source/package_map_resolver.dart'; |
13 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 13 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
14 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 14 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/parser.dart'; | 16 import 'package:analyzer/src/generated/parser.dart'; |
17 import 'package:analyzer/src/generated/sdk.dart'; | 17 import 'package:analyzer/src/generated/sdk.dart'; |
18 import 'package:analyzer/src/generated/source_io.dart'; | 18 import 'package:analyzer/src/generated/source_io.dart'; |
| 19 import 'package:analyzer/src/summary/summary_sdk.dart'; |
19 import 'package:kernel/application_root.dart'; | 20 import 'package:kernel/application_root.dart'; |
20 import 'package:package_config/discovery.dart'; | 21 import 'package:package_config/discovery.dart'; |
21 import 'package:package_config/packages.dart'; | 22 import 'package:package_config/packages.dart'; |
22 | 23 |
23 import '../ast.dart' as ast; | 24 import '../ast.dart' as ast; |
24 import '../repository.dart'; | 25 import '../repository.dart'; |
25 import '../target/targets.dart' show Target; | 26 import '../target/targets.dart' show Target; |
26 import '../type_algebra.dart'; | 27 import '../type_algebra.dart'; |
27 import 'analyzer.dart'; | 28 import 'analyzer.dart'; |
28 import 'ast_from_analyzer.dart'; | 29 import 'ast_from_analyzer.dart'; |
29 | 30 |
30 /// Options passed to the Dart frontend. | 31 /// Options passed to the Dart frontend. |
31 class DartOptions { | 32 class DartOptions { |
32 /// True if user code should be loaded in strong mode. | 33 /// True if user code should be loaded in strong mode. |
33 bool strongMode; | 34 bool strongMode; |
34 | 35 |
35 /// True if the Dart SDK should be loaded in strong mode. | 36 /// True if the Dart SDK should be loaded in strong mode. |
36 bool strongModeSdk; | 37 bool strongModeSdk; |
| 38 |
| 39 /// Path to the sdk sources, ignored if sdkSummary is provided. |
37 String sdk; | 40 String sdk; |
| 41 |
| 42 /// Path to a summary of the sdk sources. |
| 43 String sdkSummary; |
| 44 |
| 45 /// Path to the `.packages` file. |
38 String packagePath; | 46 String packagePath; |
| 47 |
| 48 /// Root used to relativize app file-urls, making them machine agnostic. |
39 ApplicationRoot applicationRoot; | 49 ApplicationRoot applicationRoot; |
| 50 |
40 Map<Uri, Uri> customUriMappings; | 51 Map<Uri, Uri> customUriMappings; |
| 52 |
| 53 /// Environment definitions provided via `-Dkey=value`. |
41 Map<String, String> declaredVariables; | 54 Map<String, String> declaredVariables; |
42 | 55 |
43 DartOptions( | 56 DartOptions( |
44 {bool strongMode: false, | 57 {bool strongMode: false, |
45 bool strongModeSdk, | 58 bool strongModeSdk, |
46 this.sdk, | 59 this.sdk, |
| 60 this.sdkSummary, |
47 this.packagePath, | 61 this.packagePath, |
48 ApplicationRoot applicationRoot, | 62 ApplicationRoot applicationRoot, |
49 Map<Uri, Uri> customUriMappings, | 63 Map<Uri, Uri> customUriMappings, |
50 Map<String, String> declaredVariables}) | 64 Map<String, String> declaredVariables}) |
51 : this.customUriMappings = customUriMappings ?? <Uri, Uri>{}, | 65 : this.customUriMappings = customUriMappings ?? <Uri, Uri>{}, |
52 this.declaredVariables = declaredVariables ?? <String, String>{}, | 66 this.declaredVariables = declaredVariables ?? <String, String>{}, |
53 this.strongMode = strongMode, | 67 this.strongMode = strongMode, |
54 this.strongModeSdk = strongModeSdk ?? strongMode, | 68 this.strongModeSdk = strongModeSdk ?? strongMode, |
55 this.applicationRoot = applicationRoot ?? new ApplicationRoot.none(); | 69 this.applicationRoot = applicationRoot ?? new ApplicationRoot.none(); |
56 } | 70 } |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 AnalysisOptions createAnalysisOptions(bool strongMode) { | 770 AnalysisOptions createAnalysisOptions(bool strongMode) { |
757 return new AnalysisOptionsImpl() | 771 return new AnalysisOptionsImpl() |
758 ..strongMode = strongMode | 772 ..strongMode = strongMode |
759 ..generateImplicitErrors = false | 773 ..generateImplicitErrors = false |
760 ..generateSdkErrors = false | 774 ..generateSdkErrors = false |
761 ..preserveComments = false | 775 ..preserveComments = false |
762 ..hint = false | 776 ..hint = false |
763 ..enableSuperMixins = true; | 777 ..enableSuperMixins = true; |
764 } | 778 } |
765 | 779 |
766 DartSdk createDartSdk(String path, {bool strongMode}) { | 780 DartSdk createDartSdk(String path, {bool strongMode, bool isSummary}) { |
| 781 if (isSummary) { |
| 782 return new SummaryBasedDartSdk(path, strongMode); |
| 783 } |
767 var resources = PhysicalResourceProvider.INSTANCE; | 784 var resources = PhysicalResourceProvider.INSTANCE; |
768 return new FolderBasedDartSdk(resources, resources.getFolder(path)) | 785 return new FolderBasedDartSdk(resources, resources.getFolder(path)) |
769 ..context | 786 ..context |
770 .analysisOptions | 787 .analysisOptions |
771 .setCrossContextOptionsFrom(createAnalysisOptions(strongMode)); | 788 .setCrossContextOptionsFrom(createAnalysisOptions(strongMode)); |
772 } | 789 } |
773 | 790 |
774 class CustomUriResolver extends UriResolver { | 791 class CustomUriResolver extends UriResolver { |
775 final ResourceUriResolver _resourceUriResolver; | 792 final ResourceUriResolver _resourceUriResolver; |
776 final Map<Uri, Uri> _customUrlMappings; | 793 final Map<Uri, Uri> _customUrlMappings; |
(...skipping 22 matching lines...) Expand all Loading... |
799 return _resourceUriResolver.resolveAbsolute(mapped, actualUri); | 816 return _resourceUriResolver.resolveAbsolute(mapped, actualUri); |
800 } | 817 } |
801 | 818 |
802 Uri restoreAbsolute(Source source) { | 819 Uri restoreAbsolute(Source source) { |
803 return _resourceUriResolver.restoreAbsolute(source); | 820 return _resourceUriResolver.restoreAbsolute(source); |
804 } | 821 } |
805 } | 822 } |
806 | 823 |
807 AnalysisContext createContext(DartOptions options, Packages packages, | 824 AnalysisContext createContext(DartOptions options, Packages packages, |
808 {DartSdk dartSdk}) { | 825 {DartSdk dartSdk}) { |
809 dartSdk ??= createDartSdk(options.sdk, strongMode: options.strongModeSdk); | 826 bool fromSummary = options.sdkSummary != null; |
| 827 dartSdk ??= createDartSdk(fromSummary ? options.sdkSummary : options.sdk, |
| 828 strongMode: options.strongModeSdk, isSummary: fromSummary); |
810 | 829 |
811 var resourceProvider = PhysicalResourceProvider.INSTANCE; | 830 var resourceProvider = PhysicalResourceProvider.INSTANCE; |
812 var resourceUriResolver = new ResourceUriResolver(resourceProvider); | 831 var resourceUriResolver = new ResourceUriResolver(resourceProvider); |
813 List<UriResolver> resolvers = []; | 832 List<UriResolver> resolvers = []; |
814 var customUriMappings = options.customUriMappings; | 833 var customUriMappings = options.customUriMappings; |
815 if (customUriMappings != null && customUriMappings.length > 0) { | 834 if (customUriMappings != null && customUriMappings.length > 0) { |
816 resolvers | 835 resolvers |
817 .add(new CustomUriResolver(resourceUriResolver, customUriMappings)); | 836 .add(new CustomUriResolver(resourceUriResolver, customUriMappings)); |
818 } | 837 } |
819 resolvers.add(new DartUriResolver(dartSdk)); | 838 resolvers.add(new DartUriResolver(dartSdk)); |
(...skipping 11 matching lines...) Expand all Loading... |
831 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext() | 850 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext() |
832 ..sourceFactory = new SourceFactory(resolvers) | 851 ..sourceFactory = new SourceFactory(resolvers) |
833 ..analysisOptions = createAnalysisOptions(options.strongMode); | 852 ..analysisOptions = createAnalysisOptions(options.strongMode); |
834 | 853 |
835 options.declaredVariables.forEach((String name, String value) { | 854 options.declaredVariables.forEach((String name, String value) { |
836 context.declaredVariables.define(name, value); | 855 context.declaredVariables.define(name, value); |
837 }); | 856 }); |
838 | 857 |
839 return context; | 858 return context; |
840 } | 859 } |
OLD | NEW |