55import 'dart:async' ;
66
77import 'package:meta/meta.dart' ;
8+ import 'package:platform/platform.dart' ;
9+ import 'package:process/process.dart' ;
810
911import '../artifacts.dart' ;
1012import '../base/common.dart' ;
@@ -14,6 +16,7 @@ import '../base/io.dart';
1416import '../base/logger.dart' ;
1517import '../base/os.dart' ;
1618import '../base/process.dart' ;
19+ import '../base/terminal.dart' ;
1720import '../base/utils.dart' ;
1821import '../build_info.dart' ;
1922import '../cache.dart' ;
@@ -221,15 +224,33 @@ XcodeProjectInterpreter get xcodeProjectInterpreter => context.get<XcodeProjectI
221224
222225/// Interpreter of Xcode projects.
223226class XcodeProjectInterpreter {
227+ XcodeProjectInterpreter ({
228+ @required Platform platform,
229+ @required ProcessManager processManager,
230+ @required Logger logger,
231+ @required FileSystem fileSystem,
232+ @required AnsiTerminal terminal,
233+ }) : _platform = platform,
234+ _fileSystem = fileSystem,
235+ _terminal = terminal,
236+ _logger = logger,
237+ _processUtils = ProcessUtils (logger: logger, processManager: processManager);
238+
239+ final Platform _platform;
240+ final FileSystem _fileSystem;
241+ final ProcessUtils _processUtils;
242+ final AnsiTerminal _terminal;
243+ final Logger _logger;
244+
224245 static const String _executable = '/usr/bin/xcodebuild' ;
225246 static final RegExp _versionRegex = RegExp (r'Xcode ([0-9.]+)' );
226247
227248 void _updateVersion () {
228- if (! globals.platform. isMacOS || ! globals.fs .file (_executable).existsSync ()) {
249+ if (! _platform. isMacOS || ! _fileSystem .file (_executable).existsSync ()) {
229250 return ;
230251 }
231252 try {
232- final RunResult result = processUtils .runSync (
253+ final RunResult result = _processUtils .runSync (
233254 < String > [_executable, '-version' ],
234255 );
235256 if (result.exitCode != 0 ) {
@@ -283,26 +304,26 @@ class XcodeProjectInterpreter {
283304 Duration timeout = const Duration (minutes: 1 ),
284305 }) async {
285306 final Status status = Status .withSpinner (
286- timeout: timeoutConfiguration .fastOperation,
287- timeoutConfiguration: timeoutConfiguration ,
288- platform: globals.platform ,
307+ timeout: const TimeoutConfiguration () .fastOperation,
308+ timeoutConfiguration: const TimeoutConfiguration () ,
309+ platform: _platform ,
289310 stopwatch: Stopwatch (),
290- supportsColor: globals.terminal .supportsColor,
311+ supportsColor: _terminal .supportsColor,
291312 );
292313 final List <String > showBuildSettingsCommand = < String > [
293314 _executable,
294315 '-project' ,
295- globals.fs .path.absolute (projectPath),
316+ _fileSystem .path.absolute (projectPath),
296317 '-target' ,
297318 target,
298319 '-showBuildSettings' ,
299- ...environmentVariablesAsXcodeBuildSettings ()
320+ ...environmentVariablesAsXcodeBuildSettings (_platform )
300321 ];
301322 try {
302323 // showBuildSettings is reported to occasionally timeout. Here, we give it
303324 // a lot of wiggle room (locally on Flutter Gallery, this takes ~1s).
304325 // When there is a timeout, we retry once.
305- final RunResult result = await processUtils .run (
326+ final RunResult result = await _processUtils .run (
306327 showBuildSettingsCommand,
307328 throwOnError: true ,
308329 workingDirectory: projectPath,
@@ -317,32 +338,32 @@ class XcodeProjectInterpreter {
317338 command: showBuildSettingsCommand.join (' ' ),
318339 ).send ();
319340 }
320- globals .printTrace ('Unexpected failure to get the build settings: $error .' );
341+ _logger .printTrace ('Unexpected failure to get the build settings: $error .' );
321342 return const < String , String > {};
322343 } finally {
323344 status.stop ();
324345 }
325346 }
326347
327348 void cleanWorkspace (String workspacePath, String scheme) {
328- processUtils .runSync (< String > [
349+ _processUtils .runSync (< String > [
329350 _executable,
330351 '-workspace' ,
331352 workspacePath,
332353 '-scheme' ,
333354 scheme,
334355 '-quiet' ,
335356 'clean' ,
336- ...environmentVariablesAsXcodeBuildSettings ()
337- ], workingDirectory: globals.fs .currentDirectory.path);
357+ ...environmentVariablesAsXcodeBuildSettings (_platform )
358+ ], workingDirectory: _fileSystem .currentDirectory.path);
338359 }
339360
340361 Future <XcodeProjectInfo > getInfo (String projectPath, {String projectFilename}) async {
341362 // The exit code returned by 'xcodebuild -list' when either:
342363 // * -project is passed and the given project isn't there, or
343364 // * no -project is passed and there isn't a project.
344365 const int missingProjectExitCode = 66 ;
345- final RunResult result = await processUtils .run (
366+ final RunResult result = await _processUtils .run (
346367 < String > [
347368 _executable,
348369 '-list' ,
@@ -363,9 +384,9 @@ class XcodeProjectInterpreter {
363384/// This allows developers to pass arbitrary build settings in without the tool needing to make a flag
364385/// for or be aware of each one. This could be used to set code signing build settings in a CI
365386/// environment without requiring settings changes in the Xcode project.
366- List <String > environmentVariablesAsXcodeBuildSettings () {
387+ List <String > environmentVariablesAsXcodeBuildSettings (Platform platform ) {
367388 const String xcodeBuildSettingPrefix = 'FLUTTER_XCODE_' ;
368- return globals. platform.environment.entries.where ((MapEntry <String , String > mapEntry) {
389+ return platform.environment.entries.where ((MapEntry <String , String > mapEntry) {
369390 return mapEntry.key.startsWith (xcodeBuildSettingPrefix);
370391 }).expand <String >((MapEntry <String , String > mapEntry) {
371392 // Remove FLUTTER_XCODE_ prefix from the environment variable to get the build setting.
0 commit comments