Implement plugin tooling support for macOS (#33636)

Enables the CocoaPods-based plugin workflow for macOS. This allows a
macOS project to automatically fetch and add native plugin
implementations via CocoaPods for anything in pubspec.yaml, as is done
on iOS.
This commit is contained in:
stuartmorgan
2019-05-31 13:19:44 -07:00
committed by GitHub
parent 27876e09be
commit 3ebebebb8d
10 changed files with 373 additions and 127 deletions

View File

@@ -62,15 +62,20 @@ void main() {
cocoaPodsUnderTest = CocoaPods();
pretendPodVersionIs('1.5.0');
fs.file(fs.path.join(
Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'cocoapods', 'Podfile-objc',
Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'cocoapods', 'Podfile-ios-objc',
))
..createSync(recursive: true)
..writeAsStringSync('Objective-C podfile template');
..writeAsStringSync('Objective-C iOS podfile template');
fs.file(fs.path.join(
Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'cocoapods', 'Podfile-swift',
Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'cocoapods', 'Podfile-ios-swift',
))
..createSync(recursive: true)
..writeAsStringSync('Swift podfile template');
..writeAsStringSync('Swift iOS podfile template');
fs.file(fs.path.join(
Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'cocoapods', 'Podfile-macos',
))
..createSync(recursive: true)
..writeAsStringSync('macOS podfile template');
when(mockProcessManager.run(
<String>['pod', '--version'],
workingDirectory: anyNamed('workingDirectory'),
@@ -81,6 +86,11 @@ void main() {
workingDirectory: 'project/ios',
environment: <String, String>{'FLUTTER_FRAMEWORK_DIR': 'engine/path', 'COCOAPODS_DISABLE_STATS': 'true'},
)).thenAnswer((_) async => exitsHappy());
when(mockProcessManager.run(
<String>['pod', 'install', '--verbose'],
workingDirectory: 'project/macos',
environment: <String, String>{'FLUTTER_FRAMEWORK_DIR': 'engine/path', 'COCOAPODS_DISABLE_STATS': 'true'},
)).thenAnswer((_) async => exitsHappy());
});
group('Evaluate installation', () {
@@ -145,7 +155,7 @@ void main() {
testUsingContext('creates objective-c Podfile when not present', () async {
cocoaPodsUnderTest.setupPodfile(projectUnderTest.ios);
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Objective-C podfile template');
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Objective-C iOS podfile template');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
});
@@ -159,12 +169,21 @@ void main() {
final FlutterProject project = FlutterProject.fromPath('project');
cocoaPodsUnderTest.setupPodfile(project.ios);
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Swift podfile template');
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Swift iOS podfile template');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
XcodeProjectInterpreter: () => mockXcodeProjectInterpreter,
});
testUsingContext('creates macOS Podfile when not present', () async {
projectUnderTest.macos.xcodeProject.createSync(recursive: true);
cocoaPodsUnderTest.setupPodfile(projectUnderTest.macos);
expect(projectUnderTest.macos.podfile.readAsStringSync(), 'macOS podfile template');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
});
testUsingContext('does not recreate Podfile when already present', () async {
projectUnderTest.ios.podfile..createSync()..writeAsStringSync('Existing Podfile');
@@ -250,8 +269,8 @@ void main() {
pretendPodIsNotInstalled();
projectUnderTest.ios.podfile.createSync();
final bool didInstall = await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
);
verifyNever(mockProcessManager.run(
argThat(containsAllInOrder(<String>['pod', 'install'])),
@@ -269,8 +288,8 @@ void main() {
testUsingContext('throws, if Podfile is missing.', () async {
try {
await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
);
fail('ToolExit expected');
} catch(e) {
@@ -316,8 +335,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
));
try {
await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
);
fail('ToolExit expected');
} catch (e) {
@@ -340,8 +359,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
..createSync(recursive: true)
..writeAsStringSync('Existing lock file.');
final bool didInstall = await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
dependenciesChanged: false,
);
expect(didInstall, isTrue);
@@ -363,8 +382,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
..createSync()
..writeAsStringSync('Existing lock file.');
final bool didInstall = await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
dependenciesChanged: false,
);
expect(didInstall, isTrue);
@@ -392,8 +411,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
..createSync(recursive: true)
..writeAsStringSync('Different lock file.');
final bool didInstall = await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
dependenciesChanged: false,
);
expect(didInstall, isTrue);
@@ -421,8 +440,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
..createSync(recursive: true)
..writeAsStringSync('Existing lock file.');
final bool didInstall = await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
dependenciesChanged: true,
);
expect(didInstall, isTrue);
@@ -453,8 +472,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
projectUnderTest.ios.podfile
..writeAsStringSync('Updated Podfile');
await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
dependenciesChanged: false,
);
verify(mockProcessManager.run(
@@ -481,8 +500,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
..createSync(recursive: true)
..writeAsStringSync('Existing lock file.');
final bool didInstall = await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
dependenciesChanged: false,
);
expect(didInstall, isFalse);
@@ -520,8 +539,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
try {
await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
dependenciesChanged: true,
);
fail('Tool throw expected when pod install fails');
@@ -557,8 +576,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
environment: environment,
)).thenAnswer((_) async => exitsHappy());
final bool success = await cocoaPodsUnderTest.processPods(
iosProject: projectUnderTest.ios,
iosEngineDir: 'engine/path',
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
);
expect(success, true);
}, overrides: <Type, Generator>{