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> {
if (project.hasProperty('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
if (project.hasProperty('extra-front-end-options')) {
extraFrontEndOptionsValue = project.property('extra-front-end-options')
......@@ -299,6 +302,7 @@ class FlutterPlugin implements Plugin<Project> {
localEngineSrcPath this.localEngineSrcPath
targetPath target
previewDart2 previewDart2Value
trackWidgetCreation trackWidgetCreationValue
preferSharedLibrary preferSharedLibraryValue
targetPlatform targetPlatformValue
sourceDir project.file(project.flutter.source)
......@@ -314,6 +318,7 @@ class FlutterPlugin implements Plugin<Project> {
localEngineSrcPath this.localEngineSrcPath
targetPath target
previewDart2 previewDart2Value
trackWidgetCreation trackWidgetCreationValue
preferSharedLibrary preferSharedLibraryValue
targetPlatform targetPlatformValue
sourceDir project.file(project.flutter.source)
......@@ -350,6 +355,8 @@ abstract class BaseFlutterTask extends DefaultTask {
@Optional @Input
Boolean previewDart2
@Optional @Input
Boolean trackWidgetCreation
@Optional @Input
Boolean preferSharedLibrary
@Optional @Input
String targetPlatform
......@@ -392,6 +399,9 @@ abstract class BaseFlutterTask extends DefaultTask {
if (previewDart2) {
args "--preview-dart-2"
}
if (trackWidgetCreation) {
args "--track-widget-creation"
}
if (extraFrontEndOptions != null) {
args "--extra-front-end-options", "${extraFrontEndOptions}"
}
......@@ -421,7 +431,9 @@ abstract class BaseFlutterTask extends DefaultTask {
if (previewDart2) {
args "--preview-dart-2"
}
if (trackWidgetCreation) {
args "--track-widget-creation"
}
args "--output-file", "${intermediateDir}/app.flx"
if (buildMode != "debug") {
args "--precompiled"
......
......@@ -300,6 +300,8 @@ Future<Null> _buildGradleProjectV2(String gradle, BuildInfo buildInfo, String ta
if (buildInfo.previewDart2) {
command.add('-Ppreview-dart-2=true');
command.add('-Pstrong=true');
if (buildInfo.trackWidgetCreation)
command.add('-Ptrack-widget-creation=true');
if (buildInfo.extraFrontEndOptions != null)
command.add('-Pextra-front-end-options=${buildInfo.extraFrontEndOptions}');
if (buildInfo.extraGenSnapshotOptions != null)
......
......@@ -12,6 +12,7 @@ import 'globals.dart';
class BuildInfo {
const BuildInfo(this.mode, this.flavor,
{this.previewDart2,
this.trackWidgetCreation,
this.extraFrontEndOptions,
this.extraGenSnapshotOptions,
this.preferSharedLibrary,
......@@ -29,6 +30,9 @@ class BuildInfo {
// Whether build should be done using Dart2 Frontend parser.
final bool previewDart2;
/// Whether the build should track widget creation locations.
final bool trackWidgetCreation;
/// Extra command-line options for front-end.
final String extraFrontEndOptions;
......@@ -68,6 +72,7 @@ class BuildInfo {
BuildInfo withTargetPlatform(TargetPlatform targetPlatform) =>
new BuildInfo(mode, flavor,
previewDart2: previewDart2,
trackWidgetCreation: trackWidgetCreation,
extraFrontEndOptions: extraFrontEndOptions,
extraGenSnapshotOptions: extraGenSnapshotOptions,
preferSharedLibrary: preferSharedLibrary,
......
......@@ -341,6 +341,7 @@ Future<String> _buildAotSnapshot(
extraFrontEndOptions: extraFrontEndOptions,
linkPlatformKernelIn : true,
aot : true,
trackWidgetCreation: false,
);
if (mainPath == null) {
printError('Compiler terminated unexpectedly.');
......
......@@ -16,6 +16,7 @@ class BuildApkCommand extends BuildSubCommand {
argParser
..addFlag('preview-dart-2', negatable: false, hide: !verboseHelp)
..addFlag('track-widget-creation', negatable: false, hide: !verboseHelp)
..addFlag('prefer-shared-library', negatable: false,
help: 'Whether to prefer compiling to a *.so file (android only).')
..addOption('target-platform',
......
......@@ -21,6 +21,11 @@ class BuildFlxCommand extends BuildSubCommand {
argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
argParser.addOption('depfile', defaultsTo: defaultDepfilePath);
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.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();
......@@ -51,7 +56,8 @@ class BuildFlxCommand extends BuildSubCommand {
workingDirPath: argResults['working-dir'],
previewDart2: argResults['preview-dart-2'],
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 {
hide: !verboseHelp,
help: 'Turn on strong mode semantics.\n'
'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',
hide: !verboseHelp,
help: 'Specify the project root directory.');
......@@ -297,7 +300,11 @@ class RunCommand extends RunCommandBase {
}
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();
ResidentRunner runner;
......
......@@ -60,6 +60,7 @@ Future<String> compile(
String mainPath,
bool linkPlatformKernelIn: false,
bool aot: false,
bool trackWidgetCreation: false,
List<String> extraFrontEndOptions,
String incrementalCompilerByteStorePath,
String packagesPath}) async {
......@@ -77,6 +78,8 @@ Future<String> compile(
sdkRoot,
'--strong',
];
if (trackWidgetCreation)
command.add('--track-widget-creation');
if (!linkPlatformKernelIn)
command.add('--no-link-platform');
if (aot) {
......@@ -118,12 +121,15 @@ Future<String> compile(
/// The wrapper is intended to stay resident in memory as user changes, reloads,
/// restarts the Flutter app.
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.
if (!_sdkRoot.endsWith('/'))
_sdkRoot = '$_sdkRoot/';
}
final bool _trackWidgetCreation;
String _sdkRoot;
Process _server;
final _StdoutHandler stdoutHandler = new _StdoutHandler();
......@@ -162,6 +168,9 @@ class ResidentCompiler {
'--incremental',
'--strong'
];
if (_trackWidgetCreation) {
args.add('--track-widget-creation');
}
_server = await processManager.start(args);
_server.stdout
.transform(UTF8.decoder)
......
......@@ -40,7 +40,8 @@ Future<Null> build({
String packagesPath,
bool previewDart2 : false,
bool precompiledSnapshot: false,
bool reportLicensedPackages: false
bool reportLicensedPackages: false,
bool trackWidgetCreation: false,
}) async {
outputPath ??= defaultFlxOutputPath;
snapshotPath ??= defaultSnapshotPath;
......@@ -73,6 +74,7 @@ Future<Null> build({
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
incrementalCompilerByteStorePath: fs.path.absolute(getIncrementalCompilerByteStoreDirectory()),
mainPath: fs.file(mainPath).absolute.path,
trackWidgetCreation: trackWidgetCreation,
);
if (kernelBinaryFilename == null) {
throwToolExit('Compiler terminated unexpectedly on $mainPath');
......
......@@ -411,11 +411,15 @@ class IOSSimulator extends Device {
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
// produce kernel file for the application.
flx.build(precompiledSnapshot: !buildInfo.previewDart2,
previewDart2: buildInfo.previewDart2);
return flx.build(
precompiledSnapshot: !buildInfo.previewDart2,
previewDart2: buildInfo.previewDart2,
trackWidgetCreation: buildInfo.trackWidgetCreation,
);
}
@override
Future<bool> stopApp(ApplicationPackage app) async {
......
......@@ -38,9 +38,16 @@ class FlutterDevice {
StreamSubscription<String> _loggingSubscription;
FlutterDevice(this.device, { bool previewDart2 : false }) {
if (previewDart2)
generator = new ResidentCompiler(artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath));
FlutterDevice(this.device, {
bool previewDart2: false,
bool trackWidgetCreation: false,
}) {
if (previewDart2) {
generator = new ResidentCompiler(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
trackWidgetCreation: trackWidgetCreation,
);
}
}
String viewFilter;
......
......@@ -170,11 +170,20 @@ abstract class FlutterCommand extends Command<Null> {
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(),
argParser.options.containsKey('flavor')
? argResults['flavor']
: null,
previewDart2: previewDart2,
trackWidgetCreation: trackWidgetCreation,
extraFrontEndOptions: argParser.options.containsKey(FlutterOptions.kExtraFrontEndOptions)
? argResults[FlutterOptions.kExtraFrontEndOptions]
: null,
......
......@@ -46,6 +46,10 @@ void main() {
TestRunner testRunner;
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(
<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