Add support for DarwinArchs when assembling macOS App.framework (#81243)

This commit is contained in:
Matej Knopp
2021-04-28 20:33:36 +02:00
committed by GitHub
parent 2b0d09dd81
commit f6726b425d
17 changed files with 447 additions and 103 deletions

View File

@@ -76,7 +76,7 @@ void main() {
final AssembleCommand command = AssembleCommand(
buildSystem: TestBuildSystem.all(BuildResult(success: true)));
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
await commandRunner.run(<String>['assemble', '-o Output', '-dTargetPlatform=darwin-x64', 'debug_macos_bundle_flutter_assets']);
await commandRunner.run(<String>['assemble', '-o Output', '-dTargetPlatform=darwin', '-dDarwinArchs=x86_64', 'debug_macos_bundle_flutter_assets']);
expect(await command.requiredArtifacts, <DevelopmentArtifact>{
DevelopmentArtifact.macOS,

View File

@@ -139,7 +139,7 @@ void main() {
expect(() => runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=darwin-x64',
'--target-platform=darwin',
]), throwsToolExit());
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
@@ -193,7 +193,7 @@ void main() {
await runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=darwin-x64',
'--target-platform=darwin',
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),

View File

@@ -178,7 +178,7 @@ void main() {
'ios-release',
);
expect(
artifacts.getEngineType(TargetPlatform.darwin_x64),
artifacts.getEngineType(TargetPlatform.darwin),
'darwin-x64',
);
});
@@ -308,7 +308,7 @@ void main() {
'android_debug_unopt',
);
expect(
artifacts.getEngineType(TargetPlatform.darwin_x64),
artifacts.getEngineType(TargetPlatform.darwin),
'android_debug_unopt',
);
});

View File

@@ -271,7 +271,7 @@ void main() {
'--sdk-root',
artifacts.getArtifactPath(
Artifact.flutterPatchedSdkPath,
platform: TargetPlatform.darwin_x64,
platform: TargetPlatform.darwin,
mode: BuildMode.debug,
) + '/',
'--target=flutter',
@@ -288,7 +288,7 @@ void main() {
]);
await const KernelSnapshot().build(androidEnvironment
..defines[kTargetPlatform] = getNameForTargetPlatform(TargetPlatform.darwin_x64)
..defines[kTargetPlatform] = getNameForTargetPlatform(TargetPlatform.darwin)
..defines[kBuildMode] = getNameForBuildMode(BuildMode.debug)
..defines[kTrackWidgetCreation] = 'false'
);

View File

@@ -25,55 +25,76 @@ void main() {
FileSystem fileSystem;
Artifacts artifacts;
FakeProcessManager processManager;
File binary;
BufferLogger logger;
FakeCommand copyFrameworkCommand;
FakeCommand lipoInfoNonFatCommand;
FakeCommand lipoInfoFatCommand;
FakeCommand lipoVerifyX86_64Command;
setUp(() {
processManager = FakeProcessManager.any();
processManager = FakeProcessManager.empty();
artifacts = Artifacts.test();
fileSystem = MemoryFileSystem.test();
logger = BufferLogger.test();
environment = Environment.test(
fileSystem.currentDirectory,
defines: <String, String>{
kBuildMode: 'debug',
kTargetPlatform: 'darwin-x64',
kTargetPlatform: 'darwin',
kDarwinArchs: 'x86_64',
},
inputs: <String, String>{},
artifacts: artifacts,
processManager: processManager,
logger: BufferLogger.test(),
logger: logger,
fileSystem: fileSystem,
engineVersion: '2'
);
binary = environment.outputDir
.childDirectory('FlutterMacOS.framework')
.childFile('FlutterMacOS');
copyFrameworkCommand = FakeCommand(
command: <String>[
'rsync',
'-av',
'--delete',
'--filter',
'- .DS_Store/',
'Artifact.flutterMacOSFramework.debug',
environment.outputDir.path,
],
);
lipoInfoNonFatCommand = FakeCommand(command: <String>[
'lipo',
'-info',
binary.path,
], stdout: 'Non-fat file:');
lipoInfoFatCommand = FakeCommand(command: <String>[
'lipo',
'-info',
binary.path,
], stdout: 'Architectures in the fat file:');
lipoVerifyX86_64Command = FakeCommand(command: <String>[
'lipo',
binary.path,
'-verify_arch',
'x86_64',
]);
});
testUsingContext('Copies files to correct cache directory', () async {
final Directory outputDir = fileSystem.directory('output');
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
'rsync',
'-av',
'--delete',
'--filter',
'- .DS_Store/',
'Artifact.flutterMacOSFramework.debug',
outputDir.path,
],
),
binary.createSync(recursive: true);
processManager.addCommands(<FakeCommand>[
copyFrameworkCommand,
lipoInfoNonFatCommand,
lipoVerifyX86_64Command,
]);
environment = Environment.test(
fileSystem.currentDirectory,
defines: <String, String>{
kBuildMode: 'debug',
kTargetPlatform: 'darwin-x64',
},
inputs: <String, String>{},
artifacts: artifacts,
processManager: processManager,
logger: BufferLogger.test(),
fileSystem: fileSystem,
engineVersion: '2',
outputDir: outputDir,
);
await const DebugUnpackMacOS().build(environment);
@@ -83,6 +104,81 @@ void main() {
ProcessManager: () => processManager,
});
testUsingContext('thinning fails when framework missing', () async {
processManager.addCommand(copyFrameworkCommand);
await expectLater(
const DebugUnpackMacOS().build(environment),
throwsA(isA<Exception>().having(
(Exception exception) => exception.toString(),
'description',
contains('FlutterMacOS.framework/FlutterMacOS does not exist, cannot thin'),
)));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('lipo fails when arch missing from framework', () async {
environment.defines[kDarwinArchs] = 'arm64 x86_64';
binary.createSync(recursive: true);
processManager.addCommands(<FakeCommand>[
copyFrameworkCommand,
lipoInfoFatCommand,
FakeCommand(command: <String>[
'lipo',
binary.path,
'-verify_arch',
'arm64',
'x86_64',
], exitCode: 1),
]);
await expectLater(
const DebugUnpackMacOS().build(environment),
throwsA(isA<Exception>().having(
(Exception exception) => exception.toString(),
'description',
contains('does not contain arm64 x86_64. Running lipo -info:\nArchitectures in the fat file:'),
)));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('skips thins framework', () async {
binary.createSync(recursive: true);
processManager.addCommands(<FakeCommand>[
copyFrameworkCommand,
lipoInfoNonFatCommand,
lipoVerifyX86_64Command,
]);
await const DebugUnpackMacOS().build(environment);
expect(logger.traceText, contains('Skipping lipo for non-fat file /FlutterMacOS.framework/FlutterMacOS'));
});
testUsingContext('thins fat framework', () async {
binary.createSync(recursive: true);
processManager.addCommands(<FakeCommand>[
copyFrameworkCommand,
lipoInfoFatCommand,
lipoVerifyX86_64Command,
FakeCommand(command: <String>[
'lipo',
'-output',
binary.path,
'-extract',
'x86_64',
binary.path,
]),
]);
await const DebugUnpackMacOS().build(environment);
expect(processManager, hasNoRemainingExpectations);
});
testUsingContext('debug macOS application fails if App.framework missing', () async {
fileSystem.directory(
artifacts.getArtifactPath(
@@ -113,13 +209,13 @@ void main() {
fileSystem.file(
artifacts.getArtifactPath(
Artifact.vmSnapshotData,
platform: TargetPlatform.darwin_x64,
platform: TargetPlatform.darwin,
mode: BuildMode.debug,
)).createSync(recursive: true);
fileSystem.file(
artifacts.getArtifactPath(
Artifact.isolateSnapshotData,
platform: TargetPlatform.darwin_x64,
platform: TargetPlatform.darwin,
mode: BuildMode.debug,
)).createSync(recursive: true);
fileSystem.file('${environment.buildDir.path}/App.framework/App')
@@ -217,4 +313,131 @@ void main() {
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('DebugMacOSFramework creates expected binary with arm64 only arch', () async {
environment.defines[kDarwinArchs] = 'arm64';
processManager.addCommand(
FakeCommand(command: <String>[
'xcrun',
'clang',
'-x',
'c',
environment.buildDir.childFile('debug_app.cc').path,
'-arch',
'arm64',
'-dynamiclib',
'-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks',
'-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks',
'-install_name', '@rpath/App.framework/App',
'-o',
environment.buildDir
.childDirectory('App.framework')
.childFile('App')
.path,
]),
);
await const DebugMacOSFramework().build(environment);
expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('DebugMacOSFramework creates universal binary', () async {
environment.defines[kDarwinArchs] = 'arm64 x86_64';
processManager.addCommand(
FakeCommand(command: <String>[
'xcrun',
'clang',
'-x',
'c',
environment.buildDir.childFile('debug_app.cc').path,
'-arch',
'arm64',
'-arch',
'x86_64',
'-dynamiclib',
'-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks',
'-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks',
'-install_name', '@rpath/App.framework/App',
'-o',
environment.buildDir
.childDirectory('App.framework')
.childFile('App')
.path,
]),
);
await const DebugMacOSFramework().build(environment);
expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('CompileMacOSFramework creates universal binary', () async {
environment.defines[kDarwinArchs] = 'arm64 x86_64';
environment.defines[kBuildMode] = 'release';
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'Artifact.genSnapshot.TargetPlatform.darwin.release',
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=${environment.buildDir.childFile('arm64/snapshot_assembly.S').path}',
'--strip',
environment.buildDir.childFile('app.dill').path
]),
FakeCommand(command: <String>[
'Artifact.genSnapshot.TargetPlatform.darwin.release',
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=${environment.buildDir.childFile('x86_64/snapshot_assembly.S').path}',
'--strip',
environment.buildDir.childFile('app.dill').path
]),
FakeCommand(command: <String>[
'xcrun', 'cc', '-arch', 'arm64',
'-c', environment.buildDir.childFile('arm64/snapshot_assembly.S').path,
'-o', environment.buildDir.childFile('arm64/snapshot_assembly.o').path
]),
FakeCommand(command: <String>[
'xcrun', 'cc', '-arch', 'x86_64',
'-c', environment.buildDir.childFile('x86_64/snapshot_assembly.S').path,
'-o', environment.buildDir.childFile('x86_64/snapshot_assembly.o').path
]),
FakeCommand(command: <String>[
'xcrun', 'clang', '-arch', 'arm64', '-dynamiclib', '-Xlinker', '-rpath',
'-Xlinker', '@executable_path/Frameworks', '-Xlinker', '-rpath',
'-Xlinker', '@loader_path/Frameworks',
'-install_name', '@rpath/App.framework/App',
'-o', environment.buildDir.childFile('arm64/App.framework/App').path,
environment.buildDir.childFile('arm64/snapshot_assembly.o').path
]),
FakeCommand(command: <String>[
'xcrun', 'clang', '-arch', 'x86_64', '-dynamiclib', '-Xlinker', '-rpath',
'-Xlinker', '@executable_path/Frameworks', '-Xlinker', '-rpath',
'-Xlinker', '@loader_path/Frameworks',
'-install_name', '@rpath/App.framework/App',
'-o', environment.buildDir.childFile('x86_64/App.framework/App').path,
environment.buildDir.childFile('x86_64/snapshot_assembly.o').path
]),
FakeCommand(command: <String>[
'lipo',
environment.buildDir.childFile('arm64/App.framework/App').path,
environment.buildDir.childFile('x86_64/App.framework/App').path,
'-create',
'-output',
environment.buildDir.childFile('App.framework/App').path,
]),
]);
await const CompileMacOSFramework().build(environment);
expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
}

View File

@@ -41,7 +41,7 @@ void main() {
);
final MockMacOSApp mockMacOSApp = MockMacOSApp();
expect(await device.targetPlatform, TargetPlatform.darwin_x64);
expect(await device.targetPlatform, TargetPlatform.darwin);
expect(device.name, 'macOS');
expect(await device.installApp(mockMacOSApp), true);
expect(await device.uninstallApp(mockMacOSApp), true);