Bundle ios dependencies (#34669)

This updates the flutter tool to cache binary files for ideviceinstaller, ios-deploy, libimobiledevice, and dynamically linked dependencies from Flutter's GCP bucket.
This commit is contained in:
Christopher Fujino
2019-07-12 08:36:18 -07:00
committed by GitHub
parent 90326b6184
commit 14d489adc5
24 changed files with 397 additions and 431 deletions

View File

@@ -107,6 +107,22 @@ void main() {
verifyNever(artifact1.update(<DevelopmentArtifact>{}));
verify(artifact2.update(<DevelopmentArtifact>{}));
});
testUsingContext('getter dyLdLibEntry concatenates the output of each artifact\'s dyLdLibEntry getter', () async {
final CachedArtifact artifact1 = MockCachedArtifact();
final CachedArtifact artifact2 = MockCachedArtifact();
final CachedArtifact artifact3 = MockCachedArtifact();
when(artifact1.dyLdLibPath).thenReturn('/path/to/alpha:/path/to/beta');
when(artifact2.dyLdLibPath).thenReturn('/path/to/gamma:/path/to/delta:/path/to/epsilon');
when(artifact3.dyLdLibPath).thenReturn(''); // Empty output
final Cache cache = Cache(artifacts: <CachedArtifact>[artifact1, artifact2, artifact3]);
expect(cache.dyLdLibEntry.key, 'DYLD_LIBARY_PATH');
expect(
cache.dyLdLibEntry.value,
'/path/to/alpha:/path/to/beta:/path/to/gamma:/path/to/delta:/path/to/epsilon',
);
}, overrides: <Type, Generator>{
Cache: ()=> mockCache,
});
testUsingContext('failed storage.googleapis.com download shows China warning', () async {
final CachedArtifact artifact1 = MockCachedArtifact();
final CachedArtifact artifact2 = MockCachedArtifact();

View File

@@ -425,7 +425,7 @@ void main() {
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
expect(
testLogger.errorText,
testLogger.errorText.replaceAll('\n', ' '),
contains('Saved signing certificate "iPhone Developer: Invalid Profile" is not a valid development certificate'),
);
expect(

View File

@@ -1,178 +0,0 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/ios/ios_workflow.dart';
import 'package:flutter_tools/src/ios/mac.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
group('iOS Workflow validation', () {
MockIMobileDevice iMobileDevice;
MockIMobileDevice iMobileDeviceUninstalled;
MockProcessManager processManager;
FileSystem fs;
setUp(() {
iMobileDevice = MockIMobileDevice();
iMobileDeviceUninstalled = MockIMobileDevice(isInstalled: false);
processManager = MockProcessManager();
fs = MemoryFileSystem();
});
testUsingContext('Emit missing status when nothing is installed', () async {
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(
hasHomebrew: false,
hasIosDeploy: false,
hasIDeviceInstaller: false,
iosDeployVersionText: '0.0.0',
);
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.missing);
}, overrides: <Type, Generator>{
IMobileDevice: () => iMobileDeviceUninstalled,
});
testUsingContext('Emits installed status when homebrew not installed, but not needed', () async {
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(hasHomebrew: false);
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.installed);
}, overrides: <Type, Generator>{
IMobileDevice: () => iMobileDevice,
});
testUsingContext('Emits partial status when libimobiledevice is not installed', () async {
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
IMobileDevice: () => MockIMobileDevice(isInstalled: false, isWorking: false),
});
testUsingContext('Emits partial status when libimobiledevice is installed but not working', () async {
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
IMobileDevice: () => MockIMobileDevice(isWorking: false),
});
testUsingContext('Emits partial status when libimobiledevice is installed but not working', () async {
when(processManager.run(
<String>['ideviceinfo', '-u', '00008020-001C2D903C42002E'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment')),
).thenAnswer((Invocation _) async {
final MockProcessResult result = MockProcessResult();
when<String>(result.stdout).thenReturn(r'''
Usage: ideviceinfo [OPTIONS]
Show information about a connected device.
-d, --debug enable communication debugging
-s, --simple use a simple connection to avoid auto-pairing with the device
-u, --udid UDID target specific device by its 40-digit device UDID
-q, --domain NAME set domain of query to NAME. Default: None
-k, --key NAME only query key specified by NAME. Default: All keys.
-x, --xml output information as xml plist instead of key/value pairs
-h, --help prints usage information
''');
return null;
});
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
});
testUsingContext('Emits partial status when ios-deploy is not installed', () async {
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(hasIosDeploy: false);
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
IMobileDevice: () => iMobileDevice,
});
testUsingContext('Emits partial status when ios-deploy version is too low', () async {
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(iosDeployVersionText: '1.8.0');
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
IMobileDevice: () => iMobileDevice,
});
testUsingContext('Emits partial status when ios-deploy version is a known bad version', () async {
final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(iosDeployVersionText: '2.0.0');
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
IMobileDevice: () => iMobileDevice,
});
testUsingContext('Succeeds when all checks pass', () async {
final ValidationResult result = await IOSWorkflowTestTarget().validate();
expect(result.type, ValidationType.installed);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
IMobileDevice: () => iMobileDevice,
ProcessManager: () => processManager,
});
});
}
final ProcessResult exitsHappy = ProcessResult(
1, // pid
0, // exitCode
'', // stdout
'', // stderr
);
class MockIMobileDevice extends IMobileDevice {
MockIMobileDevice({
this.isInstalled = true,
bool isWorking = true,
}) : isWorking = Future<bool>.value(isWorking);
@override
final bool isInstalled;
@override
final Future<bool> isWorking;
}
class MockProcessManager extends Mock implements ProcessManager {}
class MockProcessResult extends Mock implements ProcessResult {}
class IOSWorkflowTestTarget extends IOSValidator {
IOSWorkflowTestTarget({
this.hasHomebrew = true,
bool hasIosDeploy = true,
String iosDeployVersionText = '1.9.4',
bool hasIDeviceInstaller = true,
}) : hasIosDeploy = Future<bool>.value(hasIosDeploy),
iosDeployVersionText = Future<String>.value(iosDeployVersionText),
hasIDeviceInstaller = Future<bool>.value(hasIDeviceInstaller);
@override
final bool hasHomebrew;
@override
final Future<bool> hasIosDeploy;
@override
final Future<String> iosDeployVersionText;
@override
final Future<bool> hasIDeviceInstaller;
}

View File

@@ -9,6 +9,8 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart' show ProcessException, ProcessResult;
import 'package:flutter_tools/src/ios/mac.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
@@ -22,6 +24,8 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform: _kNoColorTerminalPlatform,
};
class MockArtifacts extends Mock implements Artifacts {}
class MockCache extends Mock implements Cache {}
class MockProcessManager extends Mock implements ProcessManager {}
class MockFile extends Mock implements File {}
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
@@ -32,41 +36,80 @@ void main() {
final FakePlatform osx = FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'macos';
MockProcessManager mockProcessManager;
final String libimobiledevicePath = fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice');
final String ideviceIdPath = fs.path.join(libimobiledevicePath, 'idevice_id');
final String ideviceInfoPath = fs.path.join(libimobiledevicePath, 'ideviceinfo');
final String idevicescreenshotPath = fs.path.join(libimobiledevicePath, 'idevicescreenshot');
MockArtifacts mockArtifacts;
MockCache mockCache;
setUp(() {
mockProcessManager = MockProcessManager();
mockCache = MockCache();
mockArtifacts = MockArtifacts();
when(mockArtifacts.getArtifactPath(Artifact.ideviceId, platform: anyNamed('platform'))).thenReturn(ideviceIdPath);
when(mockCache.dyLdLibEntry).thenReturn(
MapEntry<String, String>('DYLD_LIBRARY_PATH', libimobiledevicePath)
);
});
testUsingContext('isWorking returns false if libimobiledevice is not installed', () async {
when(mockProcessManager.runSync(
<String>[ideviceIdPath, '-h'], environment: anyNamed('environment')
)).thenReturn(ProcessResult(123, 1, '', ''));
expect(await iMobileDevice.isWorking, false);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Artifacts: () => mockArtifacts,
});
testUsingContext('getAvailableDeviceIDs throws ToolExit when libimobiledevice is not installed', () async {
when(mockProcessManager.run(<String>['idevice_id', '-l']))
.thenThrow(const ProcessException('idevice_id', <String>['-l']));
when(mockProcessManager.run(
<String>[ideviceIdPath, '-l'],
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
)).thenThrow(ProcessException(ideviceIdPath, <String>['-l']));
expect(() async => await iMobileDevice.getAvailableDeviceIDs(), throwsToolExit());
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
Artifacts: () => mockArtifacts,
});
testUsingContext('getAvailableDeviceIDs throws ToolExit when idevice_id returns non-zero', () async {
when(mockProcessManager.run(<String>['idevice_id', '-l']))
.thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 1, '', 'Sad today')));
when(mockProcessManager.run(
<String>[ideviceIdPath, '-l'],
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 1, '', 'Sad today')));
expect(() async => await iMobileDevice.getAvailableDeviceIDs(), throwsToolExit());
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
Artifacts: () => mockArtifacts,
});
testUsingContext('getAvailableDeviceIDs returns idevice_id output when installed', () async {
when(mockProcessManager.run(<String>['idevice_id', '-l']))
.thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 0, 'foo', '')));
when(mockProcessManager.run(
<String>[ideviceIdPath, '-l'],
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 0, 'foo', '')));
expect(await iMobileDevice.getAvailableDeviceIDs(), 'foo');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
Artifacts: () => mockArtifacts,
});
testUsingContext('getInfoForDevice throws IOSDeviceNotFoundError when ideviceinfo returns specific error code and message', () async {
when(mockProcessManager.run(<String>['ideviceinfo', '-u', 'foo', '-k', 'bar']))
.thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 255, 'No device found with udid foo, is it plugged in?', '')));
when(mockArtifacts.getArtifactPath(Artifact.ideviceinfo, platform: anyNamed('platform'))).thenReturn(ideviceInfoPath);
when(mockProcessManager.run(
<String>[ideviceInfoPath, '-u', 'foo', '-k', 'bar'],
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 255, 'No device found with udid foo, is it plugged in?', '')));
expect(() async => await iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isInstanceOf<IOSDeviceNotFoundError>()));
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
Artifacts: () => mockArtifacts,
});
group('screenshot', () {
@@ -77,14 +120,15 @@ void main() {
setUp(() {
mockProcessManager = MockProcessManager();
mockOutputFile = MockFile();
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
});
testUsingContext('error if idevicescreenshot is not installed', () async {
when(mockOutputFile.path).thenReturn(outputPath);
// Let `idevicescreenshot` fail with exit code 1.
when(mockProcessManager.run(<String>['idevicescreenshot', outputPath],
environment: null,
when(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath],
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
workingDirectory: null,
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(4, 1, '', '')));
@@ -92,20 +136,23 @@ void main() {
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Platform: () => osx,
Cache: () => mockCache,
});
testUsingContext('idevicescreenshot captures and returns screenshot', () async {
when(mockOutputFile.path).thenReturn(outputPath);
when(mockProcessManager.run(any, environment: null, workingDirectory: null)).thenAnswer(
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
await iMobileDevice.takeScreenshot(mockOutputFile);
verify(mockProcessManager.run(<String>['idevicescreenshot', outputPath],
environment: null,
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath],
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
workingDirectory: null,
));
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
Artifacts: () => mockArtifacts,
});
});
});

View File

@@ -23,7 +23,7 @@ void main() {
});
testUsingContext('Emits installed status when CocoaPods is installed', () async {
final CocoaPodsTestTarget workflow = CocoaPodsTestTarget();
const CocoaPodsValidator workflow = CocoaPodsValidator();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.installed);
}, overrides: <Type, Generator>{
@@ -33,7 +33,7 @@ void main() {
testUsingContext('Emits missing status when CocoaPods is not installed', () async {
when(cocoaPods.evaluateCocoaPodsInstallation)
.thenAnswer((_) async => CocoaPodsStatus.notInstalled);
final CocoaPodsTestTarget workflow = CocoaPodsTestTarget();
const CocoaPodsValidator workflow = CocoaPodsValidator();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.missing);
}, overrides: <Type, Generator>{
@@ -43,7 +43,7 @@ void main() {
testUsingContext('Emits partial status when CocoaPods is installed with unknown version', () async {
when(cocoaPods.evaluateCocoaPodsInstallation)
.thenAnswer((_) async => CocoaPodsStatus.unknownVersion);
final CocoaPodsTestTarget workflow = CocoaPodsTestTarget();
const CocoaPodsValidator workflow = CocoaPodsValidator();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
@@ -52,7 +52,7 @@ void main() {
testUsingContext('Emits partial status when CocoaPods is not initialized', () async {
when(cocoaPods.isCocoaPodsInitialized).thenAnswer((_) async => false);
final CocoaPodsTestTarget workflow = CocoaPodsTestTarget();
const CocoaPodsValidator workflow = CocoaPodsValidator();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
@@ -62,30 +62,13 @@ void main() {
testUsingContext('Emits partial status when CocoaPods version is too low', () async {
when(cocoaPods.evaluateCocoaPodsInstallation)
.thenAnswer((_) async => CocoaPodsStatus.belowRecommendedVersion);
final CocoaPodsTestTarget workflow = CocoaPodsTestTarget();
const CocoaPodsValidator workflow = CocoaPodsValidator();
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
CocoaPods: () => cocoaPods,
});
testUsingContext('Emits installed status when homebrew not installed, but not needed', () async {
final CocoaPodsTestTarget workflow = CocoaPodsTestTarget(hasHomebrew: false);
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.installed);
}, overrides: <Type, Generator>{
CocoaPods: () => cocoaPods,
});
});
}
class MockCocoaPods extends Mock implements CocoaPods {}
class CocoaPodsTestTarget extends CocoaPodsValidator {
CocoaPodsTestTarget({
this.hasHomebrew = true,
});
@override
final bool hasHomebrew;
}