Unverified Commit e67f9a3f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

ensure we can disable --track-widget-creation in debug mode (#43016)

parent 5db53aee
...@@ -31,6 +31,9 @@ const String kTargetFile = 'TargetFile'; ...@@ -31,6 +31,9 @@ const String kTargetFile = 'TargetFile';
/// The define to control whether the AOT snapshot is built with bitcode. /// The define to control whether the AOT snapshot is built with bitcode.
const String kBitcodeFlag = 'EnableBitcode'; const String kBitcodeFlag = 'EnableBitcode';
/// Whether to enable or disable track widget creation.
const String kTrackWidgetCreation = 'TrackWidgetCreation';
/// The define to control what iOS architectures are built for. /// The define to control what iOS architectures are built for.
/// ///
/// This is expected to be a comma-separated list of architectures. If not /// This is expected to be a comma-separated list of architectures. If not
...@@ -208,12 +211,14 @@ class KernelSnapshot extends Target { ...@@ -208,12 +211,14 @@ class KernelSnapshot extends Target {
final String targetFile = environment.defines[kTargetFile] ?? fs.path.join('lib', 'main.dart'); final String targetFile = environment.defines[kTargetFile] ?? fs.path.join('lib', 'main.dart');
final String packagesPath = environment.projectDir.childFile('.packages').path; final String packagesPath = environment.projectDir.childFile('.packages').path;
final String targetFileAbsolute = fs.file(targetFile).absolute.path; final String targetFileAbsolute = fs.file(targetFile).absolute.path;
// everything besides 'false' is considered to be enabled.
final bool trackWidgetCreation = environment.defines[kTrackWidgetCreation] != 'false';
final CompilerOutput output = await compiler.compile( final CompilerOutput output = await compiler.compile(
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode), sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
aot: buildMode != BuildMode.debug, aot: buildMode != BuildMode.debug,
buildMode: buildMode, buildMode: buildMode,
trackWidgetCreation: buildMode == BuildMode.debug, trackWidgetCreation: trackWidgetCreation && buildMode == BuildMode.debug,
targetModel: TargetModel.flutter, targetModel: TargetModel.flutter,
outputFilePath: environment.buildDir.childFile('app.dill').path, outputFilePath: environment.buildDir.childFile('app.dill').path,
packagesPath: packagesPath, packagesPath: packagesPath,
......
...@@ -80,6 +80,7 @@ class BundleBuilder { ...@@ -80,6 +80,7 @@ class BundleBuilder {
outputDir: assetDirPath, outputDir: assetDirPath,
depfilePath: depfilePath, depfilePath: depfilePath,
precompiled: precompiledSnapshot, precompiled: precompiledSnapshot,
trackWidgetCreation: trackWidgetCreation,
); );
// Work around for flutter_tester placing kernel artifacts in odd places. // Work around for flutter_tester placing kernel artifacts in odd places.
if (applicationKernelFilePath != null) { if (applicationKernelFilePath != null) {
...@@ -103,6 +104,7 @@ Future<void> buildWithAssemble({ ...@@ -103,6 +104,7 @@ Future<void> buildWithAssemble({
@required String outputDir, @required String outputDir,
@required String depfilePath, @required String depfilePath,
@required bool precompiled, @required bool precompiled,
bool trackWidgetCreation,
}) async { }) async {
// If the precompiled flag was not passed, force us into debug mode. // If the precompiled flag was not passed, force us into debug mode.
buildMode = precompiled ? buildMode : BuildMode.debug; buildMode = precompiled ? buildMode : BuildMode.debug;
...@@ -114,6 +116,7 @@ Future<void> buildWithAssemble({ ...@@ -114,6 +116,7 @@ Future<void> buildWithAssemble({
kTargetFile: mainPath, kTargetFile: mainPath,
kBuildMode: getNameForBuildMode(buildMode), kBuildMode: getNameForBuildMode(buildMode),
kTargetPlatform: getNameForTargetPlatform(targetPlatform), kTargetPlatform: getNameForTargetPlatform(targetPlatform),
kTrackWidgetCreation: trackWidgetCreation?.toString(),
}, },
); );
final Target target = buildMode == BuildMode.debug final Target target = buildMode == BuildMode.debug
......
...@@ -6,6 +6,8 @@ import 'package:args/command_runner.dart'; ...@@ -6,6 +6,8 @@ import 'package:args/command_runner.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/dart.dart';
import 'package:flutter_tools/src/bundle.dart'; import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_bundle.dart'; import 'package:flutter_tools/src/commands/build_bundle.dart';
...@@ -202,6 +204,37 @@ void main() { ...@@ -202,6 +204,37 @@ void main() {
ProcessManager: () => FakeProcessManager(<FakeCommand>[]), ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true), FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
}); });
testUsingContext('passes track widget creation through', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
when(buildSystem.build(any, any)).thenAnswer((Invocation invocation) async {
final Environment environment = invocation.positionalArguments[1];
expect(environment.defines, <String, String>{
kTargetFile: fs.path.join('lib', 'main.dart'),
kBuildMode: 'debug',
kTargetPlatform: 'android-arm',
kTrackWidgetCreation: 'true',
});
return BuildResult(success: true);
});
await runner.run(<String>[
'bundle',
'--no-pub',
'--debug',
'--target-platform=android-arm',
'--track-widget-creation'
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
BuildSystem: () => MockBuildSystem(),
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
});
} }
class MockBundleBuilder extends Mock implements BundleBuilder {} class MockBundleBuilder extends Mock implements BundleBuilder {}
class MockBuildSystem extends Mock implements BuildSystem {}
...@@ -168,6 +168,30 @@ flutter_tools:lib/'''); ...@@ -168,6 +168,30 @@ flutter_tools:lib/''');
KernelCompilerFactory: () => MockKernelCompilerFactory(), KernelCompilerFactory: () => MockKernelCompilerFactory(),
})); }));
test('kernel_snapshot can disable track-widget-creation on debug builds', () => testbed.run(() async {
final MockKernelCompiler mockKernelCompiler = MockKernelCompiler();
when(kernelCompilerFactory.create(any)).thenAnswer((Invocation _) async {
return mockKernelCompiler;
});
when(mockKernelCompiler.compile(
sdkRoot: anyNamed('sdkRoot'),
aot: anyNamed('aot'),
buildMode: anyNamed('buildMode'),
trackWidgetCreation: false,
targetModel: anyNamed('targetModel'),
outputFilePath: anyNamed('outputFilePath'),
depFilePath: anyNamed('depFilePath'),
packagesPath: anyNamed('packagesPath'),
mainPath: anyNamed('mainPath'),
)).thenAnswer((Invocation _) async {
return const CompilerOutput('example', 0, <Uri>[]);
});
await const KernelSnapshot().build(androidEnvironment..defines[kTrackWidgetCreation] = 'false');
}, overrides: <Type, Generator>{
KernelCompilerFactory: () => MockKernelCompilerFactory(),
}));
test('kernel_snapshot does use track widget creation on debug builds', () => testbed.run(() async { test('kernel_snapshot does use track widget creation on debug builds', () => testbed.run(() async {
final MockKernelCompiler mockKernelCompiler = MockKernelCompiler(); final MockKernelCompiler mockKernelCompiler = MockKernelCompiler();
when(kernelCompilerFactory.create(any)).thenAnswer((Invocation _) async { when(kernelCompilerFactory.create(any)).thenAnswer((Invocation _) async {
......
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