Skip to content

Commit

Permalink
Merge pull request #112 from acquia/ACMS-1903
Browse files Browse the repository at this point in the history
ACMS-1903: Use local executable for drush and fallback to global.
  • Loading branch information
vishalkhode1 authored and chandan-singh7929 committed Aug 28, 2023
1 parent 036b76c commit a187a46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
33 changes: 18 additions & 15 deletions src/Helpers/Process/Commands/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,25 @@ public function getBaseCommand(): string {
* Returns an array of command to execute.
*/
protected function getCommand(array $commands): array {
preg_match("/[^\/]+$/", $this->getBaseCommand(), $baseCommand);
$this->command = $baseCommand ? $baseCommand[0] : '';
// Use symfony executable finder object to look into
// global and application command to execute.
$executableFinder = new ExecutableFinder();
$this->command = $executableFinder->find($this->command, NULL, [
$this->rootDir . '/vendor/bin',
$this->rootDir . '/bin',
]);
if (!$this->command) {
throw new \RuntimeException("Could not find command executable.");
}
$this->command = $this->getBaseCommand();
if (!is_executable($this->command)) {
preg_match("/[^\/]+$/", $this->command, $baseCommand);
$this->command = $baseCommand ? $baseCommand[0] : '';
// Use symfony executable finder object to look into
// global and application command to execute.
$executableFinder = new ExecutableFinder();
$this->command = $executableFinder->find($this->command, NULL, [
$this->rootDir . '/vendor/bin',
$this->rootDir . '/bin',
]);
if (!$this->command) {
throw new \RuntimeException("Could not find command executable.");
}

// This is done so that if command exists in the root directory,
// so use relative path (instead of absolute path).
$this->command = str_replace($this->rootDir, ".", $this->command);
// This is done so that if command exists in the root directory,
// so use relative path (instead of absolute path).
$this->command = str_replace($this->rootDir, ".", $this->command);
}

return array_merge(
[$this->command],
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Process/Commands/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Drush extends CommandBase {
* {@inheritdoc}
*/
public function getBaseCommand(): string {
return 'drush';
return './vendor/bin/drush';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Task/Steps/DownloadModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function execute(array $args = []) :int {
if (!isset($composerContents->require->{'drush/drush'})) {
$this->composerCommand->prepare([
"require",
"drush/drush:^10.3 || ^11",
"drush/drush:^11 || ^12",
])->run();
}
if (!isset($composerContents->{'minimum-stability'}) || (isset($composerContents->{'minimum-stability'}) && $composerContents->{'minimum-stability'} != "dev")) {
Expand Down

0 comments on commit a187a46

Please sign in to comment.