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

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

Issue 2254893003: Add PubSummaryManager.computeUnlinkedForFolder() for Flutter. (Closed) Base URL: git@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/pubspec.yaml » ('j') | pkg/analyzer/pubspec.yaml » ('J')
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 10 matching lines...) Expand all
21 import 'package:analyzer/src/summary/format.dart'; 21 import 'package:analyzer/src/summary/format.dart';
22 import 'package:analyzer/src/summary/idl.dart'; 22 import 'package:analyzer/src/summary/idl.dart';
23 import 'package:analyzer/src/summary/link.dart'; 23 import 'package:analyzer/src/summary/link.dart';
24 import 'package:analyzer/src/summary/package_bundle_reader.dart' 24 import 'package:analyzer/src/summary/package_bundle_reader.dart'
25 show ResynthesizerResultProvider, SummaryDataStore; 25 show ResynthesizerResultProvider, SummaryDataStore;
26 import 'package:analyzer/src/summary/summarize_ast.dart' 26 import 'package:analyzer/src/summary/summarize_ast.dart'
27 show serializeAstUnlinked; 27 show serializeAstUnlinked;
28 import 'package:analyzer/src/summary/summarize_elements.dart' 28 import 'package:analyzer/src/summary/summarize_elements.dart'
29 show PackageBundleAssembler; 29 show PackageBundleAssembler;
30 import 'package:analyzer/src/util/fast_uri.dart'; 30 import 'package:analyzer/src/util/fast_uri.dart';
31 import 'package:meta/meta.dart';
31 import 'package:path/path.dart' as pathos; 32 import 'package:path/path.dart' as pathos;
32 33
33 /** 34 /**
34 * Unlinked and linked information about a [PubPackage]. 35 * Unlinked and linked information about a [PubPackage].
35 */ 36 */
36 class LinkedPubPackage { 37 class LinkedPubPackage {
37 final PubPackage package; 38 final PubPackage package;
38 final PackageBundle unlinked; 39 final PackageBundle unlinked;
39 final PackageBundle linked; 40 final PackageBundle linked;
40 41
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 assembler.addLinkedLibrary(uri, library); 224 assembler.addLinkedLibrary(uri, library);
224 }); 225 });
225 List<int> bytes = assembler.assemble().toBuffer(); 226 List<int> bytes = assembler.assemble().toBuffer();
226 return new PackageBundle.fromBuffer(bytes); 227 return new PackageBundle.fromBuffer(bytes);
227 } on FileSystemException { 228 } on FileSystemException {
228 return null; 229 return null;
229 } 230 }
230 } 231 }
231 232
232 /** 233 /**
234 * Complete when the unlinked bundles for the package with the given [name]
235 * and the [libFolder] are computed and written to the files.
236 *
237 * This method is intended to be used for generating unlinked bundles for
238 * the `Flutter` packages.
239 */
240 Future<Null> computeUnlinkedForFolder(String name, Folder libFolder) async {
241 PubPackage package = new PubPackage(name, libFolder);
242 _scheduleUnlinked(package);
243 await onUnlinkedComplete;
244 }
245
246 /**
233 * Return the list of linked [LinkedPubPackage]s that can be provided at this 247 * Return the list of linked [LinkedPubPackage]s that can be provided at this
234 * time for a subset of the packages used by the given [context]. If 248 * time for a subset of the packages used by the given [context]. If
235 * information about some of the used packages is not available yet, schedule 249 * information about some of the used packages is not available yet, schedule
236 * its computation, so that it might be available later for other contexts 250 * its computation, so that it might be available later for other contexts
237 * referencing the same packages. 251 * referencing the same packages.
238 */ 252 */
239 List<LinkedPubPackage> getLinkedBundles(AnalysisContext context) { 253 List<LinkedPubPackage> getLinkedBundles(AnalysisContext context) {
240 // Stopwatch timer = new Stopwatch()..start(); 254 // Stopwatch timer = new Stopwatch()..start();
241 255
242 PackageBundle sdkBundle = context.sourceFactory.dartSdk.getLinkedBundle(); 256 PackageBundle sdkBundle = context.sourceFactory.dartSdk.getLinkedBundle();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // ' in ${timer.elapsedMilliseconds} ms'); 338 // ' in ${timer.elapsedMilliseconds} ms');
325 339
326 // Done. 340 // Done.
327 return linkedPackages; 341 return linkedPackages;
328 } 342 }
329 343
330 /** 344 /**
331 * Return all available unlinked [PackageBundle]s for the given [context], 345 * Return all available unlinked [PackageBundle]s for the given [context],
332 * maybe an empty map, but not `null`. 346 * maybe an empty map, but not `null`.
333 */ 347 */
348 @visibleForTesting
334 Map<PubPackage, PackageBundle> getUnlinkedBundles(AnalysisContext context) { 349 Map<PubPackage, PackageBundle> getUnlinkedBundles(AnalysisContext context) {
335 bool strong = context.analysisOptions.strongMode; 350 bool strong = context.analysisOptions.strongMode;
336 Map<PubPackage, PackageBundle> unlinkedBundles = 351 Map<PubPackage, PackageBundle> unlinkedBundles =
337 new HashMap<PubPackage, PackageBundle>(); 352 new HashMap<PubPackage, PackageBundle>();
338 Map<String, List<Folder>> packageMap = context.sourceFactory.packageMap; 353 Map<String, List<Folder>> packageMap = context.sourceFactory.packageMap;
339 if (packageMap != null) { 354 if (packageMap != null) {
340 packageMap.forEach((String packageName, List<Folder> libFolders) { 355 packageMap.forEach((String packageName, List<Folder> libFolders) {
341 if (libFolders.length == 1) { 356 if (libFolders.length == 1) {
342 Folder libFolder = libFolders.first; 357 Folder libFolder = libFolders.first;
343 PubPackage package = new PubPackage(packageName, libFolder); 358 PubPackage package = new PubPackage(packageName, libFolder);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 unlinkedBundleMap[package] = bundle; 491 unlinkedBundleMap[package] = bundle;
477 // TODO(scheglov) if not in the pub cache, check for consistency 492 // TODO(scheglov) if not in the pub cache, check for consistency
478 return bundle; 493 return bundle;
479 } on FileSystemException { 494 } on FileSystemException {
480 // Ignore file system exceptions. 495 // Ignore file system exceptions.
481 } 496 }
482 } 497 }
483 // Schedule computation in the background, if in the pub cache. 498 // Schedule computation in the background, if in the pub cache.
484 if (isPathInPubCache(pathContext, package.folder.path)) { 499 if (isPathInPubCache(pathContext, package.folder.path)) {
485 if (seenPackages.add(package)) { 500 if (seenPackages.add(package)) {
486 if (packagesToComputeUnlinked.isEmpty) { 501 _scheduleUnlinked(package);
487 _scheduleNextUnlinked();
488 }
489 packagesToComputeUnlinked.add(package);
490 } 502 }
491 } 503 }
492 // The bundle is for available. 504 // The bundle is for available.
493 return null; 505 return null;
494 } 506 }
495 507
496 /** 508 /**
497 * Parse the given [source] into AST. 509 * Parse the given [source] into AST.
498 */ 510 */
499 CompilationUnit _parse(Source source, bool strong) { 511 CompilationUnit _parse(Source source, bool strong) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 * Schedule delayed computation of the next package unlinked bundle from the 556 * Schedule delayed computation of the next package unlinked bundle from the
545 * set of [packagesToComputeUnlinked]. We delay each computation because we 557 * set of [packagesToComputeUnlinked]. We delay each computation because we
546 * want operations in analysis server to proceed, and computing bundles of 558 * want operations in analysis server to proceed, and computing bundles of
547 * packages is a background task. 559 * packages is a background task.
548 */ 560 */
549 void _scheduleNextUnlinked() { 561 void _scheduleNextUnlinked() {
550 new Future.delayed(new Duration(milliseconds: 10), _computeNextUnlinked); 562 new Future.delayed(new Duration(milliseconds: 10), _computeNextUnlinked);
551 } 563 }
552 564
553 /** 565 /**
566 * Schedule computing unlinked bundles for the given [package].
567 */
568 void _scheduleUnlinked(PubPackage package) {
569 if (packagesToComputeUnlinked.isEmpty) {
570 _scheduleNextUnlinked();
571 }
572 packagesToComputeUnlinked.add(package);
573 }
574
575 /**
554 * Atomically write the given [bytes] into the file in the [folder]. 576 * Atomically write the given [bytes] into the file in the [folder].
555 */ 577 */
556 void _writeAtomic(Folder folder, String fileName, List<int> bytes) { 578 void _writeAtomic(Folder folder, String fileName, List<int> bytes) {
557 String filePath = folder.getChildAssumingFile(fileName).path; 579 String filePath = folder.getChildAssumingFile(fileName).path;
558 File tempFile = folder.getChildAssumingFile(tempFileName); 580 File tempFile = folder.getChildAssumingFile(tempFileName);
559 tempFile.writeAsBytesSync(bytes); 581 tempFile.writeAsBytesSync(bytes);
560 tempFile.renameSync(filePath); 582 tempFile.renameSync(filePath);
561 } 583 }
562 584
563 /** 585 /**
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 store.addBundle(null, node.linked); 802 store.addBundle(null, node.linked);
781 } 803 }
782 } 804 }
783 } 805 }
784 806
785 /** 807 /**
786 * This exception is thrown during linking as a signal that linking of the 808 * This exception is thrown during linking as a signal that linking of the
787 * current bundle cannot be performed, e.g. when a dependency cannot be found. 809 * current bundle cannot be performed, e.g. when a dependency cannot be found.
788 */ 810 */
789 class _LinkException {} 811 class _LinkException {}
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/pubspec.yaml » ('j') | pkg/analyzer/pubspec.yaml » ('J')

Powered by Google App Engine
This is Rietveld 408576698