mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
Add --track-widget-creation flag to frontend_server.
This is needed to activate the kernel transformer embedded with the kernel package from the flutter engine. Change-Id: I3253e01723b662eb48b4b3743ac5bcc1b44c7d46 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102920 Reviewed-by: Jake Macdonald <jakemac@google.com> Reviewed-by: Aske Simon Christensen <askesc@google.com> Commit-Queue: Jacob Richman <jacobr@google.com>
This commit is contained in:
parent
6d76c8790d
commit
e2976acd22
|
@ -11,6 +11,7 @@ import 'package:build_integration/file_system/multi_root.dart';
|
|||
import 'package:cli_util/cli_util.dart' show getSdkPath;
|
||||
import 'package:front_end/src/api_unstable/ddc.dart' as fe;
|
||||
import 'package:kernel/kernel.dart' hide MapEntry;
|
||||
import 'package:kernel/target/targets.dart';
|
||||
import 'package:kernel/text/ast_to_text.dart' as kernel show Printer;
|
||||
import 'package:kernel/binary/ast_to_binary.dart' as kernel show BinaryPrinter;
|
||||
import 'package:path/path.dart' as path;
|
||||
|
@ -226,7 +227,8 @@ Future<CompilerResult> _compile(List<String> args,
|
|||
sourcePathToUri(packageFile),
|
||||
sourcePathToUri(librarySpecPath),
|
||||
summaryModules.keys.toList(),
|
||||
DevCompilerTarget(trackWidgetCreation: trackWidgetCreation),
|
||||
DevCompilerTarget(
|
||||
TargetFlags(trackWidgetCreation: trackWidgetCreation)),
|
||||
fileSystem: fileSystem,
|
||||
experiments: experiments);
|
||||
} else {
|
||||
|
@ -238,7 +240,8 @@ Future<CompilerResult> _compile(List<String> args,
|
|||
sourcePathToUri(packageFile),
|
||||
sourcePathToUri(librarySpecPath),
|
||||
summaryModules.keys.toList(),
|
||||
DevCompilerTarget(trackWidgetCreation: trackWidgetCreation),
|
||||
DevCompilerTarget(
|
||||
TargetFlags(trackWidgetCreation: trackWidgetCreation)),
|
||||
fileSystem: fileSystem,
|
||||
experiments: experiments);
|
||||
incrementalCompiler = compilerState.incrementalCompiler;
|
||||
|
|
|
@ -14,9 +14,9 @@ import 'kernel_helpers.dart';
|
|||
|
||||
/// A kernel [Target] to configure the Dart Front End for dartdevc.
|
||||
class DevCompilerTarget extends Target {
|
||||
DevCompilerTarget({this.trackWidgetCreation = false});
|
||||
DevCompilerTarget(this.flags);
|
||||
|
||||
final bool trackWidgetCreation;
|
||||
final TargetFlags flags;
|
||||
|
||||
ClassHierarchy hierarchy;
|
||||
|
||||
|
@ -103,7 +103,7 @@ class DevCompilerTarget extends Target {
|
|||
List<Library> libraries,
|
||||
DiagnosticReporter diagnosticReporter,
|
||||
{void logger(String msg)}) {
|
||||
if (trackWidgetCreation) {
|
||||
if (flags.trackWidgetCreation) {
|
||||
WidgetCreatorTracker().transform(component, libraries);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:front_end/src/api_unstable/ddc.dart' as fe;
|
|||
import 'package:kernel/core_types.dart';
|
||||
import 'package:kernel/kernel.dart';
|
||||
import 'package:kernel/class_hierarchy.dart';
|
||||
import 'package:kernel/target/targets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:dev_compiler/src/kernel/command.dart';
|
||||
|
@ -575,8 +576,8 @@ const nullCheck = const _NullCheck();
|
|||
var mainUri = Uri.file('/memory/test.dart');
|
||||
_fileSystem.entityForUri(mainUri).writeAsStringSync(code);
|
||||
var oldCompilerState = _compilerState;
|
||||
_compilerState = await fe.initializeCompiler(
|
||||
oldCompilerState, sdkUri, packagesUri, null, [], DevCompilerTarget(),
|
||||
_compilerState = await fe.initializeCompiler(oldCompilerState, sdkUri,
|
||||
packagesUri, null, [], DevCompilerTarget(TargetFlags()),
|
||||
fileSystem: _fileSystem, experiments: const {});
|
||||
if (!identical(oldCompilerState, _compilerState)) inference = null;
|
||||
fe.DdcResult result =
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'package:dev_compiler/src/kernel/compiler.dart';
|
|||
import 'package:front_end/src/api_unstable/ddc.dart'
|
||||
show CompilerOptions, kernelForComponent;
|
||||
import 'package:kernel/kernel.dart';
|
||||
import 'package:kernel/target/targets.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
Future main(List<String> args) async {
|
||||
|
@ -38,7 +39,7 @@ Future main(List<String> args) async {
|
|||
|
||||
var librarySpecPath = parserOptions['libraries'] as String;
|
||||
|
||||
var target = DevCompilerTarget();
|
||||
var target = DevCompilerTarget(TargetFlags());
|
||||
var options = CompilerOptions()
|
||||
..compileSdk = true
|
||||
// TODO(sigmund): remove this unnecessary option when possible.
|
||||
|
|
|
@ -11,8 +11,9 @@ final List<String> targetNames = targets.keys.toList();
|
|||
|
||||
class TargetFlags {
|
||||
final bool legacyMode;
|
||||
final bool trackWidgetCreation;
|
||||
|
||||
TargetFlags({this.legacyMode: false});
|
||||
TargetFlags({this.legacyMode = false, this.trackWidgetCreation = false});
|
||||
}
|
||||
|
||||
typedef Target _TargetBuilder(TargetFlags flags);
|
||||
|
|
|
@ -113,6 +113,9 @@ ArgParser argParser = new ArgParser(allowTrailingOptions: true)
|
|||
'improved speed.',
|
||||
defaultsTo: false,
|
||||
hide: true)
|
||||
..addFlag('track-widget-creation',
|
||||
help: 'Run a kernel transformer to track creation locations for widgets.',
|
||||
defaultsTo: false)
|
||||
..addMultiOption('enable-experiment',
|
||||
help: 'Comma separated list of experimental features, eg set-literals.',
|
||||
hide: true);
|
||||
|
@ -319,7 +322,10 @@ class FrontendCompiler implements CompilerInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
compilerOptions.target = createFrontEndTarget(options['target']);
|
||||
compilerOptions.target = createFrontEndTarget(
|
||||
options['target'],
|
||||
trackWidgetCreation: options['track-widget-creation'],
|
||||
);
|
||||
if (compilerOptions.target == null) {
|
||||
print('Failed to create front-end target ${options['target']}.');
|
||||
return false;
|
||||
|
|
|
@ -534,11 +534,13 @@ bool parseCommandLineDefines(
|
|||
}
|
||||
|
||||
/// Create front-end target with given name.
|
||||
Target createFrontEndTarget(String targetName) {
|
||||
Target createFrontEndTarget(String targetName,
|
||||
{bool trackWidgetCreation = false}) {
|
||||
// Make sure VM-specific targets are available.
|
||||
installAdditionalTargets();
|
||||
|
||||
final TargetFlags targetFlags = new TargetFlags();
|
||||
final TargetFlags targetFlags =
|
||||
new TargetFlags(trackWidgetCreation: trackWidgetCreation);
|
||||
return getTarget(targetName, targetFlags);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,7 @@ import 'package:kernel/transformations/track_widget_constructor_locations.dart';
|
|||
import 'package:vm/target/vm.dart' show VmTarget;
|
||||
|
||||
class FlutterTarget extends VmTarget {
|
||||
FlutterTarget(TargetFlags flags, {this.trackWidgetCreation = false})
|
||||
: super(flags);
|
||||
|
||||
final bool trackWidgetCreation;
|
||||
FlutterTarget(TargetFlags flags) : super(flags);
|
||||
|
||||
@override
|
||||
String get name => 'flutter';
|
||||
|
@ -55,7 +52,7 @@ class FlutterTarget extends VmTarget {
|
|||
List<Library> libraries,
|
||||
DiagnosticReporter diagnosticReporter,
|
||||
{void logger(String msg)}) {
|
||||
if (trackWidgetCreation) {
|
||||
if (flags.trackWidgetCreation) {
|
||||
new WidgetCreatorTracker().transform(component, libraries);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ final summaryArgsParser = new ArgParser()
|
|||
..addOption('output')
|
||||
..addFlag('reuse-compiler-result', defaultsTo: false)
|
||||
..addFlag('use-incremental-compiler', defaultsTo: false)
|
||||
..addFlag('track-kernel-creation', defaultsTo: false);
|
||||
..addFlag('track-widget-creation', defaultsTo: false);
|
||||
|
||||
class ComputeKernelResult {
|
||||
final bool succeeded;
|
||||
|
@ -172,13 +172,13 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
var excludeNonSources = parsedArgs['exclude-non-sources'] as bool;
|
||||
|
||||
var summaryOnly = parsedArgs['summary-only'] as bool;
|
||||
var trackKernelCreation = parsedArgs['track-kernel-creation'] as bool;
|
||||
var trackWidgetCreation = parsedArgs['track-widget-creation'] as bool;
|
||||
|
||||
// TODO(sigmund,jakemac): make target mandatory. We allow null to be backwards
|
||||
// compatible while we migrate existing clients of this tool.
|
||||
var targetName =
|
||||
(parsedArgs['target'] as String) ?? (summaryOnly ? 'ddc' : 'vm');
|
||||
var targetFlags = new TargetFlags();
|
||||
var targetFlags = new TargetFlags(trackWidgetCreation: trackWidgetCreation);
|
||||
Target target;
|
||||
switch (targetName) {
|
||||
case 'vm':
|
||||
|
@ -188,8 +188,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
}
|
||||
break;
|
||||
case 'flutter':
|
||||
target = new FlutterTarget(targetFlags,
|
||||
trackWidgetCreation: trackKernelCreation);
|
||||
target = new FlutterTarget(targetFlags);
|
||||
if (summaryOnly) {
|
||||
throw new ArgumentError(
|
||||
'error: --summary-only not supported for the flutter target');
|
||||
|
@ -212,8 +211,8 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
case 'ddc':
|
||||
// TODO(jakemac):If `generateKernel` changes to return a summary
|
||||
// component, process the component instead.
|
||||
target = new DevCompilerSummaryTarget(sources, excludeNonSources,
|
||||
trackWidgetCreation: trackKernelCreation);
|
||||
target =
|
||||
new DevCompilerSummaryTarget(sources, excludeNonSources, targetFlags);
|
||||
if (!summaryOnly) {
|
||||
out.writeln('error: --no-summary-only not supported for the '
|
||||
'ddc target');
|
||||
|
@ -332,9 +331,9 @@ class DevCompilerSummaryTarget extends DevCompilerTarget {
|
|||
final List<Uri> sources;
|
||||
final bool excludeNonSources;
|
||||
|
||||
DevCompilerSummaryTarget(this.sources, this.excludeNonSources,
|
||||
{trackWidgetCreation = false})
|
||||
: super(trackWidgetCreation: trackWidgetCreation);
|
||||
DevCompilerSummaryTarget(
|
||||
this.sources, this.excludeNonSources, TargetFlags targetFlags)
|
||||
: super(targetFlags);
|
||||
|
||||
@override
|
||||
void performOutlineTransformations(Component component) {
|
||||
|
|
Loading…
Reference in a new issue