未验证 提交 7c805c0a 编写于 作者: J Jacob Richman 提交者: GitHub

Track widget creation locations. (#4529)

* Track widget creation locations.
上级 439edca2
name: flutter_kernel_transformers
version: 0.0.1-dev
description: Kernel transformers that operate on Flutter source code.
homepage: http://flutter.io
author: Flutter Authors <flutter-dev@googlegroups.com>
dependencies:
kernel: any
meta: any
dev_dependencies:
test: any
when: any
dependency_overrides:
args:
path: ../../third_party/dart/third_party/pkg/args
async:
path: ../../third_party/dart/third_party/pkg/async
charcode:
path: ../../third_party/dart/third_party/pkg/charcode
collection:
path: ../../third_party/dart/third_party/pkg/collection
convert:
path: ../../third_party/dart/third_party/pkg/convert
crypto:
path: ../../third_party/dart/third_party/pkg/crypto
front_end:
path: ../../third_party/dart/pkg/front_end/
kernel:
path: ../../third_party/dart/pkg/kernel/
logging:
path: ../../third_party/dart/third_party/pkg/logging
meta:
path: ../../third_party/dart/pkg/meta
quiver:
path: ../../third_party/dart/third_party/pkg/quiver
package_config:
path: ../../third_party/dart/third_party/pkg_tested/package_config
path:
path: ../../third_party/dart/third_party/pkg/path
source_span:
path: ../../third_party/dart/third_party/pkg/source_span
typed_data:
path: ../../third_party/dart/third_party/pkg/typed_data
usage:
path: ../../third_party/dart/third_party/pkg/usage
vm:
path: ../../third_party/dart/pkg/vm/
analyzer:
path: ../../third_party/dart/pkg/analyzer
barback:
path: ../../third_party/dart/third_party/pkg/barback
boolean_selector:
path: ../../third_party/dart/third_party/pkg/boolean_selector
cli_util:
path: ../../third_party/dart/third_party/pkg/cli_util
csslib:
path: ../../third_party/dart/third_party/pkg/csslib
glob:
path: ../../third_party/dart/third_party/pkg/glob
html:
path: ../../third_party/dart/third_party/pkg/html
http:
path: ../../third_party/dart/third_party/pkg/http
http_multi_server:
path: ../../third_party/dart/third_party/pkg/http_multi_server
http_parser:
path: ../../third_party/dart/third_party/pkg/http_parser
isolate:
path: ../../third_party/dart/third_party/pkg/isolate
matcher:
path: ../../third_party/dart/third_party/pkg/matcher
mime:
path: ../../third_party/dart/third_party/pkg/mime
mockito:
path: ../../third_party/dart/third_party/pkg/mockito
package_resolver:
path: ../../third_party/dart/third_party/pkg_tested/package_resolver
plugin:
path: ../../third_party/dart/third_party/pkg/plugin
pool:
path: ../../third_party/dart/third_party/pkg/pool
pub_semver:
path: ../../third_party/dart/third_party/pkg/pub_semver
shelf:
path: ../../third_party/dart/third_party/pkg/shelf
shelf_packages_handler:
path: ../../third_party/dart/third_party/pkg/shelf_packages_handler
shelf_static:
path: ../../third_party/dart/third_party/pkg/shelf_static
shelf_web_socket:
path: ../../third_party/dart/third_party/pkg/shelf_web_socket
source_map_stack_trace:
path: ../../third_party/dart/third_party/pkg/source_map_stack_trace
source_maps:
path: ../../third_party/dart/third_party/pkg/source_maps
stack_trace:
path: ../../third_party/dart/third_party/pkg/stack_trace
stream_channel:
path: ../../third_party/dart/third_party/pkg/stream_channel
string_scanner:
path: ../../third_party/dart/third_party/pkg/string_scanner
test:
path: ../../third_party/dart/third_party/pkg/test
utf:
path: ../../third_party/dart/third_party/pkg/utf
watcher:
path: ../../third_party/dart/third_party/pkg/watcher
web_socket_channel:
path: ../../third_party/dart/third_party/pkg/web_socket_channel
when:
path: ../../third_party/pkg/when
yaml:
path: ../../third_party/dart/third_party/pkg/yaml
...@@ -16,6 +16,9 @@ application_snapshot("frontend_server") { ...@@ -16,6 +16,9 @@ application_snapshot("frontend_server") {
frontend_server_files = exec_script("//third_party/dart/tools/list_dart_files.py", frontend_server_files = exec_script("//third_party/dart/tools/list_dart_files.py",
[ "absolute", rebase_path("."), ], "list lines") [ "absolute", rebase_path("."), ], "list lines")
frontend_server_files += exec_script("//third_party/dart/tools/list_dart_files.py",
[ "absolute", rebase_path("../flutter_kernel_transformers"), ], "list lines")
frontend_server_files += exec_script("//third_party/dart/tools/list_dart_files.py", frontend_server_files += exec_script("//third_party/dart/tools/list_dart_files.py",
[ "absolute", rebase_path("../../third_party/dart/pkg"), ], "list lines") [ "absolute", rebase_path("../../third_party/dart/pkg"), ], "list lines")
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library frontend_server; library frontend_server;
import 'dart:async'; import 'dart:async';
...@@ -22,6 +26,8 @@ import 'package:usage/uuid/uuid.dart'; ...@@ -22,6 +26,8 @@ import 'package:usage/uuid/uuid.dart';
import 'package:vm/incremental_compiler.dart' show IncrementalCompiler; import 'package:vm/incremental_compiler.dart' show IncrementalCompiler;
import 'package:vm/kernel_front_end.dart' show compileToKernel; import 'package:vm/kernel_front_end.dart' show compileToKernel;
import 'package:flutter_kernel_transformers/track_widget_constructor_locations.dart';
ArgParser _argParser = new ArgParser(allowTrailingOptions: true) ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
..addFlag('train', ..addFlag('train',
help: 'Run through sample command line to produce snapshot', help: 'Run through sample command line to produce snapshot',
...@@ -46,7 +52,10 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true) ...@@ -46,7 +52,10 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
defaultsTo: true) defaultsTo: true)
..addOption('packages', ..addOption('packages',
help: '.packages file to use for compilation', help: '.packages file to use for compilation',
defaultsTo: null); defaultsTo: null)
..addFlag('track-widget-creation',
help: 'Run a kernel transformer to track creation locations for widgets.',
defaultsTo: false);
String _usage = ''' String _usage = '''
Usage: server [options] [input.dart] Usage: server [options] [input.dart]
...@@ -115,9 +124,12 @@ class BinaryPrinterFactory { ...@@ -115,9 +124,12 @@ class BinaryPrinterFactory {
} }
class _FrontendCompiler implements CompilerInterface { class _FrontendCompiler implements CompilerInterface {
_FrontendCompiler(this._outputStream, {this.printerFactory}) { _FrontendCompiler(this._outputStream, {this.printerFactory, this.trackWidgetCreation}) {
_outputStream ??= stdout; _outputStream ??= stdout;
printerFactory ??= new BinaryPrinterFactory(); printerFactory ??= new BinaryPrinterFactory();
if (trackWidgetCreation) {
widgetCreatorTracker = new WidgetCreatorTracker();
}
} }
StringSink _outputStream; StringSink _outputStream;
...@@ -130,6 +142,8 @@ class _FrontendCompiler implements CompilerInterface { ...@@ -130,6 +142,8 @@ class _FrontendCompiler implements CompilerInterface {
String _kernelBinaryFilename; String _kernelBinaryFilename;
String _kernelBinaryFilenameIncremental; String _kernelBinaryFilenameIncremental;
String _kernelBinaryFilenameFull; String _kernelBinaryFilenameFull;
final bool trackWidgetCreation;
WidgetCreatorTracker widgetCreatorTracker;
@override @override
Future<Null> compile( Future<Null> compile(
...@@ -171,6 +185,7 @@ class _FrontendCompiler implements CompilerInterface { ...@@ -171,6 +185,7 @@ class _FrontendCompiler implements CompilerInterface {
program = await _runWithPrintRedirection(() => program = await _runWithPrintRedirection(() =>
compileToKernel(filenameUri, compilerOptions, aot: options['aot'])); compileToKernel(filenameUri, compilerOptions, aot: options['aot']));
} }
runFlutterSpecificKernelTransforms(program);
if (program != null) { if (program != null) {
final IOSink sink = new File(_kernelBinaryFilename).openWrite(); final IOSink sink = new File(_kernelBinaryFilename).openWrite();
final BinaryPrinter printer = printerFactory.newBinaryPrinter(sink); final BinaryPrinter printer = printerFactory.newBinaryPrinter(sink);
...@@ -223,12 +238,23 @@ class _FrontendCompiler implements CompilerInterface { ...@@ -223,12 +238,23 @@ class _FrontendCompiler implements CompilerInterface {
} }
} }
void runFlutterSpecificKernelTransforms(Program program) {
if (program == null) {
return;
}
if (trackWidgetCreation) {
widgetCreatorTracker.transform(program);
}
}
@override @override
Future<Null> recompileDelta() async { Future<Null> recompileDelta() async {
final String boundaryKey = new Uuid().generateV4(); final String boundaryKey = new Uuid().generateV4();
_outputStream.writeln('result $boundaryKey'); _outputStream.writeln('result $boundaryKey');
await invalidateIfBootstrapping(); await invalidateIfBootstrapping();
final Program deltaProgram = await _generator.compile(); final Program deltaProgram = await _generator.compile();
runFlutterSpecificKernelTransforms(deltaProgram);
final IOSink sink = new File(_kernelBinaryFilename).openWrite(); final IOSink sink = new File(_kernelBinaryFilename).openWrite();
final BinaryPrinter printer = printerFactory.newBinaryPrinter(sink); final BinaryPrinter printer = printerFactory.newBinaryPrinter(sink);
printer.writeProgramFile(deltaProgram); printer.writeProgramFile(deltaProgram);
...@@ -267,6 +293,7 @@ class _FrontendCompiler implements CompilerInterface { ...@@ -267,6 +293,7 @@ class _FrontendCompiler implements CompilerInterface {
return Uri.base.resolve(uriPath); return Uri.base.resolve(uriPath);
} }
/// Runs the given function [f] in a Zone that redirects all prints into /// Runs the given function [f] in a Zone that redirects all prints into
/// [_outputStream]. /// [_outputStream].
Future<T> _runWithPrintRedirection<T>(Future<T> f()) { Future<T> _runWithPrintRedirection<T>(Future<T> f()) {
...@@ -314,8 +341,11 @@ Future<int> starter( ...@@ -314,8 +341,11 @@ Future<int> starter(
return 0; return 0;
} }
compiler ??= compiler ??= new _FrontendCompiler(
new _FrontendCompiler(output, printerFactory: binaryPrinterFactory); output,
printerFactory: binaryPrinterFactory,
trackWidgetCreation: options['track-widget-creation'],
);
input ??= stdin; input ??= stdin;
// Has to be a directory, that won't have any of the compiled application // Has to be a directory, that won't have any of the compiled application
......
...@@ -12,6 +12,7 @@ dependencies: ...@@ -12,6 +12,7 @@ dependencies:
convert: any convert: any
crypto: any crypto: any
front_end: any front_end: any
flutter_kernel_transformers: any
kernel: any kernel: any
logging: any logging: any
meta: any meta: any
...@@ -71,6 +72,8 @@ dependency_overrides: ...@@ -71,6 +72,8 @@ dependency_overrides:
path: ../../third_party/dart/third_party/pkg/convert path: ../../third_party/dart/third_party/pkg/convert
crypto: crypto:
path: ../../third_party/dart/third_party/pkg/crypto path: ../../third_party/dart/third_party/pkg/crypto
flutter_kernel_transformers:
path: ../flutter_kernel_transformers
front_end: front_end:
path: ../../third_party/dart/pkg/front_end/ path: ../../third_party/dart/pkg/front_end/
kernel: kernel:
......
...@@ -32,3 +32,18 @@ if [ -n "$RESULTS" ]; then ...@@ -32,3 +32,18 @@ if [ -n "$RESULTS" ]; then
echo "Failed." echo "Failed."
exit 1; exit 1;
fi fi
echo "Analyzing flutter_kernel_transformers..."
pushd flutter/flutter_kernel_transformers/; pub get; popd
RESULTS=`dartanalyzer \
--packages=flutter/flutter_kernel_transformers/.packages \
--options flutter/analysis_options.yaml \
flutter/flutter_kernel_transformers \
2>&1 \
| grep -Ev "No issues found!" \
| grep -Ev "Analyzing.+flutter_kernel_transformers"`
echo "$RESULTS"
if [ -n "$RESULTS" ]; then
echo "Failed."
exit 1;
fi
...@@ -1881,12 +1881,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -1881,12 +1881,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==================================================================================================== ====================================================================================================
LIBRARY: engine LIBRARY: engine
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../LICENSE ORIGIN: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart + ../../../LICENSE
TYPE: LicenseType.bsd TYPE: LicenseType.bsd
FILE: ../../../flutter/fml/platform/darwin/scoped_block.h FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart
FILE: ../../../flutter/sky/engine/wtf/allocator/PartitionAllocator.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
Copyright (c) 2013 The Chromium Authors. All rights reserved. Copyright 2018 The Chromium Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
...@@ -1917,17 +1918,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -1917,17 +1918,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==================================================================================================== ====================================================================================================
LIBRARY: engine LIBRARY: engine
ORIGIN: ../../../flutter/lib/ui/painting/image.cc + ../../../LICENSE ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../LICENSE
TYPE: LicenseType.bsd TYPE: LicenseType.bsd
FILE: ../../../flutter/lib/ui/painting/image.cc FILE: ../../../flutter/fml/platform/darwin/scoped_block.h
FILE: ../../../flutter/lib/ui/painting/image.h FILE: ../../../flutter/sky/engine/wtf/allocator/PartitionAllocator.h
FILE: ../../../flutter/shell/common/switches.cc
FILE: ../../../flutter/shell/common/switches.h
FILE: ../../../flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterMain.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterView.java
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
Copyright 2013 The Chromium Authors. All rights reserved. Copyright (c) 2013 The Chromium Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
...@@ -1958,12 +1954,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -1958,12 +1954,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==================================================================================================== ====================================================================================================
LIBRARY: engine LIBRARY: engine
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h + ../../../LICENSE ORIGIN: ../../../flutter/lib/ui/painting/image.cc + ../../../LICENSE
TYPE: LicenseType.bsd TYPE: LicenseType.bsd
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h FILE: ../../../flutter/lib/ui/painting/image.cc
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm FILE: ../../../flutter/lib/ui/painting/image.h
FILE: ../../../flutter/shell/common/switches.cc
FILE: ../../../flutter/shell/common/switches.h
FILE: ../../../flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterMain.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterView.java
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
Copyright 2018 The Chromium Authors. All rights reserved. Copyright 2013 The Chromium Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册