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

Side by Side Diff: pkg/analyzer_cli/lib/src/build_mode.dart

Issue 2212813003: Clean up use of resource provider in cli (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/driver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library analyzer_cli.src.build_mode; 5 library analyzer_cli.src.build_mode;
6 6
7 import 'dart:core' hide Resource; 7 import 'dart:core' hide Resource;
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit; 10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit;
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:analyzer/file_system/file_system.dart'; 12 import 'package:analyzer/file_system/file_system.dart';
13 import 'package:analyzer/file_system/physical_file_system.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/error.dart'; 14 import 'package:analyzer/src/generated/error.dart';
16 import 'package:analyzer/src/generated/java_io.dart'; 15 import 'package:analyzer/src/generated/java_io.dart';
17 import 'package:analyzer/src/generated/sdk.dart'; 16 import 'package:analyzer/src/generated/sdk.dart';
18 import 'package:analyzer/src/generated/sdk_io.dart'; 17 import 'package:analyzer/src/generated/sdk_io.dart';
19 import 'package:analyzer/src/generated/source.dart'; 18 import 'package:analyzer/src/generated/source.dart';
20 import 'package:analyzer/src/generated/source_io.dart'; 19 import 'package:analyzer/src/generated/source_io.dart';
21 import 'package:analyzer/src/summary/format.dart'; 20 import 'package:analyzer/src/summary/format.dart';
22 import 'package:analyzer/src/summary/idl.dart'; 21 import 'package:analyzer/src/summary/idl.dart';
23 import 'package:analyzer/src/summary/link.dart'; 22 import 'package:analyzer/src/summary/link.dart';
24 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 23 import 'package:analyzer/src/summary/package_bundle_reader.dart';
25 import 'package:analyzer/src/summary/summarize_ast.dart'; 24 import 'package:analyzer/src/summary/summarize_ast.dart';
26 import 'package:analyzer/src/summary/summarize_elements.dart'; 25 import 'package:analyzer/src/summary/summarize_elements.dart';
27 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; 26 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
28 import 'package:analyzer/task/dart.dart'; 27 import 'package:analyzer/task/dart.dart';
29 import 'package:analyzer_cli/src/analyzer_impl.dart'; 28 import 'package:analyzer_cli/src/analyzer_impl.dart';
30 import 'package:analyzer_cli/src/driver.dart'; 29 import 'package:analyzer_cli/src/driver.dart';
31 import 'package:analyzer_cli/src/error_formatter.dart'; 30 import 'package:analyzer_cli/src/error_formatter.dart';
32 import 'package:analyzer_cli/src/options.dart'; 31 import 'package:analyzer_cli/src/options.dart';
33 import 'package:bazel_worker/bazel_worker.dart'; 32 import 'package:bazel_worker/bazel_worker.dart';
34 33
35 /** 34 /**
36 * Persistent Bazel worker. 35 * Persistent Bazel worker.
37 */ 36 */
38 class AnalyzerWorkerLoop extends SyncWorkerLoop { 37 class AnalyzerWorkerLoop extends SyncWorkerLoop {
39 final StringBuffer errorBuffer = new StringBuffer(); 38 final StringBuffer errorBuffer = new StringBuffer();
40 final StringBuffer outBuffer = new StringBuffer(); 39 final StringBuffer outBuffer = new StringBuffer();
41 40
41 final ResourceProvider resourceProvider;
42 final String dartSdkPath; 42 final String dartSdkPath;
43 43
44 AnalyzerWorkerLoop(SyncWorkerConnection connection, {this.dartSdkPath}) 44 AnalyzerWorkerLoop(this.resourceProvider, SyncWorkerConnection connection,
45 {this.dartSdkPath})
45 : super(connection: connection); 46 : super(connection: connection);
46 47
47 factory AnalyzerWorkerLoop.std( 48 factory AnalyzerWorkerLoop.std(ResourceProvider resourceProvider,
48 {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) { 49 {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) {
49 SyncWorkerConnection connection = new StdSyncWorkerConnection( 50 SyncWorkerConnection connection = new StdSyncWorkerConnection(
50 stdinStream: stdinStream, stdoutStream: stdoutStream); 51 stdinStream: stdinStream, stdoutStream: stdoutStream);
51 return new AnalyzerWorkerLoop(connection, dartSdkPath: dartSdkPath); 52 return new AnalyzerWorkerLoop(resourceProvider, connection,
53 dartSdkPath: dartSdkPath);
52 } 54 }
53 55
54 /** 56 /**
55 * Performs analysis with given [options]. 57 * Performs analysis with given [options].
56 */ 58 */
57 void analyze(CommandLineOptions options) { 59 void analyze(CommandLineOptions options) {
58 new BuildMode(options, new AnalysisStats()).analyze(); 60 new BuildMode(resourceProvider, options, new AnalysisStats()).analyze();
59 AnalysisEngine.instance.clearCaches(); 61 AnalysisEngine.instance.clearCaches();
60 } 62 }
61 63
62 /** 64 /**
63 * Perform a single loop step. 65 * Perform a single loop step.
64 */ 66 */
65 @override 67 @override
66 WorkResponse performRequest(WorkRequest request) { 68 WorkResponse performRequest(WorkRequest request) {
67 errorBuffer.clear(); 69 errorBuffer.clear();
68 outBuffer.clear(); 70 outBuffer.clear();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 msg += outBuffer.toString() + '\n'; 118 msg += outBuffer.toString() + '\n';
117 } 119 }
118 return msg; 120 return msg;
119 } 121 }
120 } 122 }
121 123
122 /** 124 /**
123 * Analyzer used when the "--build-mode" option is supplied. 125 * Analyzer used when the "--build-mode" option is supplied.
124 */ 126 */
125 class BuildMode { 127 class BuildMode {
128 final ResourceProvider resourceProvider;
126 final CommandLineOptions options; 129 final CommandLineOptions options;
127 final AnalysisStats stats; 130 final AnalysisStats stats;
128 131
129 final ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE;
130 SummaryDataStore summaryDataStore; 132 SummaryDataStore summaryDataStore;
131 InternalAnalysisContext context; 133 InternalAnalysisContext context;
132 Map<Uri, JavaFile> uriToFileMap; 134 Map<Uri, JavaFile> uriToFileMap;
133 final List<Source> explicitSources = <Source>[]; 135 final List<Source> explicitSources = <Source>[];
134 136
135 PackageBundleAssembler assembler; 137 PackageBundleAssembler assembler;
136 final Set<Source> processedSources = new Set<Source>(); 138 final Set<Source> processedSources = new Set<Source>();
137 final Map<Uri, UnlinkedUnit> uriToUnit = <Uri, UnlinkedUnit>{}; 139 final Map<Uri, UnlinkedUnit> uriToUnit = <Uri, UnlinkedUnit>{};
138 140
139 BuildMode(this.options, this.stats); 141 BuildMode(this.resourceProvider, this.options, this.stats);
140 142
141 /** 143 /**
142 * Perform package analysis according to the given [options]. 144 * Perform package analysis according to the given [options].
143 */ 145 */
144 ErrorSeverity analyze() { 146 ErrorSeverity analyze() {
145 // Write initial progress message. 147 // Write initial progress message.
146 if (!options.machineFormat) { 148 if (!options.machineFormat) {
147 outSink.writeln("Analyzing sources ${options.sourceFiles}..."); 149 outSink.writeln("Analyzing sources ${options.sourceFiles}...");
148 } 150 }
149 151
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 280
279 // Create the context. 281 // Create the context.
280 context = AnalysisEngine.instance.createAnalysisContext(); 282 context = AnalysisEngine.instance.createAnalysisContext();
281 context.sourceFactory = new SourceFactory(<UriResolver>[ 283 context.sourceFactory = new SourceFactory(<UriResolver>[
282 new DartUriResolver(sdk), 284 new DartUriResolver(sdk),
283 new InSummaryPackageUriResolver(summaryDataStore), 285 new InSummaryPackageUriResolver(summaryDataStore),
284 new ExplicitSourceResolver(uriToFileMap) 286 new ExplicitSourceResolver(uriToFileMap)
285 ]); 287 ]);
286 288
287 // Set context options. 289 // Set context options.
288 Driver.setAnalysisContextOptions(context, options, 290 Driver.setAnalysisContextOptions(resourceProvider, context, options,
289 (AnalysisOptionsImpl contextOptions) { 291 (AnalysisOptionsImpl contextOptions) {
290 if (options.buildSummaryOnlyDiet) { 292 if (options.buildSummaryOnlyDiet) {
291 contextOptions.analyzeFunctionBodies = false; 293 contextOptions.analyzeFunctionBodies = false;
292 } 294 }
293 }); 295 });
294 296
295 if (!options.buildSummaryOnlyAst) { 297 if (!options.buildSummaryOnlyAst) {
296 // Configure using summaries. 298 // Configure using summaries.
297 context.typeProvider = sdk.context.typeProvider; 299 context.typeProvider = sdk.context.typeProvider;
298 context.resultProvider = 300 context.resultProvider =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 'Illegal input file (must be "\$uri|\$path"): $sourceFile'); 384 'Illegal input file (must be "\$uri|\$path"): $sourceFile');
383 return null; 385 return null;
384 } 386 }
385 Uri uri = Uri.parse(sourceFile.substring(0, pipeIndex)); 387 Uri uri = Uri.parse(sourceFile.substring(0, pipeIndex));
386 String path = sourceFile.substring(pipeIndex + 1); 388 String path = sourceFile.substring(pipeIndex + 1);
387 uriToFileMap[uri] = new JavaFile(path); 389 uriToFileMap[uri] = new JavaFile(path);
388 } 390 }
389 return uriToFileMap; 391 return uriToFileMap;
390 } 392 }
391 } 393 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/driver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698