mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Stop generating index information for SDK and simplify summary generation.
The implementation is still element model based, I will switch it to the AST based approach in a following CL. R=paulberry@google.com BUG= Review URL: https://codereview.chromium.org/2345793002 .
This commit is contained in:
parent
4af56d5647
commit
fa24d1caaa
|
@ -5,9 +5,7 @@
|
|||
library analyzer.src.summary.summary_file_builder;
|
||||
|
||||
import 'dart:collection';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/file_system/physical_file_system.dart';
|
||||
|
@ -15,118 +13,37 @@ import 'package:analyzer/src/dart/sdk/sdk.dart';
|
|||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:analyzer/src/generated/source.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';
|
||||
|
||||
const int FIELD_SPEC_INDEX = 1;
|
||||
const int FIELD_SPEC_SUM = 0;
|
||||
const int FIELD_STRONG_INDEX = 3;
|
||||
const int FIELD_STRONG_SUM = 2;
|
||||
|
||||
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');
|
||||
io.File file = new io.File(outputPath);
|
||||
file.writeAsBytesSync(sum, mode: io.FileMode.WRITE_ONLY);
|
||||
}
|
||||
// Write index.
|
||||
{
|
||||
String outputPath = join(outputDirectoryPath, '$modeName.index');
|
||||
io.File file = new io.File(outputPath);
|
||||
file.writeAsBytesSync(index, mode: io.FileMode.WRITE_ONLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary build configuration.
|
||||
*/
|
||||
class SummaryBuildConfig {
|
||||
/**
|
||||
* Whether to use exclude informative data from created summaries.
|
||||
*/
|
||||
final bool buildSummaryExcludeInformative;
|
||||
|
||||
/**
|
||||
* Whether to output a summary in "fallback mode".
|
||||
*/
|
||||
final bool buildSummaryFallback;
|
||||
|
||||
/**
|
||||
* Whether to create summaries directly from ASTs, i.e. don't create a
|
||||
* full element model.
|
||||
*/
|
||||
final bool buildSummaryOnlyAst;
|
||||
|
||||
/**
|
||||
* Path to the dart SDK summary file.
|
||||
*/
|
||||
final String dartSdkSummaryPath;
|
||||
|
||||
/**
|
||||
* Whether to use strong static checking.
|
||||
*/
|
||||
final bool strongMode;
|
||||
|
||||
/**
|
||||
* List of summary input file paths.
|
||||
*/
|
||||
final Iterable<String> summaryInputs;
|
||||
|
||||
/**
|
||||
* Create a build configuration with the given set options.
|
||||
*/
|
||||
SummaryBuildConfig(
|
||||
{this.strongMode: false,
|
||||
this.summaryInputs,
|
||||
this.dartSdkSummaryPath,
|
||||
this.buildSummaryExcludeInformative: false,
|
||||
this.buildSummaryFallback: false,
|
||||
this.buildSummaryOnlyAst: false});
|
||||
}
|
||||
|
||||
class SummaryBuilder {
|
||||
final AnalysisContext context;
|
||||
final Iterable<Source> librarySources;
|
||||
final SummaryBuildConfig config;
|
||||
final AnalysisContext context;
|
||||
final bool strong;
|
||||
|
||||
/**
|
||||
* Create a summary builder for these [librarySources] and [context] using the
|
||||
* given [config].
|
||||
* Create a summary builder for these [librarySources] and [context].
|
||||
*/
|
||||
SummaryBuilder(this.librarySources, this.context, this.config);
|
||||
SummaryBuilder(this.librarySources, this.context, this.strong);
|
||||
|
||||
/**
|
||||
* Create an SDK summary builder for the dart SDK at the given [sdkPath],
|
||||
* using this [config].
|
||||
* Create an SDK summary builder for the dart SDK at the given [sdkPath].
|
||||
*/
|
||||
factory SummaryBuilder.forSdk(String sdkPath, SummaryBuildConfig config) {
|
||||
bool strongMode = config.strongMode;
|
||||
|
||||
factory SummaryBuilder.forSdk(String sdkPath, bool strong) {
|
||||
//
|
||||
// Prepare SDK.
|
||||
//
|
||||
ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE;
|
||||
FolderBasedDartSdk sdk = new FolderBasedDartSdk(
|
||||
resourceProvider, resourceProvider.getFolder(sdkPath), strongMode);
|
||||
resourceProvider, resourceProvider.getFolder(sdkPath), strong);
|
||||
sdk.useSummary = false;
|
||||
sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = strongMode;
|
||||
sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = strong;
|
||||
|
||||
//
|
||||
// Prepare 'dart:' URIs to serialize.
|
||||
//
|
||||
Set<String> uriSet =
|
||||
sdk.sdkLibraries.map((SdkLibrary library) => library.shortName).toSet();
|
||||
if (!strongMode) {
|
||||
if (!strong) {
|
||||
uriSet.add('dart:html/nativewrappers.dart');
|
||||
}
|
||||
uriSet.add('dart:html_common/html_common_dart2js.dart');
|
||||
|
@ -136,68 +53,30 @@ class SummaryBuilder {
|
|||
librarySources.add(sdk.mapDartUri(uri));
|
||||
}
|
||||
|
||||
return new SummaryBuilder(librarySources, sdk.context, config);
|
||||
return new SummaryBuilder(librarySources, sdk.context, strong);
|
||||
}
|
||||
|
||||
BuilderOutput build() => new _Builder(context, librarySources).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Intermediary summary output result.
|
||||
*/
|
||||
class SummaryOutput {
|
||||
final BuilderOutput spec;
|
||||
final BuilderOutput strong;
|
||||
SummaryOutput(this.spec, this.strong);
|
||||
|
||||
/**
|
||||
* Write this summary output to the given [outputPath] and return the
|
||||
* created file.
|
||||
* Build the linked bundle and return its bytes.
|
||||
*/
|
||||
io.File write(String outputPath) {
|
||||
fb.Builder builder = new fb.Builder();
|
||||
fb.Offset specSumOffset = builder.writeListUint8(spec.sum);
|
||||
fb.Offset specIndexOffset = builder.writeListUint8(spec.index);
|
||||
fb.Offset strongSumOffset = builder.writeListUint8(strong.sum);
|
||||
fb.Offset strongIndexOffset = builder.writeListUint8(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();
|
||||
return new io.File(outputPath)
|
||||
..writeAsBytesSync(builder.finish(offset), mode: io.FileMode.WRITE_ONLY);
|
||||
}
|
||||
List<int> build() => new _Builder(context, librarySources).build();
|
||||
}
|
||||
|
||||
class _Builder {
|
||||
final Set<Source> processedSources = new Set<Source>();
|
||||
|
||||
final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler();
|
||||
final PackageIndexAssembler indexAssembler = new PackageIndexAssembler();
|
||||
|
||||
final AnalysisContext context;
|
||||
final Iterable<Source> librarySources;
|
||||
|
||||
final Set<Source> processedSources = new Set<Source>();
|
||||
final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler();
|
||||
|
||||
_Builder(this.context, this.librarySources);
|
||||
|
||||
/**
|
||||
* Build summary output.
|
||||
* Build the linked bundle and return its bytes.
|
||||
*/
|
||||
BuilderOutput build() {
|
||||
//
|
||||
// Serialize each source.
|
||||
//
|
||||
for (Source source in librarySources) {
|
||||
_serializeLibrary(source);
|
||||
}
|
||||
//
|
||||
// Assemble the output.
|
||||
//
|
||||
List<int> sumBytes = bundleAssembler.assemble().toBuffer();
|
||||
List<int> indexBytes = indexAssembler.assemble().toBuffer();
|
||||
return new BuilderOutput(sumBytes, indexBytes);
|
||||
List<int> build() {
|
||||
librarySources.forEach(_serializeLibrary);
|
||||
return bundleAssembler.assemble().toBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,12 +91,5 @@ class _Builder {
|
|||
bundleAssembler.serializeLibraryElement(element);
|
||||
element.importedLibraries.forEach((e) => _serializeLibrary(e.source));
|
||||
element.exportedLibraries.forEach((e) => _serializeLibrary(e.source));
|
||||
// Index every unit of the library.
|
||||
for (CompilationUnitElement unitElement in element.units) {
|
||||
Source unitSource = unitElement.source;
|
||||
CompilationUnit unit =
|
||||
context.resolveCompilationUnit2(unitSource, source);
|
||||
indexAssembler.indexUnit(unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,83 +2,46 @@ import 'dart:io';
|
|||
|
||||
import 'package:analyzer/file_system/physical_file_system.dart';
|
||||
import 'package:analyzer/src/dart/sdk/sdk.dart';
|
||||
import 'package:analyzer/src/summary/flat_buffers.dart' as fb;
|
||||
import 'package:analyzer/src/summary/summary_file_builder.dart';
|
||||
|
||||
main(List<String> args) {
|
||||
if (args.length < 1) {
|
||||
String command;
|
||||
String outFilePath;
|
||||
String sdkPath;
|
||||
if (args.length == 2) {
|
||||
command = args[0];
|
||||
outFilePath = args[1];
|
||||
} else if (args.length == 3) {
|
||||
command = args[0];
|
||||
outFilePath = args[1];
|
||||
sdkPath = args[2];
|
||||
} else {
|
||||
_printUsage();
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
String command = args[0];
|
||||
if ((command == 'multiple-outputs' || command == 'strong-outputs') &&
|
||||
args.length >= 2 &&
|
||||
args.length <= 3) {
|
||||
bool includeSpec = command != 'strong-outputs';
|
||||
//
|
||||
// Prepare the output path.
|
||||
//
|
||||
String outputDirectoryPath = args[1];
|
||||
if (!FileSystemEntity.isDirectorySync(outputDirectoryPath)) {
|
||||
print("'$outputDirectoryPath' is not a directory.");
|
||||
_printUsage();
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
//
|
||||
// Prepare results.
|
||||
//
|
||||
String sdkPath = args.length > 2 ? args[2] : null;
|
||||
SummaryOutput output = _buildMultipleOutputs(sdkPath, includeSpec);
|
||||
if (output == null) {
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
//
|
||||
// Write results.
|
||||
//
|
||||
if (includeSpec) {
|
||||
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.
|
||||
//
|
||||
SummaryOutput output = _buildMultipleOutputs(sdkPath, true);
|
||||
if (output == null) {
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Write results.
|
||||
//
|
||||
output.write(outputPath);
|
||||
} 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);
|
||||
//
|
||||
// Validate the SDK path.
|
||||
//
|
||||
sdkPath ??= FolderBasedDartSdk
|
||||
.defaultSdkDirectory(PhysicalResourceProvider.INSTANCE)
|
||||
.path;
|
||||
if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
|
||||
print("'$sdkPath/lib' does not exist.");
|
||||
_printUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle commands.
|
||||
//
|
||||
if (command == 'build-spec') {
|
||||
_buildSummary(sdkPath, outFilePath, false);
|
||||
} else if (command == 'build-strong') {
|
||||
_buildSummary(sdkPath, outFilePath, true);
|
||||
} else {
|
||||
_printUsage();
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -88,72 +51,23 @@ main(List<String> args) {
|
|||
*/
|
||||
const BINARY_NAME = "build_sdk_summaries";
|
||||
|
||||
SummaryOutput _buildMultipleOutputs(String sdkPath, bool includeSpec) {
|
||||
//
|
||||
// Validate the SDK path.
|
||||
//
|
||||
if (sdkPath != null) {
|
||||
if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
|
||||
print("'$sdkPath/lib' does not exist.");
|
||||
_printUsage();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
sdkPath = FolderBasedDartSdk
|
||||
.defaultSdkDirectory(PhysicalResourceProvider.INSTANCE)
|
||||
.path;
|
||||
}
|
||||
|
||||
//
|
||||
// Build spec and strong outputs.
|
||||
//
|
||||
BuilderOutput spec = includeSpec ? _buildOutput(sdkPath, false) : null;
|
||||
BuilderOutput strong = _buildOutput(sdkPath, true);
|
||||
return new SummaryOutput(spec, strong);
|
||||
}
|
||||
|
||||
BuilderOutput _buildOutput(String sdkPath, bool strongMode) {
|
||||
String modeName = strongMode ? 'strong' : 'spec';
|
||||
print('Generating $modeName mode summary and index.');
|
||||
void _buildSummary(String sdkPath, String outPath, bool strong) {
|
||||
String modeName = strong ? 'strong' : 'spec';
|
||||
print('Generating $modeName mode summary.');
|
||||
Stopwatch sw = new Stopwatch()..start();
|
||||
SummaryBuildConfig config = new SummaryBuildConfig(strongMode: strongMode);
|
||||
BuilderOutput output = new SummaryBuilder.forSdk(sdkPath, config).build();
|
||||
List<int> bytes = new SummaryBuilder.forSdk(sdkPath, strong).build();
|
||||
new File(outPath).writeAsBytesSync(bytes, mode: FileMode.WRITE_ONLY);
|
||||
print('\tDone in ${sw.elapsedMilliseconds} ms.');
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.BufferContext root = new fb.BufferContext.fromBytes(bytes);
|
||||
int tableOffset = root.derefObject(0);
|
||||
List<int> fieldBytes =
|
||||
const fb.Uint8ListReader().vTableGet(root, tableOffset, 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 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(' strong-outputs output_directory_path [sdk_path]');
|
||||
print(' Generate separate summary and index files (strong mode only).');
|
||||
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.');
|
||||
print(' build-spec output_file [sdk_path]');
|
||||
print(' Generate spec mode summary file.');
|
||||
print(' build-strong output_file [sdk_path]');
|
||||
print(' Generate strong mode summary file.');
|
||||
}
|
||||
|
|
|
@ -32,29 +32,13 @@
|
|||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'generate_summary_bundle',
|
||||
'action_name': 'generate_summary_spec',
|
||||
'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',
|
||||
],
|
||||
|
@ -62,15 +46,17 @@
|
|||
'<(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',
|
||||
'build-spec',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/spec.sum',
|
||||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'extract_strong_summary',
|
||||
'action_name': 'generate_summary_strong',
|
||||
'inputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
'<(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)/strong.sum',
|
||||
|
@ -79,8 +65,7 @@
|
|||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'--package-root=<(PRODUCT_DIR)/packages/',
|
||||
'../../pkg/analyzer/tool/summary/build_sdk_summaries.dart',
|
||||
'extract-strong-sum',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/sdk_summary_bundle.bin',
|
||||
'build-strong',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/strong.sum',
|
||||
],
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue