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

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

Issue 2078033002: Introduce build configuration to summary building. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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/tool/summary/build_sdk_summaries.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 library analyzer.src.summary.summary_file_builder; 5 library analyzer.src.summary.summary_file_builder;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 // Write index. 40 // Write index.
41 { 41 {
42 String outputPath = join(outputDirectoryPath, '$modeName.index'); 42 String outputPath = join(outputDirectoryPath, '$modeName.index');
43 File file = new File(outputPath); 43 File file = new File(outputPath);
44 file.writeAsBytesSync(index, mode: FileMode.WRITE_ONLY); 44 file.writeAsBytesSync(index, mode: FileMode.WRITE_ONLY);
45 } 45 }
46 } 46 }
47 } 47 }
48 48
49 /**
50 * Summary build configuration.
51 */
52 class SummaryBuildConfig {
53
54 /**
55 * Whether to use exclude informative data from created summaries.
56 */
57 final bool buildSummaryExcludeInformative;
58
59 /**
60 * Whether to output a summary in "fallback mode".
61 */
62 final bool buildSummaryFallback;
63 /**
Paul Berry 2016/06/17 19:57:51 Nit: add a blank line here.
pquitslund 2016/06/17 20:47:32 Done.
64 * Whether to create summaries using only ASTs, i.e. don't perform resolution.
Paul Berry 2016/06/17 19:57:51 Technically, creating summaries from ASTs performs
pquitslund 2016/06/17 20:47:32 Done.
65 */
66 final bool buildSummaryOnlyAst;
67
68 /**
69 * Path to the dart SDK summary file.
70 */
71 final String dartSdkSummaryPath;
72
73 /**
74 * Whether to use strong static checking.
75 */
76 final bool strongMode;
77
78 /**
79 * List of summary input file paths.
80 */
81 final Iterable<String> summaryInputs;
82
83 /**
84 * Create a build configuration with the given set options.
85 */
86 SummaryBuildConfig(
87 {this.strongMode: false,
88 this.summaryInputs,
89 this.dartSdkSummaryPath,
90 this.buildSummaryExcludeInformative: false,
91 this.buildSummaryFallback: false,
92 this.buildSummaryOnlyAst: false});
93 }
94
49 class SummaryBuilder { 95 class SummaryBuilder {
50 final AnalysisContext _context; 96 final AnalysisContext context;
51 final Iterable<Source> _librarySources; 97 final Iterable<Source> librarySources;
98 final SummaryBuildConfig config;
52 99
53 SummaryBuilder(this._librarySources, this._context); 100 /**
101 * Create a summary builder for these [librarySources] and [context] using the
102 * given [config].
103 */
104 SummaryBuilder(this.librarySources, this.context, this.config);
54 105
55 factory SummaryBuilder.forSdk(String sdkPath, bool strongMode) { 106 /**
107 * Create an SDK summary builder for the dart SDK at the given [sdkPath],
108 * using this [config].
109 */
110 factory SummaryBuilder.forSdk(String sdkPath, SummaryBuildConfig config) {
111 bool strongMode = config.strongMode;
112
56 // 113 //
57 // Prepare SDK. 114 // Prepare SDK.
58 // 115 //
59 DirectoryBasedDartSdk sdk = 116 DirectoryBasedDartSdk sdk =
60 new DirectoryBasedDartSdk(new JavaFile(sdkPath), strongMode); 117 new DirectoryBasedDartSdk(new JavaFile(sdkPath), strongMode);
61 sdk.useSummary = false; 118 sdk.useSummary = false;
62 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = strongMode; 119 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = strongMode;
63 120
64 // 121 //
65 // Prepare 'dart:' URIs to serialize. 122 // Prepare 'dart:' URIs to serialize.
66 // 123 //
67 Set<String> uriSet = 124 Set<String> uriSet =
68 sdk.sdkLibraries.map((SdkLibrary library) => library.shortName).toSet(); 125 sdk.sdkLibraries.map((SdkLibrary library) => library.shortName).toSet();
69 if (!strongMode) { 126 if (!strongMode) {
70 uriSet.add('dart:html/nativewrappers.dart'); 127 uriSet.add('dart:html/nativewrappers.dart');
71 } 128 }
72 uriSet.add('dart:html_common/html_common_dart2js.dart'); 129 uriSet.add('dart:html_common/html_common_dart2js.dart');
73 130
74 Set<Source> librarySources = new HashSet<Source>(); 131 Set<Source> librarySources = new HashSet<Source>();
75 for (String uri in uriSet) { 132 for (String uri in uriSet) {
76 librarySources.add(sdk.mapDartUri(uri)); 133 librarySources.add(sdk.mapDartUri(uri));
77 } 134 }
78 135
79 return new SummaryBuilder(librarySources, sdk.context); 136 return new SummaryBuilder(librarySources, sdk.context, config);
80 } 137 }
81 138
82 BuilderOutput build() => new _Builder(_context, _librarySources).build(); 139 BuilderOutput build() => new _Builder(context, librarySources).build();
83 } 140 }
84 141
85 /** 142 /**
86 * Intermediary summary output result. 143 * Intermediary summary output result.
87 */ 144 */
88 class SummaryOutput { 145 class SummaryOutput {
89 final BuilderOutput spec; 146 final BuilderOutput spec;
90 final BuilderOutput strong; 147 final BuilderOutput strong;
91 SummaryOutput(this.spec, this.strong); 148 SummaryOutput(this.spec, this.strong);
92 149
(...skipping 23 matching lines...) Expand all
116 173
117 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler(); 174 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler();
118 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler(); 175 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler();
119 176
120 final AnalysisContext context; 177 final AnalysisContext context;
121 final Iterable<Source> librarySources; 178 final Iterable<Source> librarySources;
122 179
123 _Builder(this.context, this.librarySources); 180 _Builder(this.context, this.librarySources);
124 181
125 /** 182 /**
126 * Build a strong or spec mode summary for the Dart SDK at [sdkPath]. 183 * Build summary output.
127 */ 184 */
128 BuilderOutput build() { 185 BuilderOutput build() {
129 // 186 //
130 // Serialize each source. 187 // Serialize each source.
131 // 188 //
132 for (Source source in librarySources) { 189 for (Source source in librarySources) {
133 _serializeLibrary(source); 190 _serializeLibrary(source);
134 } 191 }
135 // 192 //
136 // Assemble the output. 193 // Assemble the output.
(...skipping 17 matching lines...) Expand all
154 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source)); 211 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source));
155 // Index every unit of the library. 212 // Index every unit of the library.
156 for (CompilationUnitElement unitElement in element.units) { 213 for (CompilationUnitElement unitElement in element.units) {
157 Source unitSource = unitElement.source; 214 Source unitSource = unitElement.source;
158 CompilationUnit unit = 215 CompilationUnit unit =
159 context.resolveCompilationUnit2(unitSource, source); 216 context.resolveCompilationUnit2(unitSource, source);
160 indexAssembler.indexUnit(unit); 217 indexAssembler.indexUnit(unit);
161 } 218 }
162 } 219 }
163 } 220 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/tool/summary/build_sdk_summaries.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698