Plumb --enable-asserts through to frontend_server invocation in debug mode. (#41832)
Bytecode generation will otherwise omit assert code, causing --enable-asserts to have no effect in the VM.
This commit is contained in:
@@ -308,6 +308,7 @@ class AOTSnapshotter {
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
linkPlatformKernelIn: true,
|
||||
aot: true,
|
||||
enableAsserts: buildMode == BuildMode.debug,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
targetProductVm: buildMode == BuildMode.release,
|
||||
));
|
||||
|
||||
@@ -212,6 +212,7 @@ 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,
|
||||
trackWidgetCreation: buildMode == BuildMode.debug,
|
||||
targetModel: TargetModel.flutter,
|
||||
targetProductVm: buildMode == BuildMode.release,
|
||||
|
||||
@@ -106,6 +106,7 @@ class BundleBuilder {
|
||||
mainPath: fs.file(mainPath).absolute.path,
|
||||
outputFilePath: applicationKernelFilePath,
|
||||
depFilePath: depfilePath,
|
||||
enableAsserts: buildMode == BuildMode.debug,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
|
||||
@@ -95,6 +95,7 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
||||
String outputFilePath,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool aot = false,
|
||||
bool enableAsserts = false,
|
||||
bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
bool targetProductVm = false,
|
||||
@@ -131,6 +132,7 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
||||
outputFilePath: outputFilePath,
|
||||
linkPlatformKernelIn: linkPlatformKernelIn,
|
||||
aot: aot,
|
||||
enableAsserts: enableAsserts,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
targetProductVm: targetProductVm,
|
||||
@@ -161,6 +163,7 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
||||
/// codegen mode.
|
||||
static Future<ResidentCompiler> create({
|
||||
@required FlutterProject flutterProject,
|
||||
bool enableAsserts = false,
|
||||
bool trackWidgetCreation = false,
|
||||
CompilerMessageConsumer compilerMessageConsumer = printError,
|
||||
bool unsafePackageSerialization = false,
|
||||
@@ -171,6 +174,7 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
||||
codeGenerator.updatePackages(flutterProject);
|
||||
final ResidentCompiler residentCompiler = ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
enableAsserts: enableAsserts,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
packagesPath: PackageMap.globalGeneratedPackagesPath,
|
||||
fileSystemRoots: <String>[
|
||||
|
||||
@@ -234,6 +234,7 @@ class TestCommand extends FastFlutterCommand {
|
||||
disableServiceAuthCodes: disableServiceAuthCodes,
|
||||
ipv6: argResults['ipv6'],
|
||||
machine: machine,
|
||||
enableAsserts: true,
|
||||
trackWidgetCreation: argResults['track-widget-creation'],
|
||||
updateGoldens: argResults['update-goldens'],
|
||||
concurrency: jobs,
|
||||
|
||||
@@ -249,6 +249,7 @@ class KernelCompiler {
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool aot = false,
|
||||
bool enableAsserts = false,
|
||||
@required bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
String packagesPath,
|
||||
@@ -285,6 +286,7 @@ class KernelCompiler {
|
||||
sdkRoot,
|
||||
'--strong',
|
||||
'--target=$targetModel',
|
||||
if (enableAsserts) '--enable-asserts',
|
||||
if (trackWidgetCreation) '--track-widget-creation',
|
||||
if (!linkPlatformKernelIn) '--no-link-platform',
|
||||
if (aot) ...<String>[
|
||||
@@ -425,6 +427,7 @@ class _RejectRequest extends _CompilationRequest {
|
||||
class ResidentCompiler {
|
||||
ResidentCompiler(
|
||||
this._sdkRoot, {
|
||||
bool enableAsserts = false,
|
||||
bool trackWidgetCreation = false,
|
||||
String packagesPath,
|
||||
List<String> fileSystemRoots,
|
||||
@@ -435,6 +438,7 @@ class ResidentCompiler {
|
||||
bool unsafePackageSerialization,
|
||||
List<String> experimentalFlags,
|
||||
}) : assert(_sdkRoot != null),
|
||||
_enableAsserts = enableAsserts,
|
||||
_trackWidgetCreation = trackWidgetCreation,
|
||||
_packagesPath = packagesPath,
|
||||
_fileSystemRoots = fileSystemRoots,
|
||||
@@ -451,6 +455,7 @@ class ResidentCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
final bool _enableAsserts;
|
||||
final bool _trackWidgetCreation;
|
||||
final String _packagesPath;
|
||||
final TargetModel _targetModel;
|
||||
@@ -575,6 +580,7 @@ class ResidentCompiler {
|
||||
'--packages',
|
||||
_packagesPath,
|
||||
],
|
||||
if (_enableAsserts) '--enable-asserts',
|
||||
if (_trackWidgetCreation) '--track-widget-creation',
|
||||
if (_fileSystemRoots != null)
|
||||
for (String root in _fileSystemRoots) ...<String>[
|
||||
|
||||
@@ -42,6 +42,7 @@ class FlutterDevice {
|
||||
}) : assert(trackWidgetCreation != null),
|
||||
generator = generator ?? ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
|
||||
enableAsserts: buildMode == BuildMode.debug,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
fileSystemScheme: fileSystemScheme,
|
||||
|
||||
@@ -86,6 +86,7 @@ FlutterPlatform installHook({
|
||||
int port = 0,
|
||||
String precompiledDillPath,
|
||||
Map<String, String> precompiledDillFiles,
|
||||
bool enableAsserts = false,
|
||||
bool trackWidgetCreation = false,
|
||||
bool updateGoldens = false,
|
||||
bool buildTestAssets = false,
|
||||
@@ -119,6 +120,7 @@ FlutterPlatform installHook({
|
||||
port: port,
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
precompiledDillFiles: precompiledDillFiles,
|
||||
enableAsserts: enableAsserts,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
buildTestAssets: buildTestAssets,
|
||||
@@ -258,6 +260,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
this.port,
|
||||
this.precompiledDillPath,
|
||||
this.precompiledDillFiles,
|
||||
this.enableAsserts,
|
||||
this.trackWidgetCreation,
|
||||
this.updateGoldens,
|
||||
this.buildTestAssets,
|
||||
@@ -277,6 +280,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
final int port;
|
||||
final String precompiledDillPath;
|
||||
final Map<String, String> precompiledDillFiles;
|
||||
final bool enableAsserts;
|
||||
final bool trackWidgetCreation;
|
||||
final bool updateGoldens;
|
||||
final bool buildTestAssets;
|
||||
@@ -451,7 +455,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(trackWidgetCreation, flutterProject);
|
||||
compiler ??= TestCompiler(enableAsserts, trackWidgetCreation, flutterProject);
|
||||
mainDart = await compiler.compile(mainDart);
|
||||
|
||||
if (mainDart == null) {
|
||||
|
||||
@@ -36,6 +36,7 @@ Future<int> runTests(
|
||||
bool machine = false,
|
||||
String precompiledDillPath,
|
||||
Map<String, String> precompiledDillFiles,
|
||||
bool enableAsserts = false,
|
||||
bool trackWidgetCreation = false,
|
||||
bool updateGoldens = false,
|
||||
TestWatcher watcher,
|
||||
@@ -113,6 +114,7 @@ Future<int> runTests(
|
||||
serverType: serverType,
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
precompiledDillFiles: precompiledDillFiles,
|
||||
enableAsserts: enableAsserts,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
buildTestAssets: buildTestAssets,
|
||||
|
||||
@@ -37,6 +37,7 @@ class TestCompiler {
|
||||
///
|
||||
/// [flutterProject] is the project for which we are running tests.
|
||||
TestCompiler(
|
||||
this.enableAsserts,
|
||||
this.trackWidgetCreation,
|
||||
this.flutterProject,
|
||||
) : testFilePath = getKernelPathForTransformerOptions(
|
||||
@@ -59,6 +60,7 @@ class TestCompiler {
|
||||
final StreamController<_CompilationRequest> compilerController = StreamController<_CompilationRequest>();
|
||||
final List<_CompilationRequest> compilationQueue = <_CompilationRequest>[];
|
||||
final FlutterProject flutterProject;
|
||||
final bool enableAsserts;
|
||||
final bool trackWidgetCreation;
|
||||
final String testFilePath;
|
||||
|
||||
@@ -94,6 +96,7 @@ class TestCompiler {
|
||||
if (flutterProject.hasBuilders) {
|
||||
return CodeGeneratingResidentCompiler.create(
|
||||
flutterProject: flutterProject,
|
||||
enableAsserts: enableAsserts,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
compilerMessageConsumer: _reportCompilerMessage,
|
||||
initializeFromDill: testFilePath,
|
||||
@@ -105,6 +108,7 @@ class TestCompiler {
|
||||
return ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
packagesPath: PackageMap.globalPackagesPath,
|
||||
enableAsserts: enableAsserts,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
compilerMessageConsumer: _reportCompilerMessage,
|
||||
initializeFromDill: testFilePath,
|
||||
|
||||
@@ -128,6 +128,7 @@ flutter_tools:lib/''');
|
||||
targetModel: anyNamed('targetModel'),
|
||||
linkPlatformKernelIn: anyNamed('linkPlatformKernelIn'),
|
||||
aot: anyNamed('aot'),
|
||||
enableAsserts: anyNamed('enableAsserts'),
|
||||
trackWidgetCreation: anyNamed('trackWidgetCreation'),
|
||||
extraFrontEndOptions: anyNamed('extraFrontEndOptions'),
|
||||
packagesPath: anyNamed('packagesPath'),
|
||||
@@ -152,6 +153,7 @@ flutter_tools:lib/''');
|
||||
when(mockKernelCompiler.compile(
|
||||
sdkRoot: anyNamed('sdkRoot'),
|
||||
aot: anyNamed('aot'),
|
||||
enableAsserts: anyNamed('enableAsserts'),
|
||||
trackWidgetCreation: false,
|
||||
targetModel: anyNamed('targetModel'),
|
||||
targetProductVm: anyNamed('targetProductVm'),
|
||||
@@ -176,6 +178,7 @@ flutter_tools:lib/''');
|
||||
when(mockKernelCompiler.compile(
|
||||
sdkRoot: anyNamed('sdkRoot'),
|
||||
aot: anyNamed('aot'),
|
||||
enableAsserts: anyNamed('enableAsserts'),
|
||||
trackWidgetCreation: true,
|
||||
targetModel: anyNamed('targetModel'),
|
||||
targetProductVm: anyNamed('targetProductVm'),
|
||||
@@ -388,6 +391,7 @@ class FakeKernelCompiler implements KernelCompiler {
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool aot = false,
|
||||
bool enableAsserts = false,
|
||||
bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
String packagesPath,
|
||||
|
||||
@@ -52,6 +52,7 @@ void main() {
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final CompilerOutput output = await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
enableAsserts: true,
|
||||
trackWidgetCreation: false,
|
||||
);
|
||||
|
||||
@@ -75,6 +76,7 @@ void main() {
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final CompilerOutput output = await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
enableAsserts: true,
|
||||
trackWidgetCreation: false,
|
||||
);
|
||||
|
||||
@@ -101,6 +103,7 @@ void main() {
|
||||
final CompilerOutput output = await kernelCompiler.compile(
|
||||
sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
enableAsserts: true,
|
||||
trackWidgetCreation: false,
|
||||
);
|
||||
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
||||
|
||||
@@ -109,6 +109,7 @@ void main() {
|
||||
port: 100,
|
||||
precompiledDillPath: 'def',
|
||||
precompiledDillFiles: expectedPrecompiledDillFiles,
|
||||
enableAsserts: true,
|
||||
trackWidgetCreation: true,
|
||||
updateGoldens: true,
|
||||
buildTestAssets: true,
|
||||
@@ -130,6 +131,7 @@ void main() {
|
||||
expect(flutterPlatform.explicitObservatoryPort, equals(200));
|
||||
expect(flutterPlatform.precompiledDillPath, equals('def'));
|
||||
expect(flutterPlatform.precompiledDillFiles, expectedPrecompiledDillFiles);
|
||||
expect(flutterPlatform.enableAsserts, equals(true));
|
||||
expect(flutterPlatform.trackWidgetCreation, equals(true));
|
||||
expect(flutterPlatform.updateGoldens, equals(true));
|
||||
expect(flutterPlatform.buildTestAssets, equals(true));
|
||||
|
||||
@@ -25,6 +25,7 @@ void main() {
|
||||
fs.file('test/foo.dart').createSync(recursive: true);
|
||||
residentCompiler = MockResidentCompiler();
|
||||
testCompiler = FakeTestCompiler(
|
||||
true,
|
||||
false,
|
||||
FlutterProject.current(),
|
||||
residentCompiler,
|
||||
@@ -75,10 +76,11 @@ void main() {
|
||||
/// Override the creation of the Resident Compiler to simplify testing.
|
||||
class FakeTestCompiler extends TestCompiler {
|
||||
FakeTestCompiler(
|
||||
bool enableAsserts,
|
||||
bool trackWidgetCreation,
|
||||
FlutterProject flutterProject,
|
||||
this.residentCompiler,
|
||||
) : super(trackWidgetCreation, flutterProject);
|
||||
) : super(enableAsserts, trackWidgetCreation, flutterProject);
|
||||
|
||||
final MockResidentCompiler residentCompiler;
|
||||
|
||||
|
||||
@@ -169,6 +169,7 @@ Hello!
|
||||
mainPath: anyNamed('mainPath'),
|
||||
outputFilePath: anyNamed('outputFilePath'),
|
||||
depFilePath: anyNamed('depFilePath'),
|
||||
enableAsserts: anyNamed('enableAsserts'),
|
||||
trackWidgetCreation: anyNamed('trackWidgetCreation'),
|
||||
extraFrontEndOptions: anyNamed('extraFrontEndOptions'),
|
||||
fileSystemRoots: anyNamed('fileSystemRoots'),
|
||||
|
||||
Reference in New Issue
Block a user