Unverified Commit 86389be6 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Convert CocoaPods tests to testWithoutContext (#53291)

parent ff20bb8c
......@@ -104,7 +104,14 @@ Future<T> runInContext<T>(
operatingSystemUtils: globals.os,
platform: globals.platform,
),
CocoaPods: () => CocoaPods(),
CocoaPods: () => CocoaPods(
fileSystem: globals.fs,
processManager: globals.processManager,
logger: globals.logger,
platform: globals.platform,
xcodeProjectInterpreter: globals.xcodeProjectInterpreter,
timeoutConfiguration: timeoutConfiguration,
),
CocoaPodsValidator: () => CocoaPodsValidator(
globals.cocoaPods,
globals.userMessages,
......
......@@ -6,6 +6,8 @@ import 'dart:async';
import 'package:file/file.dart';
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import 'package:process/process.dart';
import '../base/common.dart';
import '../base/file_system.dart';
......@@ -14,7 +16,7 @@ import '../base/logger.dart';
import '../base/process.dart';
import '../base/version.dart';
import '../cache.dart';
import '../globals.dart' as globals;
import '../ios/xcodeproj.dart';
import '../project.dart';
const String noCocoaPodsConsequence = '''
......@@ -62,16 +64,41 @@ enum CocoaPodsStatus {
}
class CocoaPods {
CocoaPods({
@required FileSystem fileSystem,
@required ProcessManager processManager,
@required XcodeProjectInterpreter xcodeProjectInterpreter,
@required Logger logger,
@required Platform platform,
@required TimeoutConfiguration timeoutConfiguration,
}) : _fileSystem = fileSystem,
_processManager = processManager,
_xcodeProjectInterpreter = xcodeProjectInterpreter,
_logger = logger,
_platform = platform,
_processUtils = ProcessUtils(processManager: processManager, logger: logger),
_fileSystemUtils = FileSystemUtils(fileSystem: fileSystem, platform: platform),
_timeoutConfiguration = timeoutConfiguration;
final FileSystem _fileSystem;
final ProcessManager _processManager;
final FileSystemUtils _fileSystemUtils;
final ProcessUtils _processUtils;
final XcodeProjectInterpreter _xcodeProjectInterpreter;
final Logger _logger;
final Platform _platform;
final TimeoutConfiguration _timeoutConfiguration;
Future<String> _versionText;
String get cocoaPodsMinimumVersion => '1.6.0';
String get cocoaPodsRecommendedVersion => '1.8.0';
Future<bool> get isInstalled =>
globals.processUtils.exitsHappy(<String>['which', 'pod']);
_processUtils.exitsHappy(<String>['which', 'pod']);
Future<String> get cocoaPodsVersionText {
_versionText ??= globals.processUtils.run(
_versionText ??= _processUtils.run(
<String>['pod', '--version'],
environment: <String, String>{
'LANG': 'en_US.UTF-8',
......@@ -124,9 +151,9 @@ class CocoaPods {
if (installedVersion != null && installedVersion >= Version.parse('1.8.0')) {
return true;
}
final String cocoapodsReposDir = globals.platform.environment['CP_REPOS_DIR']
?? globals.fs.path.join(globals.fsUtils.homeDirPath, '.cocoapods', 'repos');
return globals.fs.isDirectory(globals.fs.path.join(cocoapodsReposDir, 'master'));
final String cocoapodsReposDir = _platform.environment['CP_REPOS_DIR']
?? _fileSystem.path.join(_fileSystemUtils.homeDirPath, '.cocoapods', 'repos');
return _fileSystem.isDirectory(_fileSystem.path.join(cocoapodsReposDir, 'master'));
}
Future<bool> processPods({
......@@ -155,7 +182,7 @@ class CocoaPods {
final CocoaPodsStatus installation = await evaluateCocoaPodsInstallation;
switch (installation) {
case CocoaPodsStatus.notInstalled:
globals.printError(
_logger.printError(
'Warning: CocoaPods not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n'
'To install:\n'
......@@ -164,7 +191,7 @@ class CocoaPods {
);
return false;
case CocoaPodsStatus.brokenInstall:
globals.printError(
_logger.printError(
'Warning: CocoaPods is installed but broken. Skipping pod install.\n'
'$brokenCocoaPodsConsequence\n'
'To re-install:\n'
......@@ -173,7 +200,7 @@ class CocoaPods {
);
return false;
case CocoaPodsStatus.unknownVersion:
globals.printError(
_logger.printError(
'Warning: Unknown CocoaPods version installed.\n'
'$unknownCocoaPodsConsequence\n'
'To upgrade:\n'
......@@ -182,7 +209,7 @@ class CocoaPods {
);
break;
case CocoaPodsStatus.belowMinimumVersion:
globals.printError(
_logger.printError(
'Warning: CocoaPods minimum required version $cocoaPodsMinimumVersion or greater not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n'
'To upgrade:\n'
......@@ -191,7 +218,7 @@ class CocoaPods {
);
return false;
case CocoaPodsStatus.belowRecommendedVersion:
globals.printError(
_logger.printError(
'Warning: CocoaPods recommended version $cocoaPodsRecommendedVersion or greater not installed.\n'
'Pods handling may fail on some projects involving plugins.\n'
'To upgrade:\n'
......@@ -203,7 +230,7 @@ class CocoaPods {
break;
}
if (!await isCocoaPodsInitialized) {
globals.printError(
_logger.printError(
'Warning: CocoaPods installed but not initialized. Skipping pod install.\n'
'$noCocoaPodsConsequence\n'
'To initialize CocoaPods, run:\n'
......@@ -221,7 +248,7 @@ class CocoaPods {
/// contains a suitable `Podfile` and that its `Flutter/Xxx.xcconfig` files
/// include pods configuration.
Future<void> setupPodfile(XcodeBasedProject xcodeProject) async {
if (!globals.xcodeProjectInterpreter.isInstalled) {
if (!_xcodeProjectInterpreter.isInstalled) {
// Don't do anything for iOS when host platform doesn't support it.
return;
}
......@@ -238,13 +265,13 @@ class CocoaPods {
if (xcodeProject is MacOSProject) {
podfileTemplateName = 'Podfile-macos';
} else {
final bool isSwift = (await globals.xcodeProjectInterpreter.getBuildSettings(
final bool isSwift = (await _xcodeProjectInterpreter.getBuildSettings(
runnerProject.path,
'Runner',
)).containsKey('SWIFT_VERSION');
podfileTemplateName = isSwift ? 'Podfile-ios-swift' : 'Podfile-ios-objc';
}
final File podfileTemplate = globals.fs.file(globals.fs.path.join(
final File podfileTemplate = _fileSystem.file(_fileSystem.path.join(
Cache.flutterRoot,
'packages',
'flutter_tools',
......@@ -305,10 +332,10 @@ class CocoaPods {
}
Future<void> _runPodInstall(XcodeBasedProject xcodeProject, String engineDirectory) async {
final Status status = globals.logger.startProgress('Running pod install...', timeout: timeoutConfiguration.slowOperation);
final ProcessResult result = await globals.processManager.run(
final Status status = _logger.startProgress('Running pod install...', timeout: _timeoutConfiguration.slowOperation);
final ProcessResult result = await _processManager.run(
<String>['pod', 'install', '--verbose'],
workingDirectory: globals.fs.path.dirname(xcodeProject.podfile.path),
workingDirectory: _fileSystem.path.dirname(xcodeProject.podfile.path),
environment: <String, String>{
'FLUTTER_FRAMEWORK_DIR': engineDirectory,
// See https://github.com/flutter/flutter/issues/10873.
......@@ -318,16 +345,16 @@ class CocoaPods {
},
);
status.stop();
if (globals.logger.isVerbose || result.exitCode != 0) {
if (_logger.isVerbose || result.exitCode != 0) {
final String stdout = result.stdout as String;
if (stdout.isNotEmpty) {
globals.printStatus("CocoaPods' output:\n↳");
globals.printStatus(stdout, indent: 4);
_logger.printStatus("CocoaPods' output:\n↳");
_logger.printStatus(stdout, indent: 4);
}
final String stderr = result.stderr as String;
if (stderr.isNotEmpty) {
globals.printStatus('Error output from CocoaPods:\n↳');
globals.printStatus(stderr, indent: 4);
_logger.printStatus('Error output from CocoaPods:\n↳');
_logger.printStatus(stderr, indent: 4);
}
}
if (result.exitCode != 0) {
......@@ -340,7 +367,7 @@ class CocoaPods {
void _diagnosePodInstallFailure(ProcessResult result) {
final dynamic stdout = result.stdout;
if (stdout is String && stdout.contains('out-of-date source repos')) {
globals.printError(
_logger.printError(
"Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.\n"
'To update the CocoaPods specs, run:\n'
' pod repo update\n',
......@@ -360,12 +387,12 @@ class CocoaPods {
if (xcodeProject is! IosProject) {
return;
}
final Link flutterSymlink = globals.fs.link(globals.fs.path.join(
final Link flutterSymlink = _fileSystem.link(_fileSystem.path.join(
xcodeProject.symlinks.path,
'flutter',
));
if (flutterSymlink.existsSync()) {
globals.printError(
_logger.printError(
'Warning: Podfile is out of date\n'
'$outOfDatePodfileConsequence\n'
'To regenerate the Podfile, run:\n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment