mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:07:11 +00:00
Add hacks into build_sdk_summaries to workaround bugs in build tools.
Paul thinks that there is a bug in gyp or make, and we should generate only one output. So, we generate the whole bundle with all summaries and index information. And then we have separate actions that take this bundle and extract one output each - spec.sum and strong.sum files. R=paulberry@google.com, whesse@google.com BUG= Review URL: https://codereview.chromium.org/1775973003 .
This commit is contained in:
parent
21ed1750ce
commit
5a927c7373
2 changed files with 197 additions and 52 deletions
|
@ -7,21 +7,23 @@ import 'package:analyzer/src/generated/java_io.dart';
|
|||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:analyzer/src/generated/sdk_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/summary/format.dart';
|
||||
import 'package:analyzer/src/summary/flat_buffers.dart' as fb;
|
||||
import 'package:analyzer/src/summary/index_unit.dart';
|
||||
import 'package:analyzer/src/summary/summarize_elements.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
main(List<String> args) {
|
||||
if (args.length < 1 || args.length > 2) {
|
||||
if (args.length < 1) {
|
||||
_printUsage();
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
String command = args[0];
|
||||
if (command == 'multiple-outputs' && args.length >= 2 && args.length <= 3) {
|
||||
//
|
||||
// Prepare output file path.
|
||||
// Prepare the output path.
|
||||
//
|
||||
String outputDirectoryPath = args[0];
|
||||
String outputDirectoryPath = args[1];
|
||||
if (!FileSystemEntity.isDirectorySync(outputDirectoryPath)) {
|
||||
print("'$outputDirectoryPath' is not a directory.");
|
||||
_printUsage();
|
||||
|
@ -29,25 +31,69 @@ main(List<String> args) {
|
|||
return;
|
||||
}
|
||||
//
|
||||
// Prepare SDK path.
|
||||
// Prepare results.
|
||||
//
|
||||
String sdkPath;
|
||||
if (args.length == 2) {
|
||||
sdkPath = args[1];
|
||||
if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
|
||||
print("'$sdkPath/lib' does not exist.");
|
||||
String sdkPath = args.length > 2 ? args[2] : null;
|
||||
_Output output = _buildMultipleOutputs(sdkPath);
|
||||
if (output == null) {
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
//
|
||||
// Write results.
|
||||
//
|
||||
output.spec.writeMultiple(outputDirectoryPath, 'spec');
|
||||
output.strong.writeMultiple(outputDirectoryPath, 'strong');
|
||||
} else if (command == 'single-output' &&
|
||||
args.length >= 2 &&
|
||||
args.length <= 3) {
|
||||
String outputPath = args[1];
|
||||
String sdkPath = args.length > 2 ? args[2] : null;
|
||||
//
|
||||
// Prepare results.
|
||||
//
|
||||
_Output output = _buildMultipleOutputs(sdkPath);
|
||||
if (output == null) {
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
//
|
||||
// Write results.
|
||||
//
|
||||
fb.Builder builder = new fb.Builder();
|
||||
fb.Offset specSumOffset = builder.writeListUint8(output.spec.sum);
|
||||
fb.Offset specIndexOffset = builder.writeListUint8(output.spec.index);
|
||||
fb.Offset strongSumOffset = builder.writeListUint8(output.strong.sum);
|
||||
fb.Offset strongIndexOffset = builder.writeListUint8(output.strong.index);
|
||||
builder.startTable();
|
||||
builder.addOffset(_FIELD_SPEC_SUM, specSumOffset);
|
||||
builder.addOffset(_FIELD_SPEC_INDEX, specIndexOffset);
|
||||
builder.addOffset(_FIELD_STRONG_SUM, strongSumOffset);
|
||||
builder.addOffset(_FIELD_STRONG_INDEX, strongIndexOffset);
|
||||
fb.Offset offset = builder.endTable();
|
||||
new File(outputPath)
|
||||
.writeAsBytesSync(builder.finish(offset), mode: FileMode.WRITE_ONLY);
|
||||
} else if (command == 'extract-spec-sum' && args.length == 3) {
|
||||
String inputPath = args[1];
|
||||
String outputPath = args[2];
|
||||
_extractSingleOutput(inputPath, _FIELD_SPEC_SUM, outputPath);
|
||||
} else if (command == 'extract-spec-index' && args.length == 3) {
|
||||
String inputPath = args[1];
|
||||
String outputPath = args[2];
|
||||
_extractSingleOutput(inputPath, _FIELD_SPEC_INDEX, outputPath);
|
||||
} else if (command == 'extract-strong-sum' && args.length == 3) {
|
||||
String inputPath = args[1];
|
||||
String outputPath = args[2];
|
||||
_extractSingleOutput(inputPath, _FIELD_STRONG_SUM, outputPath);
|
||||
} else if (command == 'extract-strong-index' && args.length == 3) {
|
||||
String inputPath = args[1];
|
||||
String outputPath = args[2];
|
||||
_extractSingleOutput(inputPath, _FIELD_STRONG_INDEX, outputPath);
|
||||
} else {
|
||||
_printUsage();
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath();
|
||||
}
|
||||
//
|
||||
// Build spec and strong summaries.
|
||||
//
|
||||
new _Builder(sdkPath, outputDirectoryPath, false).build();
|
||||
new _Builder(sdkPath, outputDirectoryPath, true).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,17 +101,68 @@ main(List<String> args) {
|
|||
*/
|
||||
const BINARY_NAME = "build_sdk_summaries";
|
||||
|
||||
const int _FIELD_SPEC_INDEX = 1;
|
||||
const int _FIELD_SPEC_SUM = 0;
|
||||
const int _FIELD_STRONG_INDEX = 3;
|
||||
const int _FIELD_STRONG_SUM = 2;
|
||||
|
||||
_Output _buildMultipleOutputs(String sdkPath) {
|
||||
//
|
||||
// Validate the SDK path.
|
||||
//
|
||||
if (sdkPath != null) {
|
||||
if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
|
||||
print("'$sdkPath/lib' does not exist.");
|
||||
_printUsage();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath();
|
||||
}
|
||||
//
|
||||
// Build spec and strong outputs.
|
||||
//
|
||||
_BuilderOutput spec = new _Builder(sdkPath, false).build();
|
||||
_BuilderOutput strong = new _Builder(sdkPath, true).build();
|
||||
return new _Output(spec, strong);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the flat buffer in [inputPath] and extract the byte array in the [field]
|
||||
* into the [outputPath] file.
|
||||
*/
|
||||
void _extractSingleOutput(String inputPath, int field, String outputPath) {
|
||||
List<int> bytes = new File(inputPath).readAsBytesSync();
|
||||
fb.BufferPointer bp = new fb.BufferPointer.fromBytes(bytes);
|
||||
fb.BufferPointer table = bp.derefObject();
|
||||
List<int> fieldBytes =
|
||||
const fb.ListReader(const fb.Uint8Reader()).vTableGet(table, field);
|
||||
new File(outputPath).writeAsBytesSync(fieldBytes, mode: FileMode.WRITE_ONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print information about how to use the SDK summaries builder.
|
||||
*/
|
||||
void _printUsage() {
|
||||
print('Usage: $BINARY_NAME output_directory_path [sdk_path]');
|
||||
print('Build files spec.sum and strong.sum in the output directory.');
|
||||
// print('Usage: $BINARY_NAME command output_directory_path [sdk_path]');
|
||||
print('Usage: $BINARY_NAME command arguments');
|
||||
print('Where command can be one of the following:');
|
||||
print(' multiple-outputs output_directory_path [sdk_path]');
|
||||
print(' Generate separate summary and index files.');
|
||||
print(' single-output output_file_path [sdk_path]');
|
||||
print(' Generate a single file with summary and index.');
|
||||
print(' extract-spec-sum input_file output_file');
|
||||
print(' Extract the spec-mode summary file.');
|
||||
print(' extract-strong-sum input_file output_file');
|
||||
print(' Extract the strong-mode summary file.');
|
||||
print(' extract-spec-index input_file output_file');
|
||||
print(' Extract the spec-mode index file.');
|
||||
print(' extract-strong-index input_file output_file');
|
||||
print(' Extract the strong-mode index file.');
|
||||
}
|
||||
|
||||
class _Builder {
|
||||
final String sdkPath;
|
||||
final String outputDirectoryPath;
|
||||
final bool strongMode;
|
||||
|
||||
AnalysisContext context;
|
||||
|
@ -74,12 +171,12 @@ class _Builder {
|
|||
final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler();
|
||||
final PackageIndexAssembler indexAssembler = new PackageIndexAssembler();
|
||||
|
||||
_Builder(this.sdkPath, this.outputDirectoryPath, this.strongMode);
|
||||
_Builder(this.sdkPath, this.strongMode);
|
||||
|
||||
/**
|
||||
* Build a strong or spec mode summary for the Dart SDK at [sdkPath].
|
||||
*/
|
||||
void build() {
|
||||
_BuilderOutput build() {
|
||||
String modeName = strongMode ? 'strong' : 'spec';
|
||||
print('Generating $modeName mode summary and index.');
|
||||
Stopwatch sw = new Stopwatch()..start();
|
||||
|
@ -107,27 +204,12 @@ class _Builder {
|
|||
_serializeLibrary(libSource);
|
||||
}
|
||||
//
|
||||
// Write the whole SDK bundle.
|
||||
//
|
||||
{
|
||||
PackageBundleBuilder bundle = bundleAssembler.assemble();
|
||||
String outputPath = join(outputDirectoryPath, '$modeName.sum');
|
||||
File file = new File(outputPath);
|
||||
file.writeAsBytesSync(bundle.toBuffer(), mode: FileMode.WRITE_ONLY);
|
||||
}
|
||||
//
|
||||
// Write the whole SDK index.
|
||||
//
|
||||
{
|
||||
PackageIndexBuilder index = indexAssembler.assemble();
|
||||
String outputPath = join(outputDirectoryPath, '$modeName.index');
|
||||
File file = new File(outputPath);
|
||||
file.writeAsBytesSync(index.toBuffer(), mode: FileMode.WRITE_ONLY);
|
||||
}
|
||||
//
|
||||
// Done.
|
||||
// Assemble the output.
|
||||
//
|
||||
List<int> sumBytes = bundleAssembler.assemble().toBuffer();
|
||||
List<int> indexBytes = indexAssembler.assemble().toBuffer();
|
||||
print('\tDone in ${sw.elapsedMilliseconds} ms.');
|
||||
return new _BuilderOutput(sumBytes, indexBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,3 +233,32 @@ class _Builder {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _BuilderOutput {
|
||||
final List<int> sum;
|
||||
final List<int> index;
|
||||
|
||||
_BuilderOutput(this.sum, this.index);
|
||||
|
||||
void writeMultiple(String outputDirectoryPath, String modeName) {
|
||||
// Write summary.
|
||||
{
|
||||
String outputPath = join(outputDirectoryPath, '$modeName.sum');
|
||||
File file = new File(outputPath);
|
||||
file.writeAsBytesSync(sum, mode: FileMode.WRITE_ONLY);
|
||||
}
|
||||
// Write index.
|
||||
{
|
||||
String outputPath = join(outputDirectoryPath, '$modeName.index');
|
||||
File file = new File(outputPath);
|
||||
file.writeAsBytesSync(index, mode: FileMode.WRITE_ONLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _Output {
|
||||
final _BuilderOutput spec;
|
||||
final _BuilderOutput strong;
|
||||
|
||||
_Output(this.spec, this.strong);
|
||||
}
|
||||
|
|
|
@ -32,22 +32,56 @@
|
|||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'generate_summaries',
|
||||
'action_name': 'generate_summary_bundle',
|
||||
'inputs': [
|
||||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/packages.stamp',
|
||||
'<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../sdk/lib"])',
|
||||
'<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../pkg/analyzer"])',
|
||||
],
|
||||
'outputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
],
|
||||
'action': [
|
||||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'--package-root=<(PRODUCT_DIR)/packages/',
|
||||
'../../pkg/analyzer/tool/summary/build_sdk_summaries.dart',
|
||||
'single-output',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'extract_spec_summary',
|
||||
'inputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
],
|
||||
'outputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/spec.sum',
|
||||
],
|
||||
'action': [
|
||||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'--package-root=<(PRODUCT_DIR)/packages/',
|
||||
'../../pkg/analyzer/tool/summary/build_sdk_summaries.dart',
|
||||
'extract-spec-sum',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/spec.sum',
|
||||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'extract_strong_summary',
|
||||
'inputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
],
|
||||
'outputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/strong.sum',
|
||||
],
|
||||
'action': [
|
||||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'--package-root=<(PRODUCT_DIR)/packages/',
|
||||
'../../pkg/analyzer/tool/summary/build_sdk_summaries.dart',
|
||||
'<(SHARED_INTERMEDIATE_DIR)',
|
||||
'extract-strong-sum',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/strong.sum',
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue