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

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

Issue 1725913002: Add file hashes to SdkBundle; rename to PackageBundle. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
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.package_analyzer; 5 library analyzer_cli.src.package_analyzer;
6 6
7 import 'dart:convert';
7 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
8 import 'dart:io' as io; 9 import 'dart:io' as io;
9 10
10 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/file_system/file_system.dart'; 12 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/file_system/physical_file_system.dart'; 13 import 'package:analyzer/file_system/physical_file_system.dart';
13 import 'package:analyzer/source/package_map_resolver.dart'; 14 import 'package:analyzer/source/package_map_resolver.dart';
14 import 'package:analyzer/src/context/cache.dart'; 15 import 'package:analyzer/src/context/cache.dart';
15 import 'package:analyzer/src/context/context.dart'; 16 import 'package:analyzer/src/context/context.dart';
16 import 'package:analyzer/src/generated/engine.dart'; 17 import 'package:analyzer/src/generated/engine.dart';
17 import 'package:analyzer/src/generated/error.dart'; 18 import 'package:analyzer/src/generated/error.dart';
18 import 'package:analyzer/src/generated/resolver.dart'; 19 import 'package:analyzer/src/generated/resolver.dart';
19 import 'package:analyzer/src/generated/sdk_io.dart'; 20 import 'package:analyzer/src/generated/sdk_io.dart';
20 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/generated/source_io.dart'; 22 import 'package:analyzer/src/generated/source_io.dart';
22 import 'package:analyzer/src/summary/format.dart'; 23 import 'package:analyzer/src/summary/format.dart';
23 import 'package:analyzer/src/summary/idl.dart'; 24 import 'package:analyzer/src/summary/idl.dart';
24 import 'package:analyzer/src/summary/resynthesize.dart'; 25 import 'package:analyzer/src/summary/resynthesize.dart';
25 import 'package:analyzer/src/summary/summarize_elements.dart'; 26 import 'package:analyzer/src/summary/summarize_elements.dart';
26 import 'package:analyzer/src/summary/summary_sdk.dart'; 27 import 'package:analyzer/src/summary/summary_sdk.dart';
27 import 'package:analyzer/src/task/dart.dart'; 28 import 'package:analyzer/src/task/dart.dart';
28 import 'package:analyzer/task/dart.dart'; 29 import 'package:analyzer/task/dart.dart';
29 import 'package:analyzer/task/model.dart'; 30 import 'package:analyzer/task/model.dart';
30 import 'package:analyzer_cli/src/analyzer_impl.dart'; 31 import 'package:analyzer_cli/src/analyzer_impl.dart';
31 import 'package:analyzer_cli/src/driver.dart'; 32 import 'package:analyzer_cli/src/driver.dart';
32 import 'package:analyzer_cli/src/error_formatter.dart'; 33 import 'package:analyzer_cli/src/error_formatter.dart';
33 import 'package:analyzer_cli/src/options.dart'; 34 import 'package:analyzer_cli/src/options.dart';
35 import 'package:crypto/crypto.dart';
34 import 'package:path/path.dart' as pathos; 36 import 'package:path/path.dart' as pathos;
35 37
36 /** 38 /**
37 * If [uri] has the `package` scheme in form of `package:pkg/file.dart`, 39 * If [uri] has the `package` scheme in form of `package:pkg/file.dart`,
38 * return the `pkg` name. Otherwise return `null`. 40 * return the `pkg` name. Otherwise return `null`.
39 */ 41 */
40 String getPackageName(Uri uri) { 42 String getPackageName(Uri uri) {
41 if (uri.scheme != 'package') { 43 if (uri.scheme != 'package') {
42 return null; 44 return null;
43 } 45 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 80 }
79 81
80 @override 82 @override
81 bool hasLibrarySummary(String uri) { 83 bool hasLibrarySummary(String uri) {
82 return linkedMap.containsKey(uri); 84 return linkedMap.containsKey(uri);
83 } 85 }
84 86
85 void _fillMaps(String path) { 87 void _fillMaps(String path) {
86 io.File file = new io.File(path); 88 io.File file = new io.File(path);
87 List<int> buffer = file.readAsBytesSync(); 89 List<int> buffer = file.readAsBytesSync();
88 SdkBundle bundle = new SdkBundle.fromBuffer(buffer); 90 PackageBundle bundle = new PackageBundle.fromBuffer(buffer);
89 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { 91 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
90 unlinkedMap[bundle.unlinkedUnitUris[i]] = bundle.unlinkedUnits[i]; 92 unlinkedMap[bundle.unlinkedUnitUris[i]] = bundle.unlinkedUnits[i];
91 } 93 }
92 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) { 94 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) {
93 linkedMap[bundle.linkedLibraryUris[i]] = bundle.linkedLibraries[i]; 95 linkedMap[bundle.linkedLibraryUris[i]] = bundle.linkedLibraries[i];
94 } 96 }
95 } 97 }
96 } 98 }
97 99
98 /** 100 /**
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 String packageLibPath; 246 String packageLibPath;
245 247
246 final ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE; 248 final ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE;
247 InternalAnalysisContext context; 249 InternalAnalysisContext context;
248 final List<Source> explicitSources = <Source>[]; 250 final List<Source> explicitSources = <Source>[];
249 251
250 final List<String> linkedLibraryUris = <String>[]; 252 final List<String> linkedLibraryUris = <String>[];
251 final List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[]; 253 final List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[];
252 final List<String> unlinkedUnitUris = <String>[]; 254 final List<String> unlinkedUnitUris = <String>[];
253 final List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[]; 255 final List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[];
256 final List<String> unlinkedUnitHashes = <String>[];
254 257
255 PackageAnalyzer(this.options); 258 PackageAnalyzer(this.options);
256 259
257 /** 260 /**
258 * Perform package analysis according to the given [options]. 261 * Perform package analysis according to the given [options].
259 */ 262 */
260 ErrorSeverity analyze() { 263 ErrorSeverity analyze() {
261 packagePath = options.packageModePath; 264 packagePath = options.packageModePath;
262 packageLibPath = resourceProvider.pathContext.join(packagePath, 'lib'); 265 packageLibPath = resourceProvider.pathContext.join(packagePath, 'lib');
263 if (packageLibPath == null) { 266 if (packageLibPath == null) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 if (options.packageSummaryOutput != null) { 308 if (options.packageSummaryOutput != null) {
306 for (Source source in context.librarySources) { 309 for (Source source in context.librarySources) {
307 if (pathos.isWithin(packageLibPath, source.fullName)) { 310 if (pathos.isWithin(packageLibPath, source.fullName)) {
308 LibraryElement libraryElement = context.getLibraryElement(source); 311 LibraryElement libraryElement = context.getLibraryElement(source);
309 if (libraryElement != null) { 312 if (libraryElement != null) {
310 _serializeSingleLibrary(libraryElement); 313 _serializeSingleLibrary(libraryElement);
311 } 314 }
312 } 315 }
313 } 316 }
314 // Write the whole package bundle. 317 // Write the whole package bundle.
315 SdkBundleBuilder sdkBundle = new SdkBundleBuilder( 318 PackageBundleBuilder sdkBundle = new PackageBundleBuilder(
316 linkedLibraryUris: linkedLibraryUris, 319 linkedLibraryUris: linkedLibraryUris,
317 linkedLibraries: linkedLibraries, 320 linkedLibraries: linkedLibraries,
318 unlinkedUnitUris: unlinkedUnitUris, 321 unlinkedUnitUris: unlinkedUnitUris,
319 unlinkedUnits: unlinkedUnits); 322 unlinkedUnits: unlinkedUnits,
323 unlinkedUnitHashes: unlinkedUnitHashes);
320 io.File file = new io.File(options.packageSummaryOutput); 324 io.File file = new io.File(options.packageSummaryOutput);
321 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); 325 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: io.FileMode.WRITE_ONLY);
322 } 326 }
323 327
324 // Process errors. 328 // Process errors.
325 _printErrors(); 329 _printErrors();
326 return _computeMaxSeverity(); 330 return _computeMaxSeverity();
327 } 331 }
328 332
329 ErrorSeverity _computeMaxSeverity() { 333 ErrorSeverity _computeMaxSeverity() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 Source _createSourceInContext(File file) { 376 Source _createSourceInContext(File file) {
373 Source source = file.createSource(); 377 Source source = file.createSource();
374 if (context == null) { 378 if (context == null) {
375 return source; 379 return source;
376 } 380 }
377 Uri uri = context.sourceFactory.restoreUri(source); 381 Uri uri = context.sourceFactory.restoreUri(source);
378 return file.createSource(uri); 382 return file.createSource(uri);
379 } 383 }
380 384
381 /** 385 /**
386 * Compute a hash of the given file contents.
387 */
388 String _hash(String contents) {
389 MD5 md5 = new MD5();
390 md5.add(UTF8.encode(contents));
391 return CryptoUtils.bytesToHex(md5.close());
392 }
393
394 /**
382 * Print errors for all explicit sources. 395 * Print errors for all explicit sources.
383 */ 396 */
384 void _printErrors() { 397 void _printErrors() {
385 StringSink sink = options.machineFormat ? errorSink : outSink; 398 StringSink sink = options.machineFormat ? errorSink : outSink;
386 ErrorFormatter formatter = new ErrorFormatter( 399 ErrorFormatter formatter = new ErrorFormatter(
387 sink, 400 sink,
388 options, 401 options,
389 (AnalysisError error) => 402 (AnalysisError error) =>
390 AnalyzerImpl.processError(error, options, context)); 403 AnalyzerImpl.processError(error, options, context));
391 for (Source source in explicitSources) { 404 for (Source source in explicitSources) {
392 AnalysisErrorInfo errorInfo = context.getErrors(source); 405 AnalysisErrorInfo errorInfo = context.getErrors(source);
393 formatter.formatErrors([errorInfo]); 406 formatter.formatErrors([errorInfo]);
394 } 407 }
395 } 408 }
396 409
397 /** 410 /**
398 * Serialize the library with the given [element]. 411 * Serialize the library with the given [element].
399 */ 412 */
400 void _serializeSingleLibrary(LibraryElement element) { 413 void _serializeSingleLibrary(LibraryElement element) {
401 String uri = element.source.uri.toString(); 414 String uri = element.source.uri.toString();
402 LibrarySerializationResult libraryResult = 415 LibrarySerializationResult libraryResult =
403 serializeLibrary(element, context.typeProvider, options.strongMode); 416 serializeLibrary(element, context.typeProvider, options.strongMode);
404 linkedLibraryUris.add(uri); 417 linkedLibraryUris.add(uri);
405 linkedLibraries.add(libraryResult.linked); 418 linkedLibraries.add(libraryResult.linked);
406 unlinkedUnitUris.addAll(libraryResult.unitUris); 419 unlinkedUnitUris.addAll(libraryResult.unitUris);
407 unlinkedUnits.addAll(libraryResult.unlinkedUnits); 420 unlinkedUnits.addAll(libraryResult.unlinkedUnits);
421 for (Source source in libraryResult.unitSources) {
422 unlinkedUnitHashes.add(_hash(source.contents.data));
423 }
408 } 424 }
409 } 425 }
OLDNEW
« pkg/analyzer/lib/src/summary/idl.dart ('K') | « pkg/analyzer/tool/summary/stats.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698