OLD | NEW |
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:async'; |
7 import 'dart:io' as io; | 8 import 'dart:io' as io; |
8 | 9 |
9 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit; | 10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit; |
10 import 'package:analyzer/error/error.dart'; | 11 import 'package:analyzer/error/error.dart'; |
11 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
12 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 13 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
13 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
14 import 'package:analyzer/src/generated/sdk.dart'; | 15 import 'package:analyzer/src/generated/sdk.dart'; |
15 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
16 import 'package:analyzer/src/generated/source_io.dart'; | 17 import 'package:analyzer/src/generated/source_io.dart'; |
17 import 'package:analyzer/src/source/source_resource.dart'; | 18 import 'package:analyzer/src/source/source_resource.dart'; |
18 import 'package:analyzer/src/summary/format.dart'; | 19 import 'package:analyzer/src/summary/format.dart'; |
19 import 'package:analyzer/src/summary/idl.dart'; | 20 import 'package:analyzer/src/summary/idl.dart'; |
20 import 'package:analyzer/src/summary/link.dart'; | 21 import 'package:analyzer/src/summary/link.dart'; |
21 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 22 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
22 import 'package:analyzer/src/summary/summarize_ast.dart'; | 23 import 'package:analyzer/src/summary/summarize_ast.dart'; |
23 import 'package:analyzer/src/summary/summarize_elements.dart'; | 24 import 'package:analyzer/src/summary/summarize_elements.dart'; |
24 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; | 25 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; |
25 import 'package:analyzer/task/dart.dart'; | 26 import 'package:analyzer/task/dart.dart'; |
26 import 'package:analyzer_cli/src/driver.dart'; | 27 import 'package:analyzer_cli/src/driver.dart'; |
27 import 'package:analyzer_cli/src/error_formatter.dart'; | 28 import 'package:analyzer_cli/src/error_formatter.dart'; |
28 import 'package:analyzer_cli/src/error_severity.dart'; | 29 import 'package:analyzer_cli/src/error_severity.dart'; |
29 import 'package:analyzer_cli/src/options.dart'; | 30 import 'package:analyzer_cli/src/options.dart'; |
30 import 'package:bazel_worker/bazel_worker.dart'; | 31 import 'package:bazel_worker/bazel_worker.dart'; |
31 | 32 |
32 /** | 33 /** |
33 * Persistent Bazel worker. | 34 * Persistent Bazel worker. |
34 */ | 35 */ |
35 class AnalyzerWorkerLoop extends SyncWorkerLoop { | 36 class AnalyzerWorkerLoop extends AsyncWorkerLoop { |
36 final StringBuffer errorBuffer = new StringBuffer(); | 37 final StringBuffer errorBuffer = new StringBuffer(); |
37 final StringBuffer outBuffer = new StringBuffer(); | 38 final StringBuffer outBuffer = new StringBuffer(); |
38 | 39 |
39 final ResourceProvider resourceProvider; | 40 final ResourceProvider resourceProvider; |
40 final String dartSdkPath; | 41 final String dartSdkPath; |
41 | 42 |
42 AnalyzerWorkerLoop(this.resourceProvider, SyncWorkerConnection connection, | 43 AnalyzerWorkerLoop(this.resourceProvider, AsyncWorkerConnection connection, |
43 {this.dartSdkPath}) | 44 {this.dartSdkPath}) |
44 : super(connection: connection); | 45 : super(connection: connection); |
45 | 46 |
46 factory AnalyzerWorkerLoop.std(ResourceProvider resourceProvider, | 47 factory AnalyzerWorkerLoop.std(ResourceProvider resourceProvider, |
47 {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) { | 48 {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) { |
48 SyncWorkerConnection connection = new StdSyncWorkerConnection( | 49 AsyncWorkerConnection connection = new StdAsyncWorkerConnection( |
49 stdinStream: stdinStream, stdoutStream: stdoutStream); | 50 inputStream: stdinStream, outputStream: stdoutStream); |
50 return new AnalyzerWorkerLoop(resourceProvider, connection, | 51 return new AnalyzerWorkerLoop(resourceProvider, connection, |
51 dartSdkPath: dartSdkPath); | 52 dartSdkPath: dartSdkPath); |
52 } | 53 } |
53 | 54 |
54 /** | 55 /** |
55 * Performs analysis with given [options]. | 56 * Performs analysis with given [options]. |
56 */ | 57 */ |
57 void analyze(CommandLineOptions options) { | 58 void analyze(CommandLineOptions options) { |
58 new BuildMode(resourceProvider, options, new AnalysisStats()).analyze(); | 59 new BuildMode(resourceProvider, options, new AnalysisStats()).analyze(); |
59 AnalysisEngine.instance.clearCaches(); | 60 AnalysisEngine.instance.clearCaches(); |
60 } | 61 } |
61 | 62 |
62 /** | 63 /** |
63 * Perform a single loop step. | 64 * Perform a single loop step. |
64 */ | 65 */ |
65 @override | 66 @override |
66 WorkResponse performRequest(WorkRequest request) { | 67 Future<WorkResponse> performRequest(WorkRequest request) async { |
67 errorBuffer.clear(); | 68 errorBuffer.clear(); |
68 outBuffer.clear(); | 69 outBuffer.clear(); |
69 try { | 70 try { |
70 // Add in the dart-sdk argument if `dartSdkPath` is not null, otherwise it | 71 // Add in the dart-sdk argument if `dartSdkPath` is not null, otherwise it |
71 // will try to find the currently installed sdk. | 72 // will try to find the currently installed sdk. |
72 var arguments = new List<String>.from(request.arguments); | 73 var arguments = new List<String>.from(request.arguments); |
73 if (dartSdkPath != null && | 74 if (dartSdkPath != null && |
74 !arguments.any((arg) => arg.startsWith('--dart-sdk'))) { | 75 !arguments.any((arg) => arg.startsWith('--dart-sdk'))) { |
75 arguments.add('--dart-sdk=$dartSdkPath'); | 76 arguments.add('--dart-sdk=$dartSdkPath'); |
76 } | 77 } |
(...skipping 14 matching lines...) Expand all Loading... |
91 return new WorkResponse() | 92 return new WorkResponse() |
92 ..exitCode = EXIT_CODE_ERROR | 93 ..exitCode = EXIT_CODE_ERROR |
93 ..output = msg; | 94 ..output = msg; |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 /** | 98 /** |
98 * Run the worker loop. | 99 * Run the worker loop. |
99 */ | 100 */ |
100 @override | 101 @override |
101 void run() { | 102 Future<Null> run() async { |
102 errorSink = errorBuffer; | 103 errorSink = errorBuffer; |
103 outSink = outBuffer; | 104 outSink = outBuffer; |
104 exitHandler = (int exitCode) { | 105 exitHandler = (int exitCode) { |
105 return throw new StateError('Exit called: $exitCode'); | 106 return throw new StateError('Exit called: $exitCode'); |
106 }; | 107 }; |
107 super.run(); | 108 await super.run(); |
108 } | 109 } |
109 | 110 |
110 String _getErrorOutputBuffersText() { | 111 String _getErrorOutputBuffersText() { |
111 String msg = ''; | 112 String msg = ''; |
112 if (errorBuffer.isNotEmpty) { | 113 if (errorBuffer.isNotEmpty) { |
113 msg += errorBuffer.toString() + '\n'; | 114 msg += errorBuffer.toString() + '\n'; |
114 } | 115 } |
115 if (outBuffer.isNotEmpty) { | 116 if (outBuffer.isNotEmpty) { |
116 msg += outBuffer.toString() + '\n'; | 117 msg += outBuffer.toString() + '\n'; |
117 } | 118 } |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 * Build the inverse mapping of [uriToSourceMap]. | 475 * Build the inverse mapping of [uriToSourceMap]. |
475 */ | 476 */ |
476 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { | 477 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { |
477 Map<String, Uri> pathToUriMap = <String, Uri>{}; | 478 Map<String, Uri> pathToUriMap = <String, Uri>{}; |
478 uriToSourceMap.forEach((Uri uri, File file) { | 479 uriToSourceMap.forEach((Uri uri, File file) { |
479 pathToUriMap[file.path] = uri; | 480 pathToUriMap[file.path] = uri; |
480 }); | 481 }); |
481 return pathToUriMap; | 482 return pathToUriMap; |
482 } | 483 } |
483 } | 484 } |
OLD | NEW |