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

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

Issue 2345793002: Stop generating index information for SDK and simplify summary generation. (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
OLDNEW
1 import 'dart:io'; 1 import 'dart:io';
2 2
3 import 'package:analyzer/file_system/physical_file_system.dart'; 3 import 'package:analyzer/file_system/physical_file_system.dart';
4 import 'package:analyzer/src/dart/sdk/sdk.dart'; 4 import 'package:analyzer/src/dart/sdk/sdk.dart';
5 import 'package:analyzer/src/summary/flat_buffers.dart' as fb;
6 import 'package:analyzer/src/summary/summary_file_builder.dart'; 5 import 'package:analyzer/src/summary/summary_file_builder.dart';
7 6
8 main(List<String> args) { 7 main(List<String> args) {
9 if (args.length < 1) { 8 String command;
10 _printUsage(); 9 String outFilePath;
11 exitCode = 1; 10 String sdkPath;
12 return; 11 if (args.length == 2) {
13 } 12 command = args[0];
14 String command = args[0]; 13 outFilePath = args[1];
15 if ((command == 'multiple-outputs' || command == 'strong-outputs') && 14 } else if (args.length == 3) {
16 args.length >= 2 && 15 command = args[0];
17 args.length <= 3) { 16 outFilePath = args[1];
18 bool includeSpec = command != 'strong-outputs'; 17 sdkPath = args[2];
19 //
20 // Prepare the output path.
21 //
22 String outputDirectoryPath = args[1];
23 if (!FileSystemEntity.isDirectorySync(outputDirectoryPath)) {
24 print("'$outputDirectoryPath' is not a directory.");
25 _printUsage();
26 exitCode = 1;
27 return;
28 }
29 //
30 // Prepare results.
31 //
32 String sdkPath = args.length > 2 ? args[2] : null;
33 SummaryOutput output = _buildMultipleOutputs(sdkPath, includeSpec);
34 if (output == null) {
35 exitCode = 1;
36 return;
37 }
38 //
39 // Write results.
40 //
41 if (includeSpec) {
42 output.spec.writeMultiple(outputDirectoryPath, 'spec');
43 }
44 output.strong.writeMultiple(outputDirectoryPath, 'strong');
45 } else if (command == 'single-output' &&
46 args.length >= 2 &&
47 args.length <= 3) {
48 String outputPath = args[1];
49 String sdkPath = args.length > 2 ? args[2] : null;
50 //
51 // Prepare results.
52 //
53 SummaryOutput output = _buildMultipleOutputs(sdkPath, true);
54 if (output == null) {
55 exitCode = 1;
56 return;
57 }
58
59 //
60 // Write results.
61 //
62 output.write(outputPath);
63 } else if (command == 'extract-spec-sum' && args.length == 3) {
64 String inputPath = args[1];
65 String outputPath = args[2];
66 _extractSingleOutput(inputPath, FIELD_SPEC_SUM, outputPath);
67 } else if (command == 'extract-spec-index' && args.length == 3) {
68 String inputPath = args[1];
69 String outputPath = args[2];
70 _extractSingleOutput(inputPath, FIELD_SPEC_INDEX, outputPath);
71 } else if (command == 'extract-strong-sum' && args.length == 3) {
72 String inputPath = args[1];
73 String outputPath = args[2];
74 _extractSingleOutput(inputPath, FIELD_STRONG_SUM, outputPath);
75 } else if (command == 'extract-strong-index' && args.length == 3) {
76 String inputPath = args[1];
77 String outputPath = args[2];
78 _extractSingleOutput(inputPath, FIELD_STRONG_INDEX, outputPath);
79 } else { 18 } else {
80 _printUsage(); 19 _printUsage();
81 exitCode = 1; 20 exitCode = 1;
82 return; 21 return;
83 } 22 }
23
24 //
25 // Validate the SDK path.
26 //
27 sdkPath ??= FolderBasedDartSdk
28 .defaultSdkDirectory(PhysicalResourceProvider.INSTANCE)
29 .path;
30 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
31 print("'$sdkPath/lib' does not exist.");
32 _printUsage();
33 return;
34 }
35
36 //
37 // Handle commands.
38 //
39 if (command == 'build-spec') {
40 _buildSummary(sdkPath, outFilePath, false);
41 } else if (command == 'build-strong') {
42 _buildSummary(sdkPath, outFilePath, true);
43 } else {
44 _printUsage();
45 return;
46 }
84 } 47 }
85 48
86 /** 49 /**
87 * The name of the SDK summaries builder application. 50 * The name of the SDK summaries builder application.
88 */ 51 */
89 const BINARY_NAME = "build_sdk_summaries"; 52 const BINARY_NAME = "build_sdk_summaries";
90 53
91 SummaryOutput _buildMultipleOutputs(String sdkPath, bool includeSpec) { 54 void _buildSummary(String sdkPath, String outPath, bool strong) {
92 // 55 String modeName = strong ? 'strong' : 'spec';
93 // Validate the SDK path. 56 print('Generating $modeName mode summary.');
94 //
95 if (sdkPath != null) {
96 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
97 print("'$sdkPath/lib' does not exist.");
98 _printUsage();
99 return null;
100 }
101 } else {
102 sdkPath = FolderBasedDartSdk
103 .defaultSdkDirectory(PhysicalResourceProvider.INSTANCE)
104 .path;
105 }
106
107 //
108 // Build spec and strong outputs.
109 //
110 BuilderOutput spec = includeSpec ? _buildOutput(sdkPath, false) : null;
111 BuilderOutput strong = _buildOutput(sdkPath, true);
112 return new SummaryOutput(spec, strong);
113 }
114
115 BuilderOutput _buildOutput(String sdkPath, bool strongMode) {
116 String modeName = strongMode ? 'strong' : 'spec';
117 print('Generating $modeName mode summary and index.');
118 Stopwatch sw = new Stopwatch()..start(); 57 Stopwatch sw = new Stopwatch()..start();
119 SummaryBuildConfig config = new SummaryBuildConfig(strongMode: strongMode); 58 List<int> bytes = new SummaryBuilder.forSdk(sdkPath, strong).build();
120 BuilderOutput output = new SummaryBuilder.forSdk(sdkPath, config).build(); 59 new File(outPath).writeAsBytesSync(bytes, mode: FileMode.WRITE_ONLY);
121 print('\tDone in ${sw.elapsedMilliseconds} ms.'); 60 print('\tDone in ${sw.elapsedMilliseconds} ms.');
122 return output;
123 }
124
125 /**
126 * Open the flat buffer in [inputPath] and extract the byte array in the [field]
127 * into the [outputPath] file.
128 */
129 void _extractSingleOutput(String inputPath, int field, String outputPath) {
130 List<int> bytes = new File(inputPath).readAsBytesSync();
131 fb.BufferContext root = new fb.BufferContext.fromBytes(bytes);
132 int tableOffset = root.derefObject(0);
133 List<int> fieldBytes =
134 const fb.Uint8ListReader().vTableGet(root, tableOffset, field);
135 new File(outputPath).writeAsBytesSync(fieldBytes, mode: FileMode.WRITE_ONLY);
136 } 61 }
137 62
138 /** 63 /**
139 * Print information about how to use the SDK summaries builder. 64 * Print information about how to use the SDK summaries builder.
140 */ 65 */
141 void _printUsage() { 66 void _printUsage() {
142 // print('Usage: $BINARY_NAME command output_directory_path [sdk_path]');
143 print('Usage: $BINARY_NAME command arguments'); 67 print('Usage: $BINARY_NAME command arguments');
144 print('Where command can be one of the following:'); 68 print('Where command can be one of the following:');
145 print(' multiple-outputs output_directory_path [sdk_path]'); 69 print(' build-spec output_file [sdk_path]');
146 print(' Generate separate summary and index files.'); 70 print(' Generate spec mode summary file.');
147 print(' strong-outputs output_directory_path [sdk_path]'); 71 print(' build-strong output_file [sdk_path]');
148 print(' Generate separate summary and index files (strong mode only).'); 72 print(' Generate strong mode summary file.');
149 print(' single-output output_file_path [sdk_path]');
150 print(' Generate a single file with summary and index.');
151 print(' extract-spec-sum input_file output_file');
152 print(' Extract the spec-mode summary file.');
153 print(' extract-strong-sum input_file output_file');
154 print(' Extract the strong-mode summary file.');
155 print(' extract-spec-index input_file output_file');
156 print(' Extract the spec-mode index file.');
157 print(' extract-strong-index input_file output_file');
158 print(' Extract the strong-mode index file.');
159 } 73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698