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

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

Issue 2836873005: Add support for unlinked summary inputs through --build-summary-unlinked-input (Closed)
Patch Set: Created 3 years, 8 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_cli/lib/src/options.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) 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'; 7 import 'dart:core';
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 */ 125 */
126 class BuildMode { 126 class BuildMode {
127 final ResourceProvider resourceProvider; 127 final ResourceProvider resourceProvider;
128 final CommandLineOptions options; 128 final CommandLineOptions options;
129 final AnalysisStats stats; 129 final AnalysisStats stats;
130 130
131 SummaryDataStore summaryDataStore; 131 SummaryDataStore summaryDataStore;
132 InternalAnalysisContext context; 132 InternalAnalysisContext context;
133 Map<Uri, File> uriToFileMap; 133 Map<Uri, File> uriToFileMap;
134 final List<Source> explicitSources = <Source>[]; 134 final List<Source> explicitSources = <Source>[];
135 final List<PackageBundle> unlinkedBundles = <PackageBundle>[];
135 136
136 PackageBundleAssembler assembler; 137 PackageBundleAssembler assembler;
137 final Set<Source> processedSources = new Set<Source>(); 138 final Set<Source> processedSources = new Set<Source>();
138 final Map<Uri, UnlinkedUnit> uriToUnit = <Uri, UnlinkedUnit>{}; 139 final Map<Uri, UnlinkedUnit> uriToUnit = <Uri, UnlinkedUnit>{};
139 140
140 BuildMode(this.resourceProvider, this.options, this.stats); 141 BuildMode(this.resourceProvider, this.options, this.stats);
141 142
142 bool get _shouldOutputSummary => 143 bool get _shouldOutputSummary =>
143 options.buildSummaryOutput != null || 144 options.buildSummaryOutput != null ||
144 options.buildSummaryOutputSemantic != null; 145 options.buildSummaryOutputSemantic != null;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Write summary. 206 // Write summary.
206 assembler = new PackageBundleAssembler(); 207 assembler = new PackageBundleAssembler();
207 if (_shouldOutputSummary) { 208 if (_shouldOutputSummary) {
208 if (options.buildSummaryOnlyUnlinked) { 209 if (options.buildSummaryOnlyUnlinked) {
209 for (var src in explicitSources) { 210 for (var src in explicitSources) {
210 // Note: This adds the unit to the assembler if it needed to be 211 // Note: This adds the unit to the assembler if it needed to be
211 // computed, so we don't need to explicitly do that. 212 // computed, so we don't need to explicitly do that.
212 _unlinkedUnitForUri('${src.uri}'); 213 _unlinkedUnitForUri('${src.uri}');
213 } 214 }
214 } else { 215 } else {
215 _serializeAstBasedSummary(explicitSources); 216 Set<String> unlinkedUris =
217 explicitSources.map((Source s) => s.uri.toString()).toSet();
218 for (var bundle in unlinkedBundles) {
219 unlinkedUris.addAll(
220 bundle.unlinkedUnitUris.where((uri) => !uri.startsWith('dart:')));
Paul Berry 2017/04/26 15:28:31 Why is `!uri.startsWith('dart:')` necessary? It s
jakemac 2017/04/26 16:06:09 Oh I think this was just necessary for linked summ
221 }
222
223 _serializeAstBasedSummary(unlinkedUris);
216 assembler.recordDependencies(summaryDataStore); 224 assembler.recordDependencies(summaryDataStore);
217 } 225 }
218 // Write the whole package bundle. 226 // Write the whole package bundle.
219 PackageBundleBuilder bundle = assembler.assemble(); 227 PackageBundleBuilder bundle = assembler.assemble();
220 if (options.buildSummaryOutput != null) { 228 if (options.buildSummaryOutput != null) {
221 io.File file = new io.File(options.buildSummaryOutput); 229 io.File file = new io.File(options.buildSummaryOutput);
222 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); 230 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY);
223 } 231 }
224 if (options.buildSummaryOutputSemantic != null) { 232 if (options.buildSummaryOutputSemantic != null) {
225 bundle.flushInformative(); 233 bundle.flushInformative();
(...skipping 23 matching lines...) Expand all
249 maxSeverity = maxSeverity.max(processedSeverity.severity); 257 maxSeverity = maxSeverity.max(processedSeverity.severity);
250 } 258 }
251 } 259 }
252 } 260 }
253 } 261 }
254 return maxSeverity; 262 return maxSeverity;
255 } 263 }
256 264
257 void _createContext() { 265 void _createContext() {
258 // Read the summaries. 266 // Read the summaries.
259 summaryDataStore = new SummaryDataStore(options.buildSummaryInputs, 267 summaryDataStore = new SummaryDataStore(<String>[],
260 recordDependencyInfo: _shouldOutputSummary); 268 recordDependencyInfo: _shouldOutputSummary);
261 269
270 // Adds a bundle at `path` to `summaryDataStore`.
271 PackageBundle addBundle(String path) {
272 var bundle =
273 new PackageBundle.fromBuffer(new io.File(path).readAsBytesSync());
274 summaryDataStore.addBundle(path, bundle);
275 return bundle;
276 }
277
278 for (var path in options.buildSummaryInputs) {
279 var bundle = addBundle(path);
280 if (bundle.linkedLibraryUris.isEmpty &&
jakemac 2017/04/25 17:59:57 I am not sure if this is 100% sane, but it seems t
281 bundle.unlinkedUnitUris.isNotEmpty) {
282 throw new ArgumentError(
283 'Got an unlinked summary for --build-summary-input at `$path`. '
284 'Unlinked summaries should be provided with the '
285 '--build-summary-unlinked-input argument.');
286 }
287 }
288
289 for (var path in options.buildSummaryUnlinkedInputs) {
290 var bundle = addBundle(path);
291 unlinkedBundles.add(bundle);
292 if (bundle.linkedLibraryUris.isNotEmpty) {
293 throw new ArgumentError(
294 'Got a linked summary for --build-summary-input-unlinked at `$path`'
295 '. Linked bundles should be provided with the '
296 '--build-summary-input argument.');
297 }
298 }
299
262 DartSdk sdk; 300 DartSdk sdk;
263 PackageBundle sdkBundle; 301 PackageBundle sdkBundle;
264 if (options.dartSdkSummaryPath != null) { 302 if (options.dartSdkSummaryPath != null) {
265 SummaryBasedDartSdk summarySdk = new SummaryBasedDartSdk( 303 SummaryBasedDartSdk summarySdk = new SummaryBasedDartSdk(
266 options.dartSdkSummaryPath, options.strongMode); 304 options.dartSdkSummaryPath, options.strongMode);
267 sdk = summarySdk; 305 sdk = summarySdk;
268 sdkBundle = summarySdk.bundle; 306 sdkBundle = summarySdk.bundle;
269 } else { 307 } else {
270 FolderBasedDartSdk dartSdk = new FolderBasedDartSdk(resourceProvider, 308 FolderBasedDartSdk dartSdk = new FolderBasedDartSdk(resourceProvider,
271 resourceProvider.getFolder(options.dartSdkPath), options.strongMode); 309 resourceProvider.getFolder(options.dartSdkPath), options.strongMode);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 sink.write(buffer); 388 sink.write(buffer);
351 } else { 389 } else {
352 new io.File(outputPath).writeAsStringSync(buffer.toString()); 390 new io.File(outputPath).writeAsStringSync(buffer.toString());
353 } 391 }
354 } 392 }
355 393
356 /** 394 /**
357 * Serialize the package with the given [sources] into [assembler] using only 395 * Serialize the package with the given [sources] into [assembler] using only
358 * their ASTs and [LinkedUnit]s of input packages. 396 * their ASTs and [LinkedUnit]s of input packages.
359 */ 397 */
360 void _serializeAstBasedSummary(List<Source> sources) { 398 void _serializeAstBasedSummary(Set<String> unlinkedUris) {
361 Set<String> sourceUris =
362 sources.map((Source s) => s.uri.toString()).toSet();
363
364 LinkedLibrary _getDependency(String absoluteUri) => 399 LinkedLibrary _getDependency(String absoluteUri) =>
365 summaryDataStore.linkedMap[absoluteUri]; 400 summaryDataStore.linkedMap[absoluteUri];
366 401
367 Map<String, LinkedLibraryBuilder> linkResult = link( 402 Map<String, LinkedLibraryBuilder> linkResult = link(
368 sourceUris, 403 unlinkedUris,
369 _getDependency, 404 _getDependency,
370 _unlinkedUnitForUri, 405 _unlinkedUnitForUri,
371 context.declaredVariables.get, 406 context.declaredVariables.get,
372 options.strongMode); 407 options.strongMode);
373 linkResult.forEach(assembler.addLinkedLibrary); 408 linkResult.forEach(assembler.addLinkedLibrary);
374 } 409 }
375 410
376 /** 411 /**
377 * Returns the [UnlinkedUnit] for [absoluteUri], either by computing it or 412 * Returns the [UnlinkedUnit] for [absoluteUri], either by computing it or
378 * using the stored one in [uriToUnit]. 413 * using the stored one in [uriToUnit].
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 * Build the inverse mapping of [uriToSourceMap]. 476 * Build the inverse mapping of [uriToSourceMap].
442 */ 477 */
443 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { 478 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) {
444 Map<String, Uri> pathToUriMap = <String, Uri>{}; 479 Map<String, Uri> pathToUriMap = <String, Uri>{};
445 uriToSourceMap.forEach((Uri uri, File file) { 480 uriToSourceMap.forEach((Uri uri, File file) {
446 pathToUriMap[file.path] = uri; 481 pathToUriMap[file.path] = uri;
447 }); 482 });
448 return pathToUriMap; 483 return pathToUriMap;
449 } 484 }
450 } 485 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698