Build non-nullable or legacy SDK summary.

Bug: https://github.com/dart-lang/sdk/issues/38666
Change-Id: I24f6f36b5ed1dbef64588dd787aaf2abbd62f53c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132800
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2020-01-22 18:02:08 +00:00 committed by commit-bot@chromium.org
parent e685ff5131
commit b663ef5cc4
6 changed files with 71 additions and 22 deletions

View file

@ -7,6 +7,7 @@ import 'dart:async';
import 'package:analysis_server/src/context_manager.dart';
import 'package:analysis_server/src/plugin/notification_manager.dart';
import 'package:analysis_server/src/utilities/null_string_sink.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/file_system/file_system.dart';
@ -1939,7 +1940,7 @@ include: package:boo/other_options.yaml
var synchronousSession = SynchronousSession(analysisOptions, null);
List<int> bytes =
SummaryBuilder([], AnalysisContextImpl(synchronousSession, null))
.build();
.build(featureSet: FeatureSet.fromEnableFlags([]));
newFileWithBytes('$projPath/sdk.ds', bytes);
// Setup _embedder.yaml.
newFile('$libPath/_embedder.yaml', content: r'''

View file

@ -22,6 +22,7 @@ import 'package:analyzer/src/summary/summarize_elements.dart';
import 'package:analyzer/src/summary2/link.dart' as summary2;
import 'package:analyzer/src/summary2/linked_element_factory.dart' as summary2;
import 'package:analyzer/src/summary2/reference.dart' as summary2;
import 'package:meta/meta.dart';
class SummaryBuilder {
final Iterable<Source> librarySources;
@ -63,11 +64,16 @@ class SummaryBuilder {
/**
* Build the linked bundle and return its bytes.
*/
List<int> build() => _Builder(context, librarySources).build();
List<int> build({
@required FeatureSet featureSet,
}) {
return _Builder(context, featureSet, librarySources).build();
}
}
class _Builder {
final AnalysisContext context;
final FeatureSet featureSet;
final Iterable<Source> librarySources;
final Set<String> libraryUris = <String>{};
@ -75,7 +81,7 @@ class _Builder {
final PackageBundleAssembler bundleAssembler = PackageBundleAssembler();
_Builder(this.context, this.librarySources);
_Builder(this.context, this.featureSet, this.librarySources);
/**
* Build the linked bundle and return its bytes.
@ -132,14 +138,12 @@ class _Builder {
AnalysisErrorListener errorListener = AnalysisErrorListener.NULL_LISTENER;
String code = source.contents.data;
CharSequenceReader reader = CharSequenceReader(code);
// TODO(paulberry): figure out the appropriate featureSet to use here
var featureSet = FeatureSet.fromEnableFlags([]);
Scanner scanner = Scanner(source, reader, errorListener)
..configureFeatures(featureSet);
Token token = scanner.tokenize();
LineInfo lineInfo = LineInfo(scanner.lineStarts);
Parser parser = Parser(source, errorListener,
featureSet: featureSet,
featureSet: scanner.featureSet,
useFasta: context.analysisOptions.useFastaParser);
parser.enableOptionalNewAndConst = true;
CompilationUnit unit = parser.parseCompilationUnit(token);

View file

@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/context/context.dart';
@ -1022,7 +1023,10 @@ class MockSdk implements DartSdk {
List<Source> librarySources = sdkLibraries
.map((SdkLibrary library) => mapDartUri(library.shortName))
.toList();
return SummaryBuilder(librarySources, context).build();
var featureSet = FeatureSet.fromEnableFlags([]);
return SummaryBuilder(librarySources, context).build(
featureSet: featureSet,
);
}
}

View file

@ -1,8 +1,14 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/dart/sdk/sdk.dart';
import 'package:analyzer/src/summary/summary_file_builder.dart';
import 'package:meta/meta.dart';
void main(List<String> args) {
String command;
@ -36,8 +42,20 @@ void main(List<String> args) {
//
// Handle commands.
//
if (command == 'build-strong') {
_buildSummary(sdkPath, outFilePath);
if (command == 'build-non-nullable') {
_buildSummary(
sdkPath,
outFilePath,
enabledExperiments: ['non-nullable'],
title: 'non-nullable',
);
} else if (command == 'build-legacy' || command == 'build-strong') {
_buildSummary(
sdkPath,
outFilePath,
enabledExperiments: [],
title: 'legacy',
);
} else {
_printUsage();
return;
@ -49,10 +67,18 @@ void main(List<String> args) {
*/
const BINARY_NAME = "build_sdk_summaries";
void _buildSummary(String sdkPath, String outPath) {
print('Generating strong mode summary.');
void _buildSummary(
String sdkPath,
String outPath, {
@required List<String> enabledExperiments,
@required String title,
}) {
print('Generating $title summary.');
Stopwatch sw = Stopwatch()..start();
List<int> bytes = SummaryBuilder.forSdk(sdkPath).build();
var featureSet = FeatureSet.fromEnableFlags(enabledExperiments);
List<int> bytes = SummaryBuilder.forSdk(sdkPath).build(
featureSet: featureSet,
);
File(outPath).writeAsBytesSync(bytes, mode: FileMode.writeOnly);
print('\tDone in ${sw.elapsedMilliseconds} ms.');
}
@ -63,6 +89,8 @@ void _buildSummary(String sdkPath, String outPath) {
void _printUsage() {
print('Usage: $BINARY_NAME command arguments');
print('Where command can be one of the following:');
print(' build-strong output_file [sdk_path]');
print(' Generate strong mode summary file.');
print(' build-non-nullable output_file [sdk_path]');
print(' Generate non-nullable summary file.');
print(' build-legacy output_file [sdk_path]');
print(' Generate legacy summary file.');
}

View file

@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:io' as io;
import 'dart:isolate';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
@ -158,9 +159,12 @@ class Driver with HasContextMixin implements CommandLineStarter {
print('\nGenerating strong mode summary...');
final Stopwatch stopwatch = Stopwatch()..start();
SummaryBuilder.forSdk(options.dartSdkPath).build();
SummaryBuilder.forSdk(options.dartSdkPath).build();
SummaryBuilder.forSdk(options.dartSdkPath).build();
for (var i = 0; i < 3; i++) {
var featureSet = FeatureSet.fromEnableFlags([]);
SummaryBuilder.forSdk(options.dartSdkPath).build(
featureSet: featureSet,
);
}
print('Done in ${stopwatch.elapsedMilliseconds} ms.');
}

View file

@ -46,9 +46,17 @@ prebuilt_dart_action("generate_summary_strong") {
outputs = [
output,
]
args = [
"build-strong",
rebase_path(output),
rebase_path("../../sdk"),
]
if (use_nnbd) {
args = [
"build-non-nullable",
rebase_path(output),
rebase_path("../../sdk_nnbd"),
]
} else {
args = [
"build-legacy",
rebase_path(output),
rebase_path("../../sdk"),
]
}
}