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: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; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 final AnalysisStats stats; | 131 final AnalysisStats stats; |
132 | 132 |
133 SummaryDataStore summaryDataStore; | 133 SummaryDataStore summaryDataStore; |
134 InternalAnalysisContext context; | 134 InternalAnalysisContext context; |
135 Map<Uri, JavaFile> uriToFileMap; | 135 Map<Uri, JavaFile> uriToFileMap; |
136 final List<Source> explicitSources = <Source>[]; | 136 final List<Source> explicitSources = <Source>[]; |
137 | 137 |
138 PackageBundleAssembler assembler; | 138 PackageBundleAssembler assembler; |
139 final Set<Source> processedSources = new Set<Source>(); | 139 final Set<Source> processedSources = new Set<Source>(); |
140 final Map<Uri, UnlinkedUnit> uriToUnit = <Uri, UnlinkedUnit>{}; | 140 final Map<Uri, UnlinkedUnit> uriToUnit = <Uri, UnlinkedUnit>{}; |
| 141 PackageBundle sdkBundle; |
141 | 142 |
142 BuildMode(this.resourceProvider, this.options, this.stats); | 143 BuildMode(this.resourceProvider, this.options, this.stats); |
143 | 144 |
| 145 bool get _shouldOutputSummary => |
| 146 options.buildSummaryOutput != null || |
| 147 options.buildSummaryOutputSemantic != null; |
| 148 |
144 /** | 149 /** |
145 * Perform package analysis according to the given [options]. | 150 * Perform package analysis according to the given [options]. |
146 */ | 151 */ |
147 ErrorSeverity analyze() { | 152 ErrorSeverity analyze() { |
148 // Write initial progress message. | 153 // Write initial progress message. |
149 if (!options.machineFormat) { | 154 if (!options.machineFormat) { |
150 outSink.writeln("Analyzing sources ${options.sourceFiles}..."); | 155 outSink.writeln("Analyzing sources ${options.sourceFiles}..."); |
151 } | 156 } |
152 | 157 |
153 // Create the URI to file map. | 158 // Create the URI to file map. |
(...skipping 28 matching lines...) Expand all Loading... |
182 if (!analysisResult.hasMoreWork) { | 187 if (!analysisResult.hasMoreWork) { |
183 break; | 188 break; |
184 } | 189 } |
185 } | 190 } |
186 } | 191 } |
187 | 192 |
188 // Write summary. | 193 // Write summary. |
189 assembler = new PackageBundleAssembler( | 194 assembler = new PackageBundleAssembler( |
190 excludeHashes: options.buildSummaryExcludeInformative && | 195 excludeHashes: options.buildSummaryExcludeInformative && |
191 options.buildSummaryOutputSemantic == null); | 196 options.buildSummaryOutputSemantic == null); |
192 if (options.buildSummaryOutput != null || | 197 if (_shouldOutputSummary) { |
193 options.buildSummaryOutputSemantic != null) { | |
194 if (options.buildSummaryOnlyAst && !options.buildSummaryFallback) { | 198 if (options.buildSummaryOnlyAst && !options.buildSummaryFallback) { |
195 _serializeAstBasedSummary(explicitSources); | 199 _serializeAstBasedSummary(explicitSources); |
196 } else { | 200 } else { |
197 for (Source source in explicitSources) { | 201 for (Source source in explicitSources) { |
198 if (context.computeKindOf(source) == SourceKind.LIBRARY) { | 202 if (context.computeKindOf(source) == SourceKind.LIBRARY) { |
199 if (options.buildSummaryFallback) { | 203 if (options.buildSummaryFallback) { |
200 assembler.addFallbackLibrary(source); | 204 assembler.addFallbackLibrary(source); |
201 } else { | 205 } else { |
202 LibraryElement libraryElement = | 206 LibraryElement libraryElement = |
203 context.computeLibraryElement(source); | 207 context.computeLibraryElement(source); |
204 assembler.serializeLibraryElement(libraryElement); | 208 assembler.serializeLibraryElement(libraryElement); |
205 } | 209 } |
206 } | 210 } |
207 if (options.buildSummaryFallback) { | 211 if (options.buildSummaryFallback) { |
208 assembler.addFallbackUnit(source); | 212 assembler.addFallbackUnit(source); |
209 } | 213 } |
210 } | 214 } |
211 } | 215 } |
| 216 if (!options.buildSummaryOnlyAst) { |
| 217 // In non-AST mode, the SDK bundle wasn't added to the summaryDataStore |
| 218 // because it is automatically loaded during analysis. However we still |
| 219 // want the SDK bundle to be noted as a dependency, so add it now. |
| 220 summaryDataStore.addBundle(null, sdkBundle); |
| 221 } |
212 // Write the whole package bundle. | 222 // Write the whole package bundle. |
213 PackageBundleBuilder sdkBundle = assembler.assemble(); | 223 assembler.recordDependencies(summaryDataStore); |
| 224 PackageBundleBuilder bundle = assembler.assemble(); |
214 if (options.buildSummaryExcludeInformative) { | 225 if (options.buildSummaryExcludeInformative) { |
215 sdkBundle.flushInformative(); | 226 bundle.flushInformative(); |
216 } | 227 } |
217 if (options.buildSummaryOutput != null) { | 228 if (options.buildSummaryOutput != null) { |
218 io.File file = new io.File(options.buildSummaryOutput); | 229 io.File file = new io.File(options.buildSummaryOutput); |
219 file.writeAsBytesSync(sdkBundle.toBuffer(), | 230 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); |
220 mode: io.FileMode.WRITE_ONLY); | |
221 } | 231 } |
222 if (options.buildSummaryOutputSemantic != null) { | 232 if (options.buildSummaryOutputSemantic != null) { |
223 sdkBundle.flushInformative(); | 233 bundle.flushInformative(); |
224 io.File file = new io.File(options.buildSummaryOutputSemantic); | 234 io.File file = new io.File(options.buildSummaryOutputSemantic); |
225 file.writeAsBytesSync(sdkBundle.toBuffer(), | 235 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); |
226 mode: io.FileMode.WRITE_ONLY); | |
227 } | 236 } |
228 } | 237 } |
229 | 238 |
230 if (options.buildSummaryOnly) { | 239 if (options.buildSummaryOnly) { |
231 return ErrorSeverity.NONE; | 240 return ErrorSeverity.NONE; |
232 } else { | 241 } else { |
233 // Process errors. | 242 // Process errors. |
234 _printErrors(outputPath: options.buildAnalysisOutput); | 243 _printErrors(outputPath: options.buildAnalysisOutput); |
235 return _computeMaxSeverity(); | 244 return _computeMaxSeverity(); |
236 } | 245 } |
(...skipping 11 matching lines...) Expand all Loading... |
248 maxSeverity = maxSeverity.max(processedSeverity.severity); | 257 maxSeverity = maxSeverity.max(processedSeverity.severity); |
249 } | 258 } |
250 } | 259 } |
251 } | 260 } |
252 } | 261 } |
253 return maxSeverity; | 262 return maxSeverity; |
254 } | 263 } |
255 | 264 |
256 void _createContext() { | 265 void _createContext() { |
257 // Read the summaries. | 266 // Read the summaries. |
258 summaryDataStore = new SummaryDataStore(options.buildSummaryInputs); | 267 summaryDataStore = new SummaryDataStore(options.buildSummaryInputs, |
| 268 recordDependencyInfo: _shouldOutputSummary); |
259 | 269 |
260 DartSdk sdk; | 270 DartSdk sdk; |
261 PackageBundle sdkBundle; | |
262 if (options.dartSdkSummaryPath != null) { | 271 if (options.dartSdkSummaryPath != null) { |
263 SummaryBasedDartSdk summarySdk = new SummaryBasedDartSdk( | 272 SummaryBasedDartSdk summarySdk = new SummaryBasedDartSdk( |
264 options.dartSdkSummaryPath, options.strongMode); | 273 options.dartSdkSummaryPath, options.strongMode); |
265 sdk = summarySdk; | 274 sdk = summarySdk; |
266 sdkBundle = summarySdk.bundle; | 275 sdkBundle = summarySdk.bundle; |
267 } else { | 276 } else { |
268 DirectoryBasedDartSdk directorySdk = | 277 DirectoryBasedDartSdk directorySdk = |
269 new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); | 278 new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); |
270 directorySdk.analysisOptions = | 279 directorySdk.analysisOptions = |
271 Driver.createAnalysisOptionsForCommandLineOptions(options); | 280 Driver.createAnalysisOptionsForCommandLineOptions(options); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 'Illegal input file (must be "\$uri|\$path"): $sourceFile'); | 396 'Illegal input file (must be "\$uri|\$path"): $sourceFile'); |
388 return null; | 397 return null; |
389 } | 398 } |
390 Uri uri = Uri.parse(sourceFile.substring(0, pipeIndex)); | 399 Uri uri = Uri.parse(sourceFile.substring(0, pipeIndex)); |
391 String path = sourceFile.substring(pipeIndex + 1); | 400 String path = sourceFile.substring(pipeIndex + 1); |
392 uriToFileMap[uri] = new JavaFile(path); | 401 uriToFileMap[uri] = new JavaFile(path); |
393 } | 402 } |
394 return uriToFileMap; | 403 return uriToFileMap; |
395 } | 404 } |
396 } | 405 } |
OLD | NEW |