Unverified Commit 2c05ecab authored by Jacob Richman's avatar Jacob Richman Committed by GitHub

Flutter tools support for kernel transformer tracking Widget creation locations. (#13997)

parent dfbbd30d
...@@ -260,7 +260,10 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -260,7 +260,10 @@ class FlutterPlugin implements Plugin<Project> {
if (project.hasProperty('preview-dart-2')) { if (project.hasProperty('preview-dart-2')) {
previewDart2Value = project.property('preview-dart-2') previewDart2Value = project.property('preview-dart-2')
} }
Boolean trackWidgetCreationValue = false
if (project.hasProperty('track-widget-creation')) {
trackWidgetCreationValue = project.property('track-widget-creation')
}
String extraFrontEndOptionsValue = null String extraFrontEndOptionsValue = null
if (project.hasProperty('extra-front-end-options')) { if (project.hasProperty('extra-front-end-options')) {
extraFrontEndOptionsValue = project.property('extra-front-end-options') extraFrontEndOptionsValue = project.property('extra-front-end-options')
...@@ -299,6 +302,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -299,6 +302,7 @@ class FlutterPlugin implements Plugin<Project> {
localEngineSrcPath this.localEngineSrcPath localEngineSrcPath this.localEngineSrcPath
targetPath target targetPath target
previewDart2 previewDart2Value previewDart2 previewDart2Value
trackWidgetCreation trackWidgetCreationValue
preferSharedLibrary preferSharedLibraryValue preferSharedLibrary preferSharedLibraryValue
targetPlatform targetPlatformValue targetPlatform targetPlatformValue
sourceDir project.file(project.flutter.source) sourceDir project.file(project.flutter.source)
...@@ -314,6 +318,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -314,6 +318,7 @@ class FlutterPlugin implements Plugin<Project> {
localEngineSrcPath this.localEngineSrcPath localEngineSrcPath this.localEngineSrcPath
targetPath target targetPath target
previewDart2 previewDart2Value previewDart2 previewDart2Value
trackWidgetCreation trackWidgetCreationValue
preferSharedLibrary preferSharedLibraryValue preferSharedLibrary preferSharedLibraryValue
targetPlatform targetPlatformValue targetPlatform targetPlatformValue
sourceDir project.file(project.flutter.source) sourceDir project.file(project.flutter.source)
...@@ -350,6 +355,8 @@ abstract class BaseFlutterTask extends DefaultTask { ...@@ -350,6 +355,8 @@ abstract class BaseFlutterTask extends DefaultTask {
@Optional @Input @Optional @Input
Boolean previewDart2 Boolean previewDart2
@Optional @Input @Optional @Input
Boolean trackWidgetCreation
@Optional @Input
Boolean preferSharedLibrary Boolean preferSharedLibrary
@Optional @Input @Optional @Input
String targetPlatform String targetPlatform
...@@ -392,6 +399,9 @@ abstract class BaseFlutterTask extends DefaultTask { ...@@ -392,6 +399,9 @@ abstract class BaseFlutterTask extends DefaultTask {
if (previewDart2) { if (previewDart2) {
args "--preview-dart-2" args "--preview-dart-2"
} }
if (trackWidgetCreation) {
args "--track-widget-creation"
}
if (extraFrontEndOptions != null) { if (extraFrontEndOptions != null) {
args "--extra-front-end-options", "${extraFrontEndOptions}" args "--extra-front-end-options", "${extraFrontEndOptions}"
} }
...@@ -421,7 +431,9 @@ abstract class BaseFlutterTask extends DefaultTask { ...@@ -421,7 +431,9 @@ abstract class BaseFlutterTask extends DefaultTask {
if (previewDart2) { if (previewDart2) {
args "--preview-dart-2" args "--preview-dart-2"
} }
if (trackWidgetCreation) {
args "--track-widget-creation"
}
args "--output-file", "${intermediateDir}/app.flx" args "--output-file", "${intermediateDir}/app.flx"
if (buildMode != "debug") { if (buildMode != "debug") {
args "--precompiled" args "--precompiled"
......
...@@ -300,6 +300,8 @@ Future<Null> _buildGradleProjectV2(String gradle, BuildInfo buildInfo, String ta ...@@ -300,6 +300,8 @@ Future<Null> _buildGradleProjectV2(String gradle, BuildInfo buildInfo, String ta
if (buildInfo.previewDart2) { if (buildInfo.previewDart2) {
command.add('-Ppreview-dart-2=true'); command.add('-Ppreview-dart-2=true');
command.add('-Pstrong=true'); command.add('-Pstrong=true');
if (buildInfo.trackWidgetCreation)
command.add('-Ptrack-widget-creation=true');
if (buildInfo.extraFrontEndOptions != null) if (buildInfo.extraFrontEndOptions != null)
command.add('-Pextra-front-end-options=${buildInfo.extraFrontEndOptions}'); command.add('-Pextra-front-end-options=${buildInfo.extraFrontEndOptions}');
if (buildInfo.extraGenSnapshotOptions != null) if (buildInfo.extraGenSnapshotOptions != null)
......
...@@ -12,6 +12,7 @@ import 'globals.dart'; ...@@ -12,6 +12,7 @@ import 'globals.dart';
class BuildInfo { class BuildInfo {
const BuildInfo(this.mode, this.flavor, const BuildInfo(this.mode, this.flavor,
{this.previewDart2, {this.previewDart2,
this.trackWidgetCreation,
this.extraFrontEndOptions, this.extraFrontEndOptions,
this.extraGenSnapshotOptions, this.extraGenSnapshotOptions,
this.preferSharedLibrary, this.preferSharedLibrary,
...@@ -29,6 +30,9 @@ class BuildInfo { ...@@ -29,6 +30,9 @@ class BuildInfo {
// Whether build should be done using Dart2 Frontend parser. // Whether build should be done using Dart2 Frontend parser.
final bool previewDart2; final bool previewDart2;
/// Whether the build should track widget creation locations.
final bool trackWidgetCreation;
/// Extra command-line options for front-end. /// Extra command-line options for front-end.
final String extraFrontEndOptions; final String extraFrontEndOptions;
...@@ -68,6 +72,7 @@ class BuildInfo { ...@@ -68,6 +72,7 @@ class BuildInfo {
BuildInfo withTargetPlatform(TargetPlatform targetPlatform) => BuildInfo withTargetPlatform(TargetPlatform targetPlatform) =>
new BuildInfo(mode, flavor, new BuildInfo(mode, flavor,
previewDart2: previewDart2, previewDart2: previewDart2,
trackWidgetCreation: trackWidgetCreation,
extraFrontEndOptions: extraFrontEndOptions, extraFrontEndOptions: extraFrontEndOptions,
extraGenSnapshotOptions: extraGenSnapshotOptions, extraGenSnapshotOptions: extraGenSnapshotOptions,
preferSharedLibrary: preferSharedLibrary, preferSharedLibrary: preferSharedLibrary,
......
...@@ -341,6 +341,7 @@ Future<String> _buildAotSnapshot( ...@@ -341,6 +341,7 @@ Future<String> _buildAotSnapshot(
extraFrontEndOptions: extraFrontEndOptions, extraFrontEndOptions: extraFrontEndOptions,
linkPlatformKernelIn : true, linkPlatformKernelIn : true,
aot : true, aot : true,
trackWidgetCreation: false,
); );
if (mainPath == null) { if (mainPath == null) {
printError('Compiler terminated unexpectedly.'); printError('Compiler terminated unexpectedly.');
......
...@@ -16,6 +16,7 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -16,6 +16,7 @@ class BuildApkCommand extends BuildSubCommand {
argParser argParser
..addFlag('preview-dart-2', negatable: false, hide: !verboseHelp) ..addFlag('preview-dart-2', negatable: false, hide: !verboseHelp)
..addFlag('track-widget-creation', negatable: false, hide: !verboseHelp)
..addFlag('prefer-shared-library', negatable: false, ..addFlag('prefer-shared-library', negatable: false,
help: 'Whether to prefer compiling to a *.so file (android only).') help: 'Whether to prefer compiling to a *.so file (android only).')
..addOption('target-platform', ..addOption('target-platform',
......
...@@ -21,6 +21,11 @@ class BuildFlxCommand extends BuildSubCommand { ...@@ -21,6 +21,11 @@ class BuildFlxCommand extends BuildSubCommand {
argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath); argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
argParser.addOption('depfile', defaultsTo: defaultDepfilePath); argParser.addOption('depfile', defaultsTo: defaultDepfilePath);
argParser.addFlag('preview-dart-2', negatable: false, hide: !verboseHelp); argParser.addFlag('preview-dart-2', negatable: false, hide: !verboseHelp);
argParser.addFlag(
'track-widget-creation',
hide: !verboseHelp,
help: 'Track widget creation locations. Requires Dart 2.0 functionality.',
);
argParser.addOption('working-dir', defaultsTo: getAssetBuildDirectory()); argParser.addOption('working-dir', defaultsTo: getAssetBuildDirectory());
argParser.addFlag('report-licensed-packages', help: 'Whether to report the names of all the packages that are included in the application\'s LICENSE file.', defaultsTo: false); argParser.addFlag('report-licensed-packages', help: 'Whether to report the names of all the packages that are included in the application\'s LICENSE file.', defaultsTo: false);
usesPubOption(); usesPubOption();
...@@ -51,7 +56,8 @@ class BuildFlxCommand extends BuildSubCommand { ...@@ -51,7 +56,8 @@ class BuildFlxCommand extends BuildSubCommand {
workingDirPath: argResults['working-dir'], workingDirPath: argResults['working-dir'],
previewDart2: argResults['preview-dart-2'], previewDart2: argResults['preview-dart-2'],
precompiledSnapshot: argResults['precompiled'], precompiledSnapshot: argResults['precompiled'],
reportLicensedPackages: argResults['report-licensed-packages'] reportLicensedPackages: argResults['report-licensed-packages'],
trackWidgetCreation: argResults['track-widget-creation'],
); );
} }
} }
...@@ -114,6 +114,9 @@ class RunCommand extends RunCommandBase { ...@@ -114,6 +114,9 @@ class RunCommand extends RunCommandBase {
hide: !verboseHelp, hide: !verboseHelp,
help: 'Turn on strong mode semantics.\n' help: 'Turn on strong mode semantics.\n'
'Valid only when --preview-dart-2 is also specified'); 'Valid only when --preview-dart-2 is also specified');
argParser.addFlag('track-widget-creation',
hide: !verboseHelp,
help: 'Track widget creation locations. Requires Dart 2.0 functionality.');
argParser.addOption('project-root', argParser.addOption('project-root',
hide: !verboseHelp, hide: !verboseHelp,
help: 'Specify the project root directory.'); help: 'Specify the project root directory.');
...@@ -297,7 +300,11 @@ class RunCommand extends RunCommandBase { ...@@ -297,7 +300,11 @@ class RunCommand extends RunCommandBase {
} }
final List<FlutterDevice> flutterDevices = devices.map((Device device) { final List<FlutterDevice> flutterDevices = devices.map((Device device) {
return new FlutterDevice(device, previewDart2: argResults['preview-dart-2']); return new FlutterDevice(
device,
previewDart2: argResults['preview-dart-2'],
trackWidgetCreation: argResults['track-widget-creation'],
);
}).toList(); }).toList();
ResidentRunner runner; ResidentRunner runner;
......
...@@ -60,6 +60,7 @@ Future<String> compile( ...@@ -60,6 +60,7 @@ Future<String> compile(
String mainPath, String mainPath,
bool linkPlatformKernelIn: false, bool linkPlatformKernelIn: false,
bool aot: false, bool aot: false,
bool trackWidgetCreation: false,
List<String> extraFrontEndOptions, List<String> extraFrontEndOptions,
String incrementalCompilerByteStorePath, String incrementalCompilerByteStorePath,
String packagesPath}) async { String packagesPath}) async {
...@@ -77,6 +78,8 @@ Future<String> compile( ...@@ -77,6 +78,8 @@ Future<String> compile(
sdkRoot, sdkRoot,
'--strong', '--strong',
]; ];
if (trackWidgetCreation)
command.add('--track-widget-creation');
if (!linkPlatformKernelIn) if (!linkPlatformKernelIn)
command.add('--no-link-platform'); command.add('--no-link-platform');
if (aot) { if (aot) {
...@@ -118,12 +121,15 @@ Future<String> compile( ...@@ -118,12 +121,15 @@ Future<String> compile(
/// The wrapper is intended to stay resident in memory as user changes, reloads, /// The wrapper is intended to stay resident in memory as user changes, reloads,
/// restarts the Flutter app. /// restarts the Flutter app.
class ResidentCompiler { class ResidentCompiler {
ResidentCompiler(this._sdkRoot) : assert(_sdkRoot != null) { ResidentCompiler(this._sdkRoot, {bool trackWidgetCreation: false})
: assert(_sdkRoot != null),
_trackWidgetCreation = trackWidgetCreation {
// This is a URI, not a file path, so the forward slash is correct even on Windows. // This is a URI, not a file path, so the forward slash is correct even on Windows.
if (!_sdkRoot.endsWith('/')) if (!_sdkRoot.endsWith('/'))
_sdkRoot = '$_sdkRoot/'; _sdkRoot = '$_sdkRoot/';
} }
final bool _trackWidgetCreation;
String _sdkRoot; String _sdkRoot;
Process _server; Process _server;
final _StdoutHandler stdoutHandler = new _StdoutHandler(); final _StdoutHandler stdoutHandler = new _StdoutHandler();
...@@ -162,6 +168,9 @@ class ResidentCompiler { ...@@ -162,6 +168,9 @@ class ResidentCompiler {
'--incremental', '--incremental',
'--strong' '--strong'
]; ];
if (_trackWidgetCreation) {
args.add('--track-widget-creation');
}
_server = await processManager.start(args); _server = await processManager.start(args);
_server.stdout _server.stdout
.transform(UTF8.decoder) .transform(UTF8.decoder)
......
...@@ -40,7 +40,8 @@ Future<Null> build({ ...@@ -40,7 +40,8 @@ Future<Null> build({
String packagesPath, String packagesPath,
bool previewDart2 : false, bool previewDart2 : false,
bool precompiledSnapshot: false, bool precompiledSnapshot: false,
bool reportLicensedPackages: false bool reportLicensedPackages: false,
bool trackWidgetCreation: false,
}) async { }) async {
outputPath ??= defaultFlxOutputPath; outputPath ??= defaultFlxOutputPath;
snapshotPath ??= defaultSnapshotPath; snapshotPath ??= defaultSnapshotPath;
...@@ -73,6 +74,7 @@ Future<Null> build({ ...@@ -73,6 +74,7 @@ Future<Null> build({
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
incrementalCompilerByteStorePath: fs.path.absolute(getIncrementalCompilerByteStoreDirectory()), incrementalCompilerByteStorePath: fs.path.absolute(getIncrementalCompilerByteStoreDirectory()),
mainPath: fs.file(mainPath).absolute.path, mainPath: fs.file(mainPath).absolute.path,
trackWidgetCreation: trackWidgetCreation,
); );
if (kernelBinaryFilename == null) { if (kernelBinaryFilename == null) {
throwToolExit('Compiler terminated unexpectedly on $mainPath'); throwToolExit('Compiler terminated unexpectedly on $mainPath');
......
...@@ -411,11 +411,15 @@ class IOSSimulator extends Device { ...@@ -411,11 +411,15 @@ class IOSSimulator extends Device {
await SimControl.instance.install(id, fs.path.absolute(bundle.path)); await SimControl.instance.install(id, fs.path.absolute(bundle.path));
} }
Future<Null> _sideloadUpdatedAssetsForInstalledApplicationBundle(ApplicationPackage app, BuildInfo buildInfo) => Future<Null> _sideloadUpdatedAssetsForInstalledApplicationBundle(ApplicationPackage app, BuildInfo buildInfo) {
// When running in previewDart2 mode, we still need to run compiler to // When running in previewDart2 mode, we still need to run compiler to
// produce kernel file for the application. // produce kernel file for the application.
flx.build(precompiledSnapshot: !buildInfo.previewDart2, return flx.build(
previewDart2: buildInfo.previewDart2); precompiledSnapshot: !buildInfo.previewDart2,
previewDart2: buildInfo.previewDart2,
trackWidgetCreation: buildInfo.trackWidgetCreation,
);
}
@override @override
Future<bool> stopApp(ApplicationPackage app) async { Future<bool> stopApp(ApplicationPackage app) async {
......
...@@ -38,9 +38,16 @@ class FlutterDevice { ...@@ -38,9 +38,16 @@ class FlutterDevice {
StreamSubscription<String> _loggingSubscription; StreamSubscription<String> _loggingSubscription;
FlutterDevice(this.device, { bool previewDart2 : false }) { FlutterDevice(this.device, {
if (previewDart2) bool previewDart2: false,
generator = new ResidentCompiler(artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath)); bool trackWidgetCreation: false,
}) {
if (previewDart2) {
generator = new ResidentCompiler(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
trackWidgetCreation: trackWidgetCreation,
);
}
} }
String viewFilter; String viewFilter;
......
...@@ -170,11 +170,20 @@ abstract class FlutterCommand extends Command<Null> { ...@@ -170,11 +170,20 @@ abstract class FlutterCommand extends Command<Null> {
targetPlatform = getTargetPlatformForName(argResults['target-platform']); targetPlatform = getTargetPlatformForName(argResults['target-platform']);
} }
final bool trackWidgetCreation = argParser.options.containsKey('track-widget-creation')
? argResults['track-widget-creation']
: false;
if (trackWidgetCreation == true && previewDart2 == false) {
throw new UsageException(
'--track-widget-creation is valid only when --preview-dart-2 is specified.', null);
}
return new BuildInfo(getBuildMode(), return new BuildInfo(getBuildMode(),
argParser.options.containsKey('flavor') argParser.options.containsKey('flavor')
? argResults['flavor'] ? argResults['flavor']
: null, : null,
previewDart2: previewDart2, previewDart2: previewDart2,
trackWidgetCreation: trackWidgetCreation,
extraFrontEndOptions: argParser.options.containsKey(FlutterOptions.kExtraFrontEndOptions) extraFrontEndOptions: argParser.options.containsKey(FlutterOptions.kExtraFrontEndOptions)
? argResults[FlutterOptions.kExtraFrontEndOptions] ? argResults[FlutterOptions.kExtraFrontEndOptions]
: null, : null,
......
...@@ -46,6 +46,10 @@ void main() { ...@@ -46,6 +46,10 @@ void main() {
TestRunner testRunner; TestRunner testRunner;
setUp(() { setUp(() {
// TODO(jacobr): make these tests run with `previewDart2: true` and
// `trackWidgetCreation: true` as well as the default flags.
// Currently the TestRunner is not properly configured to be able to run
// with `previewDart2: true` due to missing resources.
testRunner = new TestRunner( testRunner = new TestRunner(
<FlutterDevice>[new FlutterDevice(new MockDevice())] <FlutterDevice>[new FlutterDevice(new MockDevice())]
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment