Pass build mode-specific bytecode generation options to frontend_server. (#42471)
Fixes various Flutter framework test failures when bytecode is enabled.
This commit is contained in:
@@ -308,9 +308,8 @@ class AOTSnapshotter {
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
linkPlatformKernelIn: true,
|
||||
aot: true,
|
||||
enableAsserts: buildMode == BuildMode.debug,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
targetProductVm: buildMode == BuildMode.release,
|
||||
));
|
||||
|
||||
// Write path to frontend_server, since things need to be re-generated when that changes.
|
||||
|
||||
@@ -139,7 +139,6 @@ class BuildRunner extends CodeGenerator {
|
||||
FlutterProject flutterProject, {
|
||||
String mainPath,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool targetProductVm = false,
|
||||
bool trackWidgetCreation = false,
|
||||
List<String> extraFrontEndOptions = const <String> [],
|
||||
}) async {
|
||||
|
||||
@@ -212,10 +212,9 @@ class KernelSnapshot extends Target {
|
||||
final CompilerOutput output = await compiler.compile(
|
||||
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
|
||||
aot: buildMode != BuildMode.debug,
|
||||
enableAsserts: buildMode == BuildMode.debug,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: buildMode == BuildMode.debug,
|
||||
targetModel: TargetModel.flutter,
|
||||
targetProductVm: buildMode == BuildMode.release,
|
||||
outputFilePath: environment.buildDir.childFile('app.dill').path,
|
||||
packagesPath: packagesPath,
|
||||
linkPlatformKernelIn: buildMode == BuildMode.release,
|
||||
|
||||
@@ -106,7 +106,7 @@ class BundleBuilder {
|
||||
mainPath: fs.file(mainPath).absolute.path,
|
||||
outputFilePath: applicationKernelFilePath,
|
||||
depFilePath: depfilePath,
|
||||
enableAsserts: buildMode == BuildMode.debug,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'artifacts.dart';
|
||||
import 'base/context.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'build_info.dart';
|
||||
import 'compile.dart';
|
||||
import 'dart/package_map.dart';
|
||||
import 'globals.dart';
|
||||
@@ -95,11 +96,10 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
||||
String outputFilePath,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool aot = false,
|
||||
bool enableAsserts = false,
|
||||
@required BuildMode buildMode,
|
||||
bool causalAsyncStacks = true,
|
||||
bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
bool targetProductVm = false,
|
||||
// These arguments are currently unused.
|
||||
String sdkRoot,
|
||||
String packagesPath,
|
||||
@@ -133,11 +133,10 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
||||
outputFilePath: outputFilePath,
|
||||
linkPlatformKernelIn: linkPlatformKernelIn,
|
||||
aot: aot,
|
||||
enableAsserts: enableAsserts,
|
||||
buildMode: buildMode,
|
||||
causalAsyncStacks: causalAsyncStacks,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
targetProductVm: targetProductVm,
|
||||
sdkRoot: sdkRoot,
|
||||
packagesPath: PackageMap.globalGeneratedPackagesPath,
|
||||
fileSystemRoots: <String>[
|
||||
@@ -165,7 +164,7 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
||||
/// codegen mode.
|
||||
static Future<ResidentCompiler> create({
|
||||
@required FlutterProject flutterProject,
|
||||
bool enableAsserts = false,
|
||||
@required BuildMode buildMode,
|
||||
bool trackWidgetCreation = false,
|
||||
CompilerMessageConsumer compilerMessageConsumer = printError,
|
||||
bool unsafePackageSerialization = false,
|
||||
@@ -176,7 +175,7 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
||||
codeGenerator.updatePackages(flutterProject);
|
||||
final ResidentCompiler residentCompiler = ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
enableAsserts: enableAsserts,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
packagesPath: PackageMap.globalGeneratedPackagesPath,
|
||||
fileSystemRoots: <String>[
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../asset.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../build_info.dart';
|
||||
import '../bundle.dart';
|
||||
import '../cache.dart';
|
||||
import '../codegen.dart';
|
||||
@@ -234,7 +235,7 @@ class TestCommand extends FastFlutterCommand {
|
||||
disableServiceAuthCodes: disableServiceAuthCodes,
|
||||
ipv6: argResults['ipv6'],
|
||||
machine: machine,
|
||||
enableAsserts: true,
|
||||
buildMode: BuildMode.debug,
|
||||
trackWidgetCreation: argResults['track-widget-creation'],
|
||||
updateGoldens: argResults['update-goldens'],
|
||||
concurrency: jobs,
|
||||
|
||||
@@ -15,6 +15,7 @@ import 'base/io.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/process_manager.dart';
|
||||
import 'base/terminal.dart';
|
||||
import 'build_info.dart';
|
||||
import 'codegen.dart';
|
||||
import 'convert.dart';
|
||||
import 'dart/package_map.dart';
|
||||
@@ -238,6 +239,31 @@ class PackageUriMapper {
|
||||
}
|
||||
}
|
||||
|
||||
List<String> _buildModeOptions(BuildMode mode) {
|
||||
switch (mode) {
|
||||
case BuildMode.debug:
|
||||
return <String>[
|
||||
'-Ddart.vm.profile=false',
|
||||
'-Ddart.vm.product=false',
|
||||
'--bytecode-options=source-positions,local-var-info,debugger-stops,instance-field-initializers,keep-unreachable-code,avoid-closure-call-instructions',
|
||||
'--enable-asserts',
|
||||
];
|
||||
case BuildMode.profile:
|
||||
return <String>[
|
||||
'-Ddart.vm.profile=true',
|
||||
'-Ddart.vm.product=false',
|
||||
'--bytecode-options=source-positions',
|
||||
];
|
||||
case BuildMode.release:
|
||||
return <String>[
|
||||
'-Ddart.vm.profile=false',
|
||||
'-Ddart.vm.product=true',
|
||||
'--bytecode-options=source-positions',
|
||||
];
|
||||
}
|
||||
throw Exception('Unknown BuildMode: $mode');
|
||||
}
|
||||
|
||||
class KernelCompiler {
|
||||
const KernelCompiler();
|
||||
|
||||
@@ -247,16 +273,15 @@ class KernelCompiler {
|
||||
String outputFilePath,
|
||||
String depFilePath,
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
@required BuildMode buildMode,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool aot = false,
|
||||
bool enableAsserts = false,
|
||||
bool causalAsyncStacks = true,
|
||||
@required bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
String packagesPath,
|
||||
List<String> fileSystemRoots,
|
||||
String fileSystemScheme,
|
||||
bool targetProductVm = false,
|
||||
String initializeFromDill,
|
||||
String platformDill,
|
||||
}) async {
|
||||
@@ -288,19 +313,13 @@ class KernelCompiler {
|
||||
'--strong',
|
||||
'--target=$targetModel',
|
||||
'-Ddart.developer.causal_async_stacks=$causalAsyncStacks',
|
||||
if (enableAsserts) '--enable-asserts',
|
||||
..._buildModeOptions(buildMode),
|
||||
if (trackWidgetCreation) '--track-widget-creation',
|
||||
if (!linkPlatformKernelIn) '--no-link-platform',
|
||||
if (aot) ...<String>[
|
||||
'--aot',
|
||||
'--tfa',
|
||||
],
|
||||
// If we're not targeting product (release) mode and we're still aot, then
|
||||
// target profile mode.
|
||||
if (targetProductVm)
|
||||
'-Ddart.vm.product=true'
|
||||
else if (aot)
|
||||
'-Ddart.vm.profile=true',
|
||||
if (packagesPath != null) ...<String>[
|
||||
'--packages',
|
||||
packagesPath,
|
||||
@@ -429,7 +448,7 @@ class _RejectRequest extends _CompilationRequest {
|
||||
class ResidentCompiler {
|
||||
ResidentCompiler(
|
||||
this._sdkRoot, {
|
||||
bool enableAsserts = false,
|
||||
@required BuildMode buildMode,
|
||||
bool causalAsyncStacks = true,
|
||||
bool trackWidgetCreation = false,
|
||||
String packagesPath,
|
||||
@@ -441,7 +460,7 @@ class ResidentCompiler {
|
||||
bool unsafePackageSerialization,
|
||||
List<String> experimentalFlags,
|
||||
}) : assert(_sdkRoot != null),
|
||||
_enableAsserts = enableAsserts,
|
||||
_buildMode = buildMode,
|
||||
_causalAsyncStacks = causalAsyncStacks,
|
||||
_trackWidgetCreation = trackWidgetCreation,
|
||||
_packagesPath = packagesPath,
|
||||
@@ -459,7 +478,7 @@ class ResidentCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
final bool _enableAsserts;
|
||||
final BuildMode _buildMode;
|
||||
final bool _causalAsyncStacks;
|
||||
final bool _trackWidgetCreation;
|
||||
final String _packagesPath;
|
||||
@@ -586,7 +605,7 @@ class ResidentCompiler {
|
||||
'--packages',
|
||||
_packagesPath,
|
||||
],
|
||||
if (_enableAsserts) '--enable-asserts',
|
||||
..._buildModeOptions(_buildMode),
|
||||
if (_trackWidgetCreation) '--track-widget-creation',
|
||||
if (_fileSystemRoots != null)
|
||||
for (String root in _fileSystemRoots) ...<String>[
|
||||
|
||||
@@ -453,6 +453,7 @@ class IOSSimulator extends Device {
|
||||
return BundleBuilder().build(
|
||||
mainPath: mainPath,
|
||||
precompiledSnapshot: false,
|
||||
buildMode: buildInfo.mode,
|
||||
trackWidgetCreation: buildInfo.trackWidgetCreation,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class FlutterDevice {
|
||||
}) : assert(trackWidgetCreation != null),
|
||||
generator = generator ?? ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
|
||||
enableAsserts: buildMode == BuildMode.debug,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
fileSystemScheme: fileSystemScheme,
|
||||
@@ -67,11 +67,13 @@ class FlutterDevice {
|
||||
ResidentCompiler generator;
|
||||
if (flutterProject.hasBuilders) {
|
||||
generator = await CodeGeneratingResidentCompiler.create(
|
||||
buildMode: buildMode,
|
||||
flutterProject: flutterProject,
|
||||
);
|
||||
} else {
|
||||
generator = ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
fileSystemScheme: fileSystemScheme,
|
||||
|
||||
@@ -21,6 +21,7 @@ import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../build_info.dart';
|
||||
import '../compile.dart';
|
||||
import '../convert.dart';
|
||||
import '../dart/package_map.dart';
|
||||
@@ -86,7 +87,7 @@ FlutterPlatform installHook({
|
||||
int port = 0,
|
||||
String precompiledDillPath,
|
||||
Map<String, String> precompiledDillFiles,
|
||||
bool enableAsserts = false,
|
||||
@required BuildMode buildMode,
|
||||
bool trackWidgetCreation = false,
|
||||
bool updateGoldens = false,
|
||||
bool buildTestAssets = false,
|
||||
@@ -120,7 +121,7 @@ FlutterPlatform installHook({
|
||||
port: port,
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
precompiledDillFiles: precompiledDillFiles,
|
||||
enableAsserts: enableAsserts,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
buildTestAssets: buildTestAssets,
|
||||
@@ -260,7 +261,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
this.port,
|
||||
this.precompiledDillPath,
|
||||
this.precompiledDillFiles,
|
||||
this.enableAsserts,
|
||||
@required this.buildMode,
|
||||
this.trackWidgetCreation,
|
||||
this.updateGoldens,
|
||||
this.buildTestAssets,
|
||||
@@ -280,7 +281,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
final int port;
|
||||
final String precompiledDillPath;
|
||||
final Map<String, String> precompiledDillFiles;
|
||||
final bool enableAsserts;
|
||||
final BuildMode buildMode;
|
||||
final bool trackWidgetCreation;
|
||||
final bool updateGoldens;
|
||||
final bool buildTestAssets;
|
||||
@@ -455,7 +456,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
|
||||
if (precompiledDillPath == null && precompiledDillFiles == null) {
|
||||
// Lazily instantiate compiler so it is built only if it is actually used.
|
||||
compiler ??= TestCompiler(enableAsserts, trackWidgetCreation, flutterProject);
|
||||
compiler ??= TestCompiler(buildMode, trackWidgetCreation, flutterProject);
|
||||
mainDart = await compiler.compile(mainDart);
|
||||
|
||||
if (mainDart == null) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../build_info.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
@@ -36,7 +37,7 @@ Future<int> runTests(
|
||||
bool machine = false,
|
||||
String precompiledDillPath,
|
||||
Map<String, String> precompiledDillFiles,
|
||||
bool enableAsserts = false,
|
||||
@required BuildMode buildMode,
|
||||
bool trackWidgetCreation = false,
|
||||
bool updateGoldens = false,
|
||||
TestWatcher watcher,
|
||||
@@ -114,7 +115,7 @@ Future<int> runTests(
|
||||
serverType: serverType,
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
precompiledDillFiles: precompiledDillFiles,
|
||||
enableAsserts: enableAsserts,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
buildTestAssets: buildTestAssets,
|
||||
|
||||
@@ -37,7 +37,7 @@ class TestCompiler {
|
||||
///
|
||||
/// [flutterProject] is the project for which we are running tests.
|
||||
TestCompiler(
|
||||
this.enableAsserts,
|
||||
this.buildMode,
|
||||
this.trackWidgetCreation,
|
||||
this.flutterProject,
|
||||
) : testFilePath = getKernelPathForTransformerOptions(
|
||||
@@ -60,7 +60,7 @@ class TestCompiler {
|
||||
final StreamController<_CompilationRequest> compilerController = StreamController<_CompilationRequest>();
|
||||
final List<_CompilationRequest> compilationQueue = <_CompilationRequest>[];
|
||||
final FlutterProject flutterProject;
|
||||
final bool enableAsserts;
|
||||
final BuildMode buildMode;
|
||||
final bool trackWidgetCreation;
|
||||
final String testFilePath;
|
||||
|
||||
@@ -96,7 +96,7 @@ class TestCompiler {
|
||||
if (flutterProject.hasBuilders) {
|
||||
return CodeGeneratingResidentCompiler.create(
|
||||
flutterProject: flutterProject,
|
||||
enableAsserts: enableAsserts,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
compilerMessageConsumer: _reportCompilerMessage,
|
||||
initializeFromDill: testFilePath,
|
||||
@@ -108,7 +108,7 @@ class TestCompiler {
|
||||
return ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
packagesPath: PackageMap.globalPackagesPath,
|
||||
enableAsserts: enableAsserts,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
compilerMessageConsumer: _reportCompilerMessage,
|
||||
initializeFromDill: testFilePath,
|
||||
|
||||
@@ -149,6 +149,7 @@ class FlutterTesterDevice extends Device {
|
||||
assetDirPath: assetDirPath,
|
||||
applicationKernelFilePath: applicationKernelFilePath,
|
||||
precompiledSnapshot: false,
|
||||
buildMode: buildInfo.mode,
|
||||
trackWidgetCreation: buildInfo.trackWidgetCreation,
|
||||
);
|
||||
command.add('--flutter-assets-dir=$assetDirPath');
|
||||
|
||||
Reference in New Issue
Block a user