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

Side by Side Diff: pkg/dev_compiler/lib/src/analyzer/context.dart

Issue 2584293003: DDC/AnalyzerCLI common cmdline option processing (Closed)
Patch Set: Created 4 years 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) 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 import 'package:args/args.dart' show ArgParser, ArgResults; 5 import 'package:args/args.dart' show ArgParser, ArgResults;
6 import 'package:analyzer/src/command_line/arguments.dart';
6 import 'package:analyzer/file_system/file_system.dart' 7 import 'package:analyzer/file_system/file_system.dart'
7 show ResourceProvider, ResourceUriResolver; 8 show ResourceProvider, ResourceUriResolver;
8 import 'package:analyzer/file_system/physical_file_system.dart' 9 import 'package:analyzer/file_system/physical_file_system.dart'
9 show PhysicalResourceProvider; 10 show PhysicalResourceProvider;
10 import 'package:analyzer/source/custom_resolver.dart'; 11 import 'package:analyzer/source/custom_resolver.dart';
11 import 'package:analyzer/source/package_map_resolver.dart'; 12 import 'package:analyzer/source/package_map_resolver.dart';
12 import 'package:analyzer/src/context/builder.dart'; 13 import 'package:analyzer/src/context/builder.dart';
13 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; 14 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
14 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; 15 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
15 import 'package:analyzer/src/generated/engine.dart' 16 import 'package:analyzer/src/generated/engine.dart'
16 show AnalysisEngine, AnalysisOptionsImpl; 17 show AnalysisEngine, AnalysisOptionsImpl;
17 import 'package:analyzer/src/generated/source.dart' 18 import 'package:analyzer/src/generated/source.dart'
18 show DartUriResolver, SourceFactory, UriResolver; 19 show DartUriResolver, SourceFactory, UriResolver;
19 import 'package:analyzer/src/summary/package_bundle_reader.dart' 20 import 'package:analyzer/src/summary/package_bundle_reader.dart'
20 show InSummaryUriResolver, SummaryDataStore; 21 show InSummaryUriResolver, SummaryDataStore;
21 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; 22 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
22 import 'package:cli_util/cli_util.dart' show getSdkDir; 23 import 'package:cli_util/cli_util.dart' show getSdkDir;
23 import 'package:path/path.dart' as path; 24 import 'package:path/path.dart' as path;
24 25
25 /// Options used to set up Source URI resolution in the analysis context. 26 /// Options used to set up Source URI resolution in the analysis context.
26 class AnalyzerOptions { 27 class AnalyzerOptions {
28 final ContextBuilderOptions contextBuilderOptions;
29
27 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" 30 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart"
28 final Map<String, String> customUrlMappings; 31 final Map<String, String> customUrlMappings;
29 32
30 /// Package root when resolving 'package:' urls the standard way. 33 /// Package root when resolving 'package:' urls the standard way.
31 final String packageRoot; 34 String get packageRoot => contextBuilderOptions.defaultPackagesDirectoryPath;
32 35
33 /// List of summary file paths. 36 /// List of summary file paths.
34 final List<String> summaryPaths; 37 final List<String> summaryPaths;
35 38
36 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't 39 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't
37 /// be determined 40 /// be determined
38 final String dartSdkPath; 41 final String dartSdkPath;
39 42
40 /// Path to the dart-sdk summary. If this is set, it will be used in favor 43 /// Path to the dart-sdk summary. If this is set, it will be used in favor
41 /// of the unsummarized one. 44 /// of the unsummarized one.
42 final String dartSdkSummaryPath; 45 String get dartSdkSummaryPath => contextBuilderOptions.dartSdkSummaryPath;
43 46
44 /// Defined variables used by `bool.fromEnvironment` etc. 47 /// Defined variables used by `bool.fromEnvironment` etc.
45 final Map<String, String> declaredVariables; 48 Map<String, String> get declaredVariables =>
49 contextBuilderOptions.declaredVariables;
46 50
47 AnalyzerOptions( 51 AnalyzerOptions._(
48 {this.summaryPaths: const [], 52 {this.contextBuilderOptions,
53 this.summaryPaths: const [],
49 String dartSdkPath, 54 String dartSdkPath,
50 this.dartSdkSummaryPath, 55 this.customUrlMappings: const {}})
51 this.customUrlMappings: const {}, 56 : dartSdkPath = dartSdkPath ?? getSdkDir().path {
52 this.packageRoot: null, 57 contextBuilderOptions.declaredVariables ??= const {};
53 this.declaredVariables: const {}}) 58 }
54 : dartSdkPath = dartSdkPath ?? getSdkDir().path;
55 59
56 factory AnalyzerOptions.fromArguments( 60 factory AnalyzerOptions.basic(
57 ArgResults args, Map<String, String> declaredVariables) { 61 {String dartSdkPath,
58 var sdkPath = args['dart-sdk'] ?? getSdkDir().path; 62 String dartSdkSummaryPath,
59 var sdkSummaryPath = args['dart-sdk-summary']; 63 List<String> summaryPaths}) {
64 var contextBuilderOptions = new ContextBuilderOptions();
65 contextBuilderOptions.dartSdkSummaryPath = dartSdkSummaryPath;
60 66
61 if (sdkSummaryPath == null) { 67 return new AnalyzerOptions._(
62 sdkSummaryPath = path.join(sdkPath, 'lib', '_internal', 'ddc_sdk.sum'); 68 contextBuilderOptions: contextBuilderOptions,
63 } else if (sdkSummaryPath == 'build') { 69 dartSdkPath: dartSdkPath,
70 summaryPaths: summaryPaths);
71 }
72
73 factory AnalyzerOptions.fromArguments(ArgResults args,
74 {String dartSdkSummaryPath, List<String> summaryPaths}) {
75 var contextBuilderOptions = createContextBuilderOptions(args);
76
77 if (dartSdkSummaryPath != null)
78 contextBuilderOptions.dartSdkSummaryPath = dartSdkSummaryPath;
79 contextBuilderOptions.dartSdkSummaryPath ??=
80 path.join(args['dart-sdk'], 'lib', '_internal', 'ddc_sdk.sum');
81 if (contextBuilderOptions.dartSdkSummaryPath == 'build') {
64 // For building the SDK, we explicitly set the path to none. 82 // For building the SDK, we explicitly set the path to none.
65 sdkSummaryPath = null; 83 contextBuilderOptions.dartSdkSummaryPath = null;
66 } 84 }
67 85
68 return new AnalyzerOptions( 86 return new AnalyzerOptions._(
69 summaryPaths: args['summary'] as List<String>, 87 contextBuilderOptions: contextBuilderOptions,
70 dartSdkPath: sdkPath, 88 summaryPaths: summaryPaths ?? args['summary'] as List<String>,
71 dartSdkSummaryPath: sdkSummaryPath, 89 dartSdkPath: args['dart-sdk'],
72 customUrlMappings: _parseUrlMappings(args['url-mapping']), 90 customUrlMappings: _parseUrlMappings(args['url-mapping']));
73 packageRoot: args['package-root'],
74 declaredVariables: declaredVariables);
75 } 91 }
76 92
77 static void addArguments(ArgParser parser, {bool hide: true}) { 93 static void addArguments(ArgParser parser, {bool hide: true}) {
78 parser 94 parser
79 ..addOption('summary', 95 ..addOption('summary',
80 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) 96 abbr: 's', help: 'summary file(s) to include', allowMultiple: true)
81 ..addOption('url-mapping', 97 ..addOption('url-mapping',
82 help: '--url-mapping=libraryUri,/path/to/library.dart uses\n' 98 help: '--url-mapping=libraryUri,/path/to/library.dart uses\n'
83 'library.dart as the source for an import of of "libraryUri".', 99 'library.dart as the source for an import of of "libraryUri".',
84 allowMultiple: true, 100 allowMultiple: true,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return sdk; 178 return sdk;
163 } 179 }
164 180
165 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. 181 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath].
166 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { 182 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) {
167 var sdk = (sdkSummaryPath != null) 183 var sdk = (sdkSummaryPath != null)
168 ? new SummaryBasedDartSdk(sdkSummaryPath, true) 184 ? new SummaryBasedDartSdk(sdkSummaryPath, true)
169 : _createFolderBasedDartSdk(sdkPath); 185 : _createFolderBasedDartSdk(sdkPath);
170 return new DartUriResolver(sdk); 186 return new DartUriResolver(sdk);
171 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698