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

Add commandfile searchpath for global composer installers #1513

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 27 additions & 1 deletion includes/preflight.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,27 @@ function drush_preflight_prepare() {
require_once DRUSH_BASE_PATH . '/includes/dbtng.inc';

// Stash our vendor path and classloader.
drush_set_context('DRUSH_VENDOR_PATH', dirname(realpath($vendor_path)));
$vendor_path = dirname(realpath($vendor_path));
drush_set_context('DRUSH_VENDOR_PATH', $vendor_path);
drush_set_context('DRUSH_CLASSLOADER', $classloader);

// Attempt to retrieve the home path of Composer directly from its config
// information (in case Drush was installed somewhere else). Use the
// "global" context here in case the CWD does not have a composer.json
// file which would cause the failure of this command.
if (drush_shell_exec('composer global config home')) {
$composer_output = drush_shell_exec_output();
$composer_home_path = _drush_convert_path(array_pop($composer_output));
}
// In case no path can be determined, simply step up one directory
// from the current Drush vendor path as a fallback.
else {
$composer_home_path = _drush_convert_path(_drush_shift_path_up($vendor_path));
}

// Store the Composer home path.
drush_set_context('DRUSH_COMPOSER_HOME_PATH', $composer_home_path);

// Terminate immediately unless invoked as a command line script
if (!drush_verify_cli()) {
return drush_set_error('DRUSH_REQUIREMENTS_ERROR', dt('Drush is designed to run via the command line.'));
Expand Down Expand Up @@ -407,6 +425,14 @@ function _drush_find_commandfiles_drush() {
if (!empty($per_user_config_dir)) {
$searchpath[] = $per_user_config_dir;
}

// Global Composer Installer packages, residing in $COMPOSER_HOME/drush.
// Note: this is not the same directory that Drush is typically installed,
// which is $COMPOSER_HOME/vendor/drush/drush.
$composer_home_path = drush_get_context('DRUSH_COMPOSER_HOME_PATH');
if ($composer_home_path && is_dir("$composer_home_path/drush")) {
$searchpath[] = "$composer_home_path/drush";
}
}

// @todo the zero parameter is a bit weird here. It's $phase.
Expand Down