Skip to content

Commit

Permalink
Refs #5785. Fix path to remote drush (#5796)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Oct 26, 2023
1 parent 067bbcf commit edfd51a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Runtime/DependencyInjection.php
Expand Up @@ -133,7 +133,8 @@ protected function addDrushServices($container, ClassLoader $loader, DrushDrupal
Robo::addShared($container, 'tildeExpansion.hook', 'Drush\Runtime\TildeExpansionHook');
Robo::addShared($container, 'process.manager', ProcessManager::class)
->addMethodCall('setConfig', ['config'])
->addMethodCall('setConfigRuntime', ['config.runtime']);
->addMethodCall('setConfigRuntime', ['config.runtime'])
->addMethodCall('setDrupalFinder', [$drupalFinder]);
Robo::addShared($container, 'redispatch.hook', 'Drush\Runtime\RedispatchHook')
->addArgument('process.manager');

Expand Down
27 changes: 19 additions & 8 deletions src/SiteAlias/ProcessManager.php
Expand Up @@ -18,6 +18,18 @@
*/
class ProcessManager extends ConsolidationProcessManager
{
protected $drupalFinder;

public function setDrupalFinder($drupalFinder): void
{
$this->drupalFinder = $drupalFinder;
}

public function getDrupalFinder()
{
return $this->drupalFinder;
}

/**
* Run a Drush command on a site alias (or @self).
*/
Expand Down Expand Up @@ -66,13 +78,13 @@ public function drushScript(SiteAliasInterface $siteAlias)
return $siteAlias->get('paths.drush-script');
}

// If the provided site alias is for a remote site / container et. al.,
// then use the 'drush' in the $PATH.
// A remote site / container et. al.,
if ($this->hasTransport($siteAlias)) {
if ($siteAlias->hasRoot()) {
return Path::join($siteAlias->root(), $this->relativePathToVendorBinDrush());
}

// Fallback to the 'drush' in the $PATH.
return $defaultDrushScript;
}

Expand All @@ -91,15 +103,14 @@ public function drushScript(SiteAliasInterface $siteAlias)
}

/**
* Return the relative path to 'vendor/bin/drush' from the project root.
* Return the relative path to 'vendor/bin/drush' from the Drupal root.
*/
protected function relativePathToVendorBinDrush()
{
$absoluteVendorBin = $_composer_bin_dir ?? Path::join($this->getConfig()->get('drush.vendor-dir'), 'bin');
$projectRoot = $this->getConfig()->get('runtime.project');

$relativeVendorBin = Path::makeRelative($absoluteVendorBin, $projectRoot);

// https://getcomposer.org/doc/articles/vendor-binaries.md#finding-the-composer-bin-dir-from-a-binary
$vendorBin = $GLOBALS['_composer_bin_dir'] ?? Path::join($this->getDrupalFinder()->getVendorDir(), 'bin');
$drupalRoot = $this->getDrupalFinder()->getDrupalRoot();
$relativeVendorBin = Path::makeRelative($vendorBin, $drupalRoot);
return Path::join($relativeVendorBin, 'drush');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/RsyncTest.php
Expand Up @@ -41,7 +41,7 @@ public function testRsyncSimulated()
// the remote side, at which point they will be evaluated & any needed
// injection will be done.
$this->drush('rsync', ['@example.dev', '@example.stage'], $options, 'user@server/path/to/drupal#sitename');
$expected = "[notice] Simulating: ssh -o PasswordAuthentication=no user@server '/path/to/drupal/vendor/bin/drush --no-interaction rsync @example.dev @example.stage --uri=sitename";
$expected = "[notice] Simulating: ssh -o PasswordAuthentication=no user@server '/path/to/vendor/bin/drush --no-interaction rsync @example.dev @example.stage --uri=sitename";
$this->assertStringContainsString($expected, $this->getSimplifiedErrorOutput());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/SqlSyncTest.php
Expand Up @@ -66,7 +66,7 @@ public function testSimulatedSqlSync()
// Test simulated remote invoke with a remote runner.
$this->drush(SqlSyncCommands::SYNC, ['@synctest.remote', '@synctest.local'], $options, 'user@server/path/to/drupal#sitename');
$output = $this->getSimplifiedErrorOutput();
$this->assertStringContainsString("[notice] Simulating: ssh -o PasswordAuthentication=no user@server '/path/to/drupal/vendor/bin/drush --no-interaction sql:sync @synctest.remote @synctest.local --uri=sitename'", $output);
$this->assertStringContainsString("[notice] Simulating: ssh -o PasswordAuthentication=no user@server '/path/to/vendor/bin/drush --no-interaction sql:sync @synctest.remote @synctest.local --uri=sitename'", $output);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/unish/CommandUnishTestCase.php
Expand Up @@ -189,7 +189,7 @@ protected function prepareDrushCommand(string $command, array $args = [], array
$cmd[] = '2>' . $this->bitBucket();
}
// Remove NULLs
$exec = @array_filter($cmd, 'strlen');
$exec = array_filter($cmd, fn ($value) => !is_null($value));
$cmd = implode(' ', $exec);
return [$cmd, $coverage_file];
}
Expand Down

0 comments on commit edfd51a

Please sign in to comment.