diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 09d46d041c..256f3a42cd 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -178,7 +178,8 @@ class AOTSnapshotter { // is resolved. // The DWARF section confuses Xcode tooling, so this strips it. Ideally, // gen_snapshot would provide an argument to do this automatically. - if (platform == TargetPlatform.ios && bitcode) { + final bool stripSymbols = platform == TargetPlatform.ios && buildMode == BuildMode.release && bitcode; + if (stripSymbols) { final IOSink sink = fs.file('$assembly.stripped.S').openWrite(); for (String line in fs.file(assembly).readAsLinesSync()) { if (line.startsWith('.section __DWARF')) { @@ -201,12 +202,13 @@ class AOTSnapshotter { final RunResult result = await _buildFramework( appleArch: darwinArch, isIOS: platform == TargetPlatform.ios, - assemblyPath: bitcode ? '$assembly.stripped.S' : assembly, + assemblyPath: stripSymbols ? '$assembly.stripped.S' : assembly, outputPath: outputDir.path, bitcode: bitcode, ); - if (result.exitCode != 0) + if (result.exitCode != 0) { return result.exitCode; + } } return 0; } diff --git a/packages/flutter_tools/test/general.shard/base/build_test.dart b/packages/flutter_tools/test/general.shard/base/build_test.dart index be3556ccc8..d767d9a0a3 100644 --- a/packages/flutter_tools/test/general.shard/base/build_test.dart +++ b/packages/flutter_tools/test/general.shard/base/build_test.dart @@ -163,7 +163,7 @@ void main() { ), isNot(0)); }, overrides: contextOverrides); - testUsingContext('iOS debug AOT with bitcode uses right flags', () async { + testUsingContext('iOS profile AOT with bitcode uses right flags', () async { fs.file('main.dill').writeAsStringSync('binary magic'); final String outputPath = fs.path.join('build', 'foo'); @@ -204,6 +204,52 @@ void main() { verify(xcode.cc(argThat(contains('-fembed-bitcode')))).called(1); verify(xcode.clang(argThat(contains('-fembed-bitcode')))).called(1); + final File assemblyFile = fs.file(assembly); + expect(assemblyFile.existsSync(), true); + expect(assemblyFile.readAsStringSync().contains('.section __DWARF'), true); + }, overrides: contextOverrides); + + testUsingContext('iOS release AOT with bitcode uses right flags', () async { + fs.file('main.dill').writeAsStringSync('binary magic'); + + final String outputPath = fs.path.join('build', 'foo'); + fs.directory(outputPath).createSync(recursive: true); + + final String assembly = fs.path.join(outputPath, 'snapshot_assembly.S'); + genSnapshot.outputs = { + assembly: 'blah blah\n.section __DWARF\nblah blah\n', + }; + + final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), ['command name', 'arguments...']); + when(xcode.cc(any)).thenAnswer((_) => Future.value(successResult)); + when(xcode.clang(any)).thenAnswer((_) => Future.value(successResult)); + + final int genSnapshotExitCode = await snapshotter.build( + platform: TargetPlatform.ios, + buildMode: BuildMode.release, + mainPath: 'main.dill', + packagesPath: '.packages', + outputPath: outputPath, + darwinArch: DarwinArch.armv7, + bitcode: true, + ); + + expect(genSnapshotExitCode, 0); + expect(genSnapshot.callCount, 1); + expect(genSnapshot.snapshotType.platform, TargetPlatform.ios); + expect(genSnapshot.snapshotType.mode, BuildMode.release); + expect(genSnapshot.additionalArgs, [ + '--deterministic', + '--snapshot_kind=app-aot-assembly', + '--assembly=$assembly', + '--no-sim-use-hardfp', + '--no-use-integer-division', + 'main.dill', + ]); + + verify(xcode.cc(argThat(contains('-fembed-bitcode')))).called(1); + verify(xcode.clang(argThat(contains('-fembed-bitcode')))).called(1); + final File assemblyFile = fs.file(assembly); final File assemblyBitcodeFile = fs.file('$assembly.stripped.S'); expect(assemblyFile.existsSync(), true); @@ -253,9 +299,7 @@ void main() { verifyNever(xcode.clang(argThat(contains('-fembed-bitcode')))); final File assemblyFile = fs.file(assembly); - final File assemblyBitcodeFile = fs.file('$assembly.bitcode'); expect(assemblyFile.existsSync(), true); - expect(assemblyBitcodeFile.existsSync(), false); expect(assemblyFile.readAsStringSync().contains('.section __DWARF'), true); }, overrides: contextOverrides);