Skip to content

Commit

Permalink
add ArtifactRepository.iosSimulatorPath
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Oct 18, 2022
1 parent 81e8886 commit c2f8843
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
26 changes: 26 additions & 0 deletions packages/patrol_cli/lib/src/common/artifacts_repository.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dart:io' show Process;

import 'package:archive/archive.dart';
import 'package:file/file.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' show join, dirname;
import 'package:patrol_cli/src/common/constants.dart' show globalVersion;
import 'package:patrol_cli/src/common/extensions/process.dart';
import 'package:platform/platform.dart';

part 'artifacts_repository.freezed.dart';
Expand Down Expand Up @@ -206,6 +209,29 @@ class ArtifactsRepository {
return join(artifactPath, artifact.filename);
}

/// Returns path to the iOS artifact appropriate for the architecture of the
/// machine.
///
/// Known issues on Apple Silicon:
///
/// * If Simulator.app is run with Rosetta 2, then artifact for x86_64
/// architecture is used, and it won't work
///
/// * If Terminal.app is run with Rosetta 2, then artifact for x86_64
/// architecture is used even if the Simulator.app is running without
/// Rosetta 2, and it won't work
String get iosSimulatorPath {
final processResult = Process.runSync('uname', ['-m']);
final arch = processResult.stdOut;
if (arch == 'arm64') {
return iosSimulatorArmPath;
} else if (arch == 'x86_64') {
return iosSimulatorAmdPath;
} else {
throw StateError('architecture $arch is not supported');
}
}

String get iosSimulatorArmPath {
final artifact =
debug ? Artifacts.iosSimulatorArm.debug : Artifacts.iosSimulatorArm;
Expand Down
28 changes: 15 additions & 13 deletions packages/patrol_cli/lib/src/features/drive/platform/ios_driver.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:async';
import 'dart:io' show Process, Platform;
import 'dart:io' show Platform, Process;

import 'package:dispose_scope/dispose_scope.dart';
import 'package:logging/logging.dart';
Expand All @@ -24,6 +24,8 @@ class IOSDriver {
final ArtifactsRepository _artifactsRepository;
final Logger _logger;

static const _bundleId = 'pl.leancode.AutomatorServerUITests.xctrunner';

Future<void> run({
required String port,
required Device device,
Expand Down Expand Up @@ -101,8 +103,7 @@ class IOSDriver {
required String port,
required String deviceId,
}) async {
// TODO: Use artifact appropriate for the Simulator architecture
final artifactPath = _artifactsRepository.iosSimulatorArmPath;
final artifactPath = _artifactsRepository.iosSimulatorPath;
_logger.fine('Using artifact ${basename(artifactPath)}');

final installProcess = await Process.start(
Expand All @@ -114,7 +115,9 @@ class IOSDriver {
artifactPath,
],
runInShell: true,
);
)
..listenStdOut(_logger.info).disposedBy(_disposeScope)
..listenStdErr(_logger.info).disposedBy(_disposeScope);

_disposeScope.addDispose(() async {
await Process.run(
Expand All @@ -123,13 +126,13 @@ class IOSDriver {
'simctl',
'uninstall',
deviceId,
'pl.leancode.AutomatorServerUITests.xctrunner',
_bundleId,
],
runInShell: true,
);
});

installProcess.listenStdOut(_logger.info).disposedBy(_disposeScope);
installProcess.listenStdErr(_logger.fine).disposedBy(_disposeScope);
_logger.fine('Uninstalled $_bundleId');
});

await installProcess.exitCode;

Expand All @@ -139,13 +142,12 @@ class IOSDriver {
'simctl',
'launch',
deviceId,
'pl.leancode.AutomatorServerUITests.xctrunner',
_bundleId,
],
runInShell: true,
);

runProcess.listenStdOut(_logger.info).disposedBy(_disposeScope);
runProcess.listenStdErr(_logger.fine).disposedBy(_disposeScope);
)
..listenStdOut(_logger.info).disposedBy(_disposeScope)
..listenStdErr(_logger.info).disposedBy(_disposeScope);

await runProcess.exitCode;
}
Expand Down

0 comments on commit c2f8843

Please sign in to comment.