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

Side by Side Diff: pkg/analyzer/tool/summary/build_sdk_summaries.dart

Issue 2077583002: Make SDK summary writing available to analyzer clients. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Review feedbacks. 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 | « pkg/analyzer/lib/src/summary/summary_file_builder.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import 'dart:io'; 1 import 'dart:io';
2 2
3 import 'package:analyzer/src/generated/sdk_io.dart'; 3 import 'package:analyzer/src/generated/sdk_io.dart';
4 import 'package:analyzer/src/summary/flat_buffers.dart' as fb; 4 import 'package:analyzer/src/summary/flat_buffers.dart' as fb;
5 import 'package:analyzer/src/summary/summary_file_builder.dart'; 5 import 'package:analyzer/src/summary/summary_file_builder.dart';
6 6
7 main(List<String> args) { 7 main(List<String> args) {
8 if (args.length < 1) { 8 if (args.length < 1) {
9 _printUsage(); 9 _printUsage();
10 exitCode = 1; 10 exitCode = 1;
(...skipping 11 matching lines...) Expand all
22 if (!FileSystemEntity.isDirectorySync(outputDirectoryPath)) { 22 if (!FileSystemEntity.isDirectorySync(outputDirectoryPath)) {
23 print("'$outputDirectoryPath' is not a directory."); 23 print("'$outputDirectoryPath' is not a directory.");
24 _printUsage(); 24 _printUsage();
25 exitCode = 1; 25 exitCode = 1;
26 return; 26 return;
27 } 27 }
28 // 28 //
29 // Prepare results. 29 // Prepare results.
30 // 30 //
31 String sdkPath = args.length > 2 ? args[2] : null; 31 String sdkPath = args.length > 2 ? args[2] : null;
32 _Output output = _buildMultipleOutputs(sdkPath, includeSpec); 32 SummaryOutput output = _buildMultipleOutputs(sdkPath, includeSpec);
33 if (output == null) { 33 if (output == null) {
34 exitCode = 1; 34 exitCode = 1;
35 return; 35 return;
36 } 36 }
37 // 37 //
38 // Write results. 38 // Write results.
39 // 39 //
40 if (includeSpec) { 40 if (includeSpec) {
41 output.spec.writeMultiple(outputDirectoryPath, 'spec'); 41 output.spec.writeMultiple(outputDirectoryPath, 'spec');
42 } 42 }
43 output.strong.writeMultiple(outputDirectoryPath, 'strong'); 43 output.strong.writeMultiple(outputDirectoryPath, 'strong');
44 } else if (command == 'single-output' && 44 } else if (command == 'single-output' &&
45 args.length >= 2 && 45 args.length >= 2 &&
46 args.length <= 3) { 46 args.length <= 3) {
47 String outputPath = args[1]; 47 String outputPath = args[1];
48 String sdkPath = args.length > 2 ? args[2] : null; 48 String sdkPath = args.length > 2 ? args[2] : null;
49 // 49 //
50 // Prepare results. 50 // Prepare results.
51 // 51 //
52 _Output output = _buildMultipleOutputs(sdkPath, true); 52 SummaryOutput output = _buildMultipleOutputs(sdkPath, true);
53 if (output == null) { 53 if (output == null) {
54 exitCode = 1; 54 exitCode = 1;
55 return; 55 return;
56 } 56 }
57
57 // 58 //
58 // Write results. 59 // Write results.
59 // 60 //
60 fb.Builder builder = new fb.Builder(); 61 output.write(outputPath);
61 fb.Offset specSumOffset = builder.writeListUint8(output.spec.sum);
62 fb.Offset specIndexOffset = builder.writeListUint8(output.spec.index);
63 fb.Offset strongSumOffset = builder.writeListUint8(output.strong.sum);
64 fb.Offset strongIndexOffset = builder.writeListUint8(output.strong.index);
65 builder.startTable();
66 builder.addOffset(_FIELD_SPEC_SUM, specSumOffset);
67 builder.addOffset(_FIELD_SPEC_INDEX, specIndexOffset);
68 builder.addOffset(_FIELD_STRONG_SUM, strongSumOffset);
69 builder.addOffset(_FIELD_STRONG_INDEX, strongIndexOffset);
70 fb.Offset offset = builder.endTable();
71 new File(outputPath)
72 .writeAsBytesSync(builder.finish(offset), mode: FileMode.WRITE_ONLY);
73 } else if (command == 'extract-spec-sum' && args.length == 3) { 62 } else if (command == 'extract-spec-sum' && args.length == 3) {
74 String inputPath = args[1]; 63 String inputPath = args[1];
75 String outputPath = args[2]; 64 String outputPath = args[2];
76 _extractSingleOutput(inputPath, _FIELD_SPEC_SUM, outputPath); 65 _extractSingleOutput(inputPath, FIELD_SPEC_SUM, outputPath);
77 } else if (command == 'extract-spec-index' && args.length == 3) { 66 } else if (command == 'extract-spec-index' && args.length == 3) {
78 String inputPath = args[1]; 67 String inputPath = args[1];
79 String outputPath = args[2]; 68 String outputPath = args[2];
80 _extractSingleOutput(inputPath, _FIELD_SPEC_INDEX, outputPath); 69 _extractSingleOutput(inputPath, FIELD_SPEC_INDEX, outputPath);
81 } else if (command == 'extract-strong-sum' && args.length == 3) { 70 } else if (command == 'extract-strong-sum' && args.length == 3) {
82 String inputPath = args[1]; 71 String inputPath = args[1];
83 String outputPath = args[2]; 72 String outputPath = args[2];
84 _extractSingleOutput(inputPath, _FIELD_STRONG_SUM, outputPath); 73 _extractSingleOutput(inputPath, FIELD_STRONG_SUM, outputPath);
85 } else if (command == 'extract-strong-index' && args.length == 3) { 74 } else if (command == 'extract-strong-index' && args.length == 3) {
86 String inputPath = args[1]; 75 String inputPath = args[1];
87 String outputPath = args[2]; 76 String outputPath = args[2];
88 _extractSingleOutput(inputPath, _FIELD_STRONG_INDEX, outputPath); 77 _extractSingleOutput(inputPath, FIELD_STRONG_INDEX, outputPath);
89 } else { 78 } else {
90 _printUsage(); 79 _printUsage();
91 exitCode = 1; 80 exitCode = 1;
92 return; 81 return;
93 } 82 }
94 } 83 }
95 84
96 /** 85 /**
97 * The name of the SDK summaries builder application. 86 * The name of the SDK summaries builder application.
98 */ 87 */
99 const BINARY_NAME = "build_sdk_summaries"; 88 const BINARY_NAME = "build_sdk_summaries";
100 89
101 const int _FIELD_SPEC_INDEX = 1; 90 SummaryOutput _buildMultipleOutputs(String sdkPath, bool includeSpec) {
102 const int _FIELD_SPEC_SUM = 0;
103 const int _FIELD_STRONG_INDEX = 3;
104 const int _FIELD_STRONG_SUM = 2;
105
106 _Output _buildMultipleOutputs(String sdkPath, bool includeSpec) {
107 // 91 //
108 // Validate the SDK path. 92 // Validate the SDK path.
109 // 93 //
110 if (sdkPath != null) { 94 if (sdkPath != null) {
111 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) { 95 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
112 print("'$sdkPath/lib' does not exist."); 96 print("'$sdkPath/lib' does not exist.");
113 _printUsage(); 97 _printUsage();
114 return null; 98 return null;
115 } 99 }
116 } else { 100 } else {
117 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath(); 101 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath();
118 } 102 }
119 103
120 // 104 //
121 // Build spec and strong outputs. 105 // Build spec and strong outputs.
122 // 106 //
123 BuilderOutput spec = includeSpec ? _buildOutput(sdkPath, false) : null; 107 BuilderOutput spec = includeSpec ? _buildOutput(sdkPath, false) : null;
124 BuilderOutput strong = _buildOutput(sdkPath, true); 108 BuilderOutput strong = _buildOutput(sdkPath, true);
125 return new _Output(spec, strong); 109 return new SummaryOutput(spec, strong);
126 } 110 }
127 111
128 BuilderOutput _buildOutput(String sdkPath, bool strongMode) { 112 BuilderOutput _buildOutput(String sdkPath, bool strongMode) {
129 String modeName = strongMode ? 'strong' : 'spec'; 113 String modeName = strongMode ? 'strong' : 'spec';
130 print('Generating $modeName mode summary and index.'); 114 print('Generating $modeName mode summary and index.');
131 Stopwatch sw = new Stopwatch()..start(); 115 Stopwatch sw = new Stopwatch()..start();
132 BuilderOutput output = new SummaryBuilder.forSdk(sdkPath, strongMode).build(); 116 BuilderOutput output = new SummaryBuilder.forSdk(sdkPath, strongMode).build();
133 print('\tDone in ${sw.elapsedMilliseconds} ms.'); 117 print('\tDone in ${sw.elapsedMilliseconds} ms.');
134 return output; 118 return output;
135 } 119 }
(...skipping 26 matching lines...) Expand all
162 print(' Generate a single file with summary and index.'); 146 print(' Generate a single file with summary and index.');
163 print(' extract-spec-sum input_file output_file'); 147 print(' extract-spec-sum input_file output_file');
164 print(' Extract the spec-mode summary file.'); 148 print(' Extract the spec-mode summary file.');
165 print(' extract-strong-sum input_file output_file'); 149 print(' extract-strong-sum input_file output_file');
166 print(' Extract the strong-mode summary file.'); 150 print(' Extract the strong-mode summary file.');
167 print(' extract-spec-index input_file output_file'); 151 print(' extract-spec-index input_file output_file');
168 print(' Extract the spec-mode index file.'); 152 print(' Extract the spec-mode index file.');
169 print(' extract-strong-index input_file output_file'); 153 print(' extract-strong-index input_file output_file');
170 print(' Extract the strong-mode index file.'); 154 print(' Extract the strong-mode index file.');
171 } 155 }
172
173 class _Output {
174 final BuilderOutput spec;
175 final BuilderOutput strong;
176
177 _Output(this.spec, this.strong);
178 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summary_file_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698