Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Add support for arm64 macOS #869

Merged
merged 2 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/Chrome/ChromeProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public function toProcess(array $arguments = [])
if ($this->driver) {
$driver = $this->driver;
} elseif ($this->onWindows()) {
$driver = __DIR__.'/../../bin/chromedriver-win.exe';
} elseif ($this->onMac()) {
$driver = __DIR__.'/../../bin/chromedriver-mac';
$driver = realpath(__DIR__.'/../../bin/chromedriver-win.exe');
} elseif ($this->onIntelMac()) {
$driver = realpath(__DIR__.'/../../bin/chromedriver-mac-intel');
} elseif ($this->onArmMac()) {
$driver = realpath(__DIR__.'/../../bin/chromedriver-mac-arm');
} else {
$driver = __DIR__.'/../../bin/chromedriver-linux';
}
Expand Down Expand Up @@ -77,7 +79,7 @@ protected function process(array $arguments = [])
*/
protected function chromeEnvironment()
{
if ($this->onMac() || $this->onWindows()) {
if ($this->onIntelMac() || $this->onArmMac() || $this->onWindows()) {
return [];
}

Expand All @@ -95,12 +97,22 @@ protected function onWindows()
}

/**
* Determine if Dusk is running on Mac.
* Determine if Dusk is running on Mac x86_64.
*
* @return bool
*/
protected function onMac()
protected function onIntelMac()
{
return OperatingSystem::onMac();
return OperatingSystem::onIntelMac();
}

/**
* Determine if Dusk is running on Mac arm64.
*
* @return bool
*/
protected function onArmMac()
{
return OperatingSystem::onArmMac();
}
}
8 changes: 6 additions & 2 deletions src/Console/ChromeDriverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ChromeDriverCommand extends Command
*/
protected $slugs = [
'linux' => 'linux64',
'mac' => 'mac64',
'mac-intel' => 'mac64',
'mac-arm' => 'mac64_m1',
'win' => 'win32',
];

Expand Down Expand Up @@ -116,7 +117,10 @@ class ChromeDriverCommand extends Command
'/usr/bin/chromium --version',
'/usr/bin/google-chrome-stable --version',
],
'mac' => [
'mac-intel' => [
'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version',
],
'mac-arm' => [
'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version',
],
'win' => [
Expand Down
26 changes: 22 additions & 4 deletions src/OperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ class OperatingSystem
*/
public static function id()
{
return static::onWindows() ? 'win' : (static::onMac() ? 'mac' : 'linux');
if (static::onWindows()) {
return 'win';
} elseif (static::onIntelMac()) {
return 'mac-intel';
} elseif (static::onArmMac()) {
return 'mac-arm';
}

return 'linux';
}

/**
Expand All @@ -27,12 +35,22 @@ public static function onWindows()
}

/**
* Determine if the operating system is macOS.
* Determine if the operating system is macOS x86_64.
*
* @return bool
*/
public static function onIntelMac()
{
return PHP_OS === 'Darwin' && php_uname('m') === 'x86_64';
}

/**
* Determine if the operating system is macOS arm64.
*
* @return bool
*/
public static function onMac()
public static function onArmMac()
{
return PHP_OS === 'Darwin';
return PHP_OS === 'Darwin' && php_uname('m') === 'arm64';
}
}
44 changes: 38 additions & 6 deletions tests/ChromeProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ public function test_build_process_for_windows()
}
}

public function test_build_process_for_darwin()
public function test_build_process_for_darwin_intel()
{
try {
(new ChromeProcessDarwin)->toProcess();
(new ChromeProcessDarwinIntel)->toProcess();
} catch (RuntimeException $exception) {
$this->assertStringContainsString('chromedriver-mac', $exception->getMessage());
$this->assertStringContainsString('chromedriver-mac-intel', $exception->getMessage());
}
}

public function test_build_process_for_darwin_arm()
{
try {
(new ChromeProcessDarwinArm)->toProcess();
} catch (RuntimeException $exception) {
$this->assertStringContainsString('chromedriver-mac-arm', $exception->getMessage());
}
}

Expand Down Expand Up @@ -63,9 +72,9 @@ protected function onWindows()
}
}

class ChromeProcessDarwin extends ChromeProcess
class ChromeProcessDarwinIntel extends ChromeProcess
{
protected function onMac()
protected function onIntelMac()
{
return true;
}
Expand All @@ -76,9 +85,32 @@ protected function onWindows()
}
}

class ChromeProcessDarwinArm extends ChromeProcess
{
protected function onArmMac()
{
return true;
}

protected function onIntelMac()
{
return false;
}

protected function onWindows()
{
return false;
}
}

class ChromeProcessLinux extends ChromeProcess
{
protected function onMac()
protected function onArmMac()
{
return false;
}

protected function onIntelMac()
{
return false;
}
Expand Down