From 3082a2806eaf1f6e1aa6b446291e602af331d157 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 6 Jan 2021 12:12:23 -0800 Subject: [PATCH] build ios-framework simulator slices for profile/release (#73378) --- .../build_ios_framework_module_test.dart | 30 +++---- dev/devicelab/lib/framework/ios.dart | 4 - .../lib/src/commands/build_ios_framework.dart | 82 +++++++++---------- 3 files changed, 56 insertions(+), 60 deletions(-) diff --git a/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart b/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart index bdfa1b5be0..539f71fcae 100644 --- a/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart +++ b/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart @@ -191,7 +191,7 @@ Future _testBuildIosFramework(Directory projectDir, { bool isModule = fals section('Check debug build has no Dart AOT'); - final String aotSymbols = await dylibSymbols(debugAppFrameworkPath); + final String aotSymbols = await _dylibSymbols(debugAppFrameworkPath); if (aotSymbols.contains('architecture') || aotSymbols.contains('_kDartVmSnapshot')) { @@ -212,7 +212,7 @@ Future _testBuildIosFramework(Directory projectDir, { bool isModule = fals await _checkBitcode(appFrameworkPath, mode); - final String aotSymbols = await dylibSymbols(appFrameworkPath); + final String aotSymbols = await _dylibSymbols(appFrameworkPath); if (!aotSymbols.contains('_kDartVmSnapshot')) { throw TaskResult.failure('$mode App.framework missing Dart AOT'); @@ -228,7 +228,7 @@ Future _testBuildIosFramework(Directory projectDir, { bool isModule = fals 'vm_snapshot_data', )); - checkFileNotExists(path.join( + checkFileExists(path.join( outputPath, mode, 'App.xcframework', @@ -314,13 +314,8 @@ Future _testBuildIosFramework(Directory projectDir, { bool isModule = fals 'DeviceInfoPlugin.h', ); - if (mode == 'Debug') { - checkFileExists(simulatorFrameworkPath); - checkFileExists(simulatorFrameworkHeaderPath); - } else { - checkFileNotExists(simulatorFrameworkPath); - checkFileNotExists(simulatorFrameworkHeaderPath); - } + checkFileExists(simulatorFrameworkPath); + checkFileExists(simulatorFrameworkHeaderPath); } section('Check all modes have generated plugin registrant'); @@ -357,11 +352,7 @@ Future _testBuildIosFramework(Directory projectDir, { bool isModule = fals 'Headers', 'GeneratedPluginRegistrant.h', ); - if (mode == 'Debug') { - checkFileExists(simulatorHeaderPath); - } else { - checkFileNotExists(simulatorHeaderPath); - } + checkFileExists(simulatorHeaderPath); } // This builds all build modes' frameworks by default @@ -443,3 +434,12 @@ Future _checkBitcode(String frameworkPath, String mode) async { throw TaskResult.failure('$frameworkPath does not contain bitcode'); } } + +Future _dylibSymbols(String pathToDylib) { + return eval('nm', [ + '-g', + pathToDylib, + '-arch', + 'arm64', + ]); +} diff --git a/dev/devicelab/lib/framework/ios.dart b/dev/devicelab/lib/framework/ios.dart index da5b71777a..0a1759e233 100644 --- a/dev/devicelab/lib/framework/ios.dart +++ b/dev/devicelab/lib/framework/ios.dart @@ -10,10 +10,6 @@ import 'utils.dart'; typedef SimulatorFunction = Future Function(String deviceId); -Future dylibSymbols(String pathToDylib) { - return eval('nm', ['-g', pathToDylib]); -} - Future fileType(String pathToBinary) { return eval('file', [pathToBinary]); } diff --git a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart index 2d971b6a2f..675897a384 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart @@ -342,17 +342,9 @@ end ); final List environmentTypes = [ EnvironmentType.physical, + EnvironmentType.simulator, ]; final List frameworks = []; - Target target; - if (buildInfo.isDebug) { - environmentTypes.add(EnvironmentType.simulator); - target = const DebugIosApplicationBundle(); - } else if (buildInfo.isProfile) { - target = const ProfileIosApplicationBundle(); - } else { - target = const ReleaseIosApplicationBundle(); - } try { for (final EnvironmentType sdkType in environmentTypes) { @@ -392,6 +384,15 @@ end ? null : globals.flutterVersion.engineRevision, ); + Target target; + // Always build debug for simulator. + if (buildInfo.isDebug || sdkType == EnvironmentType.simulator) { + target = const DebugIosApplicationBundle(); + } else if (buildInfo.isProfile) { + target = const ProfileIosApplicationBundle(); + } else { + target = const ReleaseIosApplicationBundle(); + } final BuildResult result = await buildSystem.build(target, environment); if (!result.success) { for (final ExceptionMeasurement measurement @@ -453,42 +454,42 @@ end throwToolExit('Unable to build plugin frameworks: ${buildPluginsResult.stderr}'); } - if (mode == BuildMode.debug) { - pluginsBuildCommand = [ - ...globals.xcode.xcrunCommand(), - 'xcodebuild', - '-alltargets', - '-sdk', - 'iphonesimulator', - '-configuration', - xcodeBuildConfiguration, - 'SYMROOT=${simulatorBuildOutput.path}', - 'ENABLE_BITCODE=YES', // Support host apps with bitcode enabled. - 'ARCHS=x86_64', - 'ONLY_ACTIVE_ARCH=NO', // No device targeted, so build all valid architectures. - 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', - ]; + // Always build debug for simulator. + final String simulatorConfiguration = toTitleCase(getNameForBuildMode(BuildMode.debug)); + pluginsBuildCommand = [ + ...globals.xcode.xcrunCommand(), + 'xcodebuild', + '-alltargets', + '-sdk', + 'iphonesimulator', + '-configuration', + simulatorConfiguration, + 'SYMROOT=${simulatorBuildOutput.path}', + 'ENABLE_BITCODE=YES', // Support host apps with bitcode enabled. + 'ARCHS=x86_64', + 'ONLY_ACTIVE_ARCH=NO', // No device targeted, so build all valid architectures. + 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', + ]; - buildPluginsResult = await globals.processUtils.run( - pluginsBuildCommand, - workingDirectory: _project.ios.hostAppRoot - .childDirectory('Pods') - .path, - allowReentrantFlutter: false, + buildPluginsResult = await globals.processUtils.run( + pluginsBuildCommand, + workingDirectory: _project.ios.hostAppRoot + .childDirectory('Pods') + .path, + allowReentrantFlutter: false, + ); + + if (buildPluginsResult.exitCode != 0) { + throwToolExit( + 'Unable to build plugin frameworks for simulator: ${buildPluginsResult.stderr}', ); - - if (buildPluginsResult.exitCode != 0) { - throwToolExit( - 'Unable to build plugin frameworks for simulator: ${buildPluginsResult.stderr}', - ); - } } final Directory iPhoneBuildConfiguration = iPhoneBuildOutput.childDirectory( '$xcodeBuildConfiguration-iphoneos', ); final Directory simulatorBuildConfiguration = simulatorBuildOutput.childDirectory( - '$xcodeBuildConfiguration-iphonesimulator', + '$simulatorConfiguration-iphonesimulator', ); final Iterable products = iPhoneBuildConfiguration @@ -504,10 +505,9 @@ end final List frameworks = [ podProduct as Directory, - if (mode == BuildMode.debug) - simulatorBuildConfiguration - .childDirectory(builtProduct.basename) - .childDirectory(podFrameworkName) + simulatorBuildConfiguration + .childDirectory(builtProduct.basename) + .childDirectory(podFrameworkName) ]; await _produceXCFramework(frameworks, binaryName, modeDirectory);