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

Side by Side Diff: pkg/analyzer/lib/src/summary/pub_summary.dart

Issue 2328613002: Verify that cache unlinked and linked bundles are majorVersion compatible. (Closed)
Patch Set: Created 4 years, 3 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/test/src/summary/pub_summary_test.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:core' hide Resource; 7 import 'dart:core' hide Resource;
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 * 73 *
74 * The client should call [getLinkedBundles] after creating a new 74 * The client should call [getLinkedBundles] after creating a new
75 * [AnalysisContext] and configuring its source factory, but before computing 75 * [AnalysisContext] and configuring its source factory, but before computing
76 * any analysis results. The returned linked bundles can be used to create and 76 * any analysis results. The returned linked bundles can be used to create and
77 * configure [ResynthesizerResultProvider] for the context. 77 * configure [ResynthesizerResultProvider] for the context.
78 */ 78 */
79 class PubSummaryManager { 79 class PubSummaryManager {
80 static const UNLINKED_NAME = 'unlinked.ds'; 80 static const UNLINKED_NAME = 'unlinked.ds';
81 static const UNLINKED_SPEC_NAME = 'unlinked_spec.ds'; 81 static const UNLINKED_SPEC_NAME = 'unlinked_spec.ds';
82 82
83 /**
84 * See [PackageBundleAssembler.currentMajorVersion].
85 */
86 @visibleForTesting
87 int majorVersion = PackageBundleAssembler.currentMajorVersion;
Brian Wilkerson 2016/09/08 16:42:28 Should this be final?
scheglov 2016/09/08 16:44:24 No. The only reason it was added is to be able to
Paul Berry 2016/09/08 16:45:16 I was just about to make a similar comment. I'd p
scheglov 2016/09/08 17:02:37 OK, it seems that we have a consensus here :-) Don
88
83 final ResourceProvider resourceProvider; 89 final ResourceProvider resourceProvider;
84 90
85 /** 91 /**
86 * The name of the temporary file that is used for atomic writes. 92 * The name of the temporary file that is used for atomic writes.
87 */ 93 */
88 final String tempFileName; 94 final String tempFileName;
89 95
90 /** 96 /**
91 * The map from [PubPackage]s to their unlinked [PackageBundle]s in the pub 97 * The map from [PubPackage]s to their unlinked [PackageBundle]s in the pub
92 * cache. 98 * cache.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 341 }
336 for (Resource child in children) { 342 for (Resource child in children) {
337 if (child is Folder) { 343 if (child is Folder) {
338 addDartFiles(child); 344 addDartFiles(child);
339 } 345 }
340 } 346 }
341 } 347 }
342 348
343 try { 349 try {
344 addDartFiles(libFolder); 350 addDartFiles(libFolder);
345 List<int> bytes = assembler.assemble().toBuffer(); 351 PackageBundleBuilder bundleWriter = assembler.assemble();
352 bundleWriter.majorVersion = majorVersion;
353 List<int> bytes = bundleWriter.toBuffer();
346 String fileName = _getUnlinkedName(strong); 354 String fileName = _getUnlinkedName(strong);
347 _writeAtomic(package.folder, fileName, bytes); 355 _writeAtomic(package.folder, fileName, bytes);
348 } on FileSystemException { 356 } on FileSystemException {
349 // Ignore file system exceptions. 357 // Ignore file system exceptions.
350 } 358 }
351 } 359 }
352 360
353 /** 361 /**
354 * Return the name of the file for a linked bundle, in strong or spec mode. 362 * Return the name of the file for a linked bundle, in strong or spec mode.
355 */ 363 */
(...skipping 19 matching lines...) Expand all
375 /** 383 /**
376 * Return the unlinked [PackageBundle] for the given [package]. If the bundle 384 * Return the unlinked [PackageBundle] for the given [package]. If the bundle
377 * has not been compute yet, return `null` and schedule its computation. 385 * has not been compute yet, return `null` and schedule its computation.
378 */ 386 */
379 PackageBundle _getUnlinkedOrSchedule(PubPackage package, bool strong) { 387 PackageBundle _getUnlinkedOrSchedule(PubPackage package, bool strong) {
380 // Try to find in the cache. 388 // Try to find in the cache.
381 PackageBundle bundle = unlinkedBundleMap[package]; 389 PackageBundle bundle = unlinkedBundleMap[package];
382 if (bundle != null) { 390 if (bundle != null) {
383 return bundle; 391 return bundle;
384 } 392 }
393
385 // Try to read from the file system. 394 // Try to read from the file system.
386 String fileName = _getUnlinkedName(strong); 395 String fileName = _getUnlinkedName(strong);
387 File unlinkedFile = package.folder.getChildAssumingFile(fileName); 396 File file = package.folder.getChildAssumingFile(fileName);
388 if (unlinkedFile.exists) { 397 if (file.exists) {
389 try { 398 try {
390 List<int> bytes = unlinkedFile.readAsBytesSync(); 399 List<int> bytes = file.readAsBytesSync();
391 bundle = new PackageBundle.fromBuffer(bytes); 400 bundle = new PackageBundle.fromBuffer(bytes);
392 unlinkedBundleMap[package] = bundle;
393 // TODO(scheglov) if not in the pub cache, check for consistency
394 return bundle;
395 } on FileSystemException { 401 } on FileSystemException {
396 // Ignore file system exceptions. 402 // Ignore file system exceptions.
397 } 403 }
398 } 404 }
405
406 bool isInPubCache = isPathInPubCache(pathContext, package.folder.path);
407
408 // Verify compatibility.
409 // TODO(scheglov) if not in the pub cache, check for consistency
410 if (bundle != null && bundle.majorVersion == majorVersion) {
411 unlinkedBundleMap[package] = bundle;
412 return bundle;
413 }
414
399 // Schedule computation in the background, if in the pub cache. 415 // Schedule computation in the background, if in the pub cache.
400 if (isPathInPubCache(pathContext, package.folder.path)) { 416 if (isInPubCache) {
401 if (seenPackages.add(package)) { 417 if (seenPackages.add(package)) {
402 _scheduleUnlinked(package); 418 _scheduleUnlinked(package);
403 } 419 }
404 } 420 }
405 // The bundle is for available. 421
422 // The bundle is not available.
406 return null; 423 return null;
407 } 424 }
408 425
409 /** 426 /**
410 * Parse the given [source] into AST. 427 * Parse the given [source] into AST.
411 */ 428 */
412 CompilationUnit _parse(Source source, bool strong) { 429 CompilationUnit _parse(Source source, bool strong) {
413 String code = source.contents.data; 430 String code = source.contents.data;
414 AnalysisErrorListener errorListener = AnalysisErrorListener.NULL_LISTENER; 431 AnalysisErrorListener errorListener = AnalysisErrorListener.NULL_LISTENER;
415 CharSequenceReader reader = new CharSequenceReader(code); 432 CharSequenceReader reader = new CharSequenceReader(code);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 } 724 }
708 725
709 /** 726 /**
710 * Check whether the given `package:` [uri] is listed in the package map. 727 * Check whether the given `package:` [uri] is listed in the package map.
711 */ 728 */
712 bool isListed(String uri) { 729 bool isListed(String uri) {
713 String package = PubSummaryManager.getPackageName(uri); 730 String package = PubSummaryManager.getPackageName(uri);
714 return names.contains(package); 731 return names.contains(package);
715 } 732 }
716 } 733 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/pub_summary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698