From 7587f54b204a61c1dbe84926caf3330d635cfa62 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 25 May 2018 14:53:10 -0700 Subject: [PATCH] Build single-architecture for local iOS engines (#17919) When running with --local-engine, build single-architecture apps, rather than what's declared in the Xcode project. By default, Flutter creates Xcode projects that generate universal binaries supporting both armv7 and arm64 processors. Since local engine builds are all single-architecture, override the Xcode project's ARCHS setting with the appropriate value for the specific engine. NOTE: this assumes engine paths consistent with those used in the engine repo: 32-bit iOS engine builds end in _arm, 64-bit builds do not. --- .../flutter_tools/lib/src/ios/xcodeproj.dart | 9 +++ .../test/ios/xcodeproj_test.dart | 66 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/packages/flutter_tools/lib/src/ios/xcodeproj.dart b/packages/flutter_tools/lib/src/ios/xcodeproj.dart index f11dad62b4..7d00695159 100644 --- a/packages/flutter_tools/lib/src/ios/xcodeproj.dart +++ b/packages/flutter_tools/lib/src/ios/xcodeproj.dart @@ -80,6 +80,15 @@ void updateGeneratedXcodeProperties({ if (artifacts is LocalEngineArtifacts) { final LocalEngineArtifacts localEngineArtifacts = artifacts; localsBuffer.writeln('LOCAL_ENGINE=${localEngineArtifacts.engineOutPath}'); + + // Tell Xcode not to build universal binaries for local engines, which are + // single-architecture. + // + // NOTE: this assumes that local engine binary paths are consistent with + // the conventions uses in the engine: 32-bit iOS engines are built to + // paths ending in _arm, 64-bit builds are not. + final String arch = localEngineArtifacts.engineOutPath.endsWith('_arm') ? 'armv7' : 'arm64'; + localsBuffer.writeln('ARCHS=$arch'); } if (previewDart2) { diff --git a/packages/flutter_tools/test/ios/xcodeproj_test.dart b/packages/flutter_tools/test/ios/xcodeproj_test.dart index 426c9c4c8d..dd75f93988 100644 --- a/packages/flutter_tools/test/ios/xcodeproj_test.dart +++ b/packages/flutter_tools/test/ios/xcodeproj_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:file/memory.dart'; +import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/build_info.dart'; @@ -252,11 +253,76 @@ Information about project "Runner": expect(info.buildConfigurationFor(const BuildInfo(BuildMode.release, 'Paid'), 'Paid'), null); }); }); + + group('updateGeneratedXcodeProperties', () { + MockLocalEngineArtifacts mockArtifacts; + MockProcessManager mockProcessManager; + FakePlatform macOS; + FileSystem fs; + + setUp(() { + fs = new MemoryFileSystem(); + mockArtifacts = new MockLocalEngineArtifacts(); + mockProcessManager = new MockProcessManager(); + macOS = fakePlatform('macos'); + fs.file(xcodebuild).createSync(recursive: true); + }); + + void testUsingOsxContext(String description, dynamic testMethod()) { + testUsingContext(description, testMethod, overrides: { + Artifacts: () => mockArtifacts, + ProcessManager: () => mockProcessManager, + Platform: () => macOS, + FileSystem: () => fs, + }); + } + + testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () { + when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, any)).thenReturn('engine'); + when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm')); + const BuildInfo buildInfo = const BuildInfo(BuildMode.debug, null, + previewDart2: true, + targetPlatform: TargetPlatform.ios, + ); + updateGeneratedXcodeProperties( + projectPath: 'path/to/project', + buildInfo: buildInfo, + previewDart2: true, + ); + + final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig'); + expect(config.existsSync(), isTrue); + + final String contents = config.readAsStringSync(); + expect(contents.contains('ARCHS=armv7'), isTrue); + }); + + testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () { + when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, any)).thenReturn('engine'); + when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile')); + const BuildInfo buildInfo = const BuildInfo(BuildMode.debug, null, + previewDart2: true, + targetPlatform: TargetPlatform.ios, + ); + updateGeneratedXcodeProperties( + projectPath: 'path/to/project', + buildInfo: buildInfo, + previewDart2: true, + ); + + final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig'); + expect(config.existsSync(), isTrue); + + final String contents = config.readAsStringSync(); + expect(contents.contains('ARCHS=arm64'), isTrue); + }); + }); } Platform fakePlatform(String name) { return new FakePlatform.fromPlatform(const LocalPlatform())..operatingSystem = name; } +class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {} class MockProcessManager extends Mock implements ProcessManager {} class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter { }